| 711 | } |
| 712 | |
| 713 | int Socket::OnCreated(const SocketOptions& options) { |
| 714 | if (_io_event.Init((void*)id()) != 0) { |
| 715 | LOG(ERROR) << "Fail to init IOEvent"; |
| 716 | SetFailed(ENOMEM, "%s", "Fail to init IOEvent"); |
| 717 | return -1; |
| 718 | } |
| 719 | _io_event.set_bthread_tag(options.bthread_tag); |
| 720 | auto guard = butil::MakeScopeGuard([this] { |
| 721 | _io_event.Reset(); |
| 722 | }); |
| 723 | // start build the transport |
| 724 | _socket_mode = options.socket_mode; |
| 725 | _transport = TransportFactory::CreateTransport(options.socket_mode); |
| 726 | CHECK(NULL != _transport); |
| 727 | _transport->Init(this, options); |
| 728 | |
| 729 | g_vars->nsocket << 1; |
| 730 | CHECK(NULL == _shared_part.load(butil::memory_order_relaxed)); |
| 731 | _nevent.store(0, butil::memory_order_relaxed); |
| 732 | _keytable_pool = options.keytable_pool; |
| 733 | _tos = 0; |
| 734 | _remote_side = options.remote_side; |
| 735 | _local_side = options.local_side; |
| 736 | _device_name = options.device_name; |
| 737 | _on_edge_triggered_events = options.on_edge_triggered_events; |
| 738 | _need_on_edge_trigger = options.need_on_edge_trigger; |
| 739 | _user = options.user; |
| 740 | _conn = options.conn; |
| 741 | _app_connect = _transport->Connect(); |
| 742 | _preferred_index = -1; |
| 743 | _hc_count = 0; |
| 744 | CHECK(_read_buf.empty()); |
| 745 | const int64_t cpuwide_now = butil::cpuwide_time_us(); |
| 746 | _last_readtime_us.store(cpuwide_now, butil::memory_order_relaxed); |
| 747 | reset_parsing_context(options.initial_parsing_context); |
| 748 | _correlation_id = 0; |
| 749 | _health_check_interval_s = options.health_check_interval_s; |
| 750 | _hc_option = options.hc_option; |
| 751 | _is_hc_related_ref_held = false; |
| 752 | _ninprocess.store(1, butil::memory_order_relaxed); |
| 753 | _auth_flag_error.store(0, butil::memory_order_relaxed); |
| 754 | const int rc2 = bthread_id_create(&_auth_id, NULL, NULL); |
| 755 | if (rc2) { |
| 756 | LOG(ERROR) << "Fail to create auth_id: " << berror(rc2); |
| 757 | SetFailed(rc2, "Fail to create auth_id: %s", berror(rc2)); |
| 758 | return -1; |
| 759 | } |
| 760 | _force_ssl = options.force_ssl; |
| 761 | // Disable SSL check if there is no SSL context |
| 762 | _ssl_state = (options.initial_ssl_ctx == NULL ? SSL_OFF : SSL_UNKNOWN); |
| 763 | _ssl_session = NULL; |
| 764 | _ssl_ctx = options.initial_ssl_ctx; |
| 765 | _connection_type_for_progressive_read = CONNECTION_TYPE_UNKNOWN; |
| 766 | _controller_released_socket.store(false, butil::memory_order_relaxed); |
| 767 | _overcrowded = false; |
| 768 | // Maybe non-zero for RTMP connections. |
| 769 | _fail_me_at_server_stop = false; |
| 770 | _logoff_flag.store(false, butil::memory_order_relaxed); |
no test coverage detected