void zmq::tcp_connecter_t::out_event () { fd_t fd = connect (); rm_fd (handle); handle_valid = false; // Handle the error condition by attempt to reconnect. if (fd == retired_fd) { close (); add_reconnect_timer(); return; } tune_tcp_socket (fd); tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl); // Create the engine object for this connection. stream_engine_t *engine = new (std::nothrow) stream_engine_t (fd, options, endpoint); alloc_assert (engine); // Attach the engine to the corresponding session object. send_attach (session, engine); // Shut the connecter down. terminate (); socket->event_connected (endpoint, fd); }
void zmq::tcp_connecter_t::out_event () { bool is_interruped = false; fd_t fd = connect(&is_interruped); if (is_interruped) { return; } rm_fd (handle); handle_valid = false; // Handle the error condition by attempt to reconnect. if (fd == retired_fd) { close (); wait = true; add_reconnect_timer(); return; } tune_tcp_socket (fd); tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl); // Create the engine object for this connection. stream_engine_t *engine = new (std::nothrow) stream_engine_t (fd, options); alloc_assert (engine); // Attach the engine to the corresponding session object. send_attach (session, engine); // Shut the connecter down. terminate (); session->monitor_event (ZMQ_EVENT_CONNECTED, endpoint.c_str(), fd); }
void zmq::tcp_listener_t::in_event () { fd_t fd = accept (); // If connection was reset by the peer in the meantime, just ignore it. // TODO: Handle specific errors like ENFILE/EMFILE etc. if (fd == retired_fd) { socket->monitor_event (ZMQ_EVENT_ACCEPT_FAILED, endpoint.c_str(), zmq_errno()); return; } tune_tcp_socket (fd); tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl); // Create the engine object for this connection. stream_engine_t *engine = new (std::nothrow) stream_engine_t (fd, options); alloc_assert (engine); // Choose I/O thread to run connecter in. Given that we are already // running in an I/O thread, there must be at least one available. io_thread_t *io_thread = choose_io_thread (options.affinity); zmq_assert (io_thread); // Create and launch a session object. session_base_t *session = session_base_t::create (io_thread, false, socket, options, NULL); errno_assert (session); session->inc_seqnum (); launch_child (session); send_attach (session, engine, false); socket->monitor_event (ZMQ_EVENT_ACCEPTED, endpoint.c_str(), fd); }
void zmq::tcp_listener_t::in_event () { fd_t fd = accept (); // If connection was reset by the peer in the meantime, just ignore it. // TODO: Handle specific errors like ENFILE/EMFILE etc. if (fd == retired_fd) { _socket->event_accept_failed ( make_unconnected_bind_endpoint_pair (_endpoint), zmq_errno ()); return; } int rc = tune_tcp_socket (fd); rc = rc | tune_tcp_keepalives ( fd, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl); rc = rc | tune_tcp_maxrt (fd, options.tcp_maxrt); if (rc != 0) { _socket->event_accept_failed ( make_unconnected_bind_endpoint_pair (_endpoint), zmq_errno ()); return; } // Create the engine object for this connection. create_engine (fd); }
bool zmq::tcp_connecter_t::tune_socket (const fd_t fd) { const int rc = tune_tcp_socket (fd) | tune_tcp_keepalives ( fd, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl) | tune_tcp_maxrt (fd, options.tcp_maxrt); return rc == 0; }
zmq::fd_t zmq::socks_connecter_t::check_proxy_connection () { // Async connect has finished. Check whether an error occurred int err = 0; #ifdef ZMQ_HAVE_HPUX int len = sizeof err; #else socklen_t len = sizeof err; #endif int rc = getsockopt (s, SOL_SOCKET, SO_ERROR, (char*) &err, &len); // Assert if the error was caused by 0MQ bug. // Networking problems are OK. No need to assert. #ifdef ZMQ_HAVE_WINDOWS zmq_assert (rc == 0); if (err != 0) { wsa_assert (err == WSAECONNREFUSED || err == WSAETIMEDOUT || err == WSAECONNABORTED || err == WSAEHOSTUNREACH || err == WSAENETUNREACH || err == WSAENETDOWN || err == WSAEACCES || err == WSAEINVAL || err == WSAEADDRINUSE); return -1; } #else // Following code should handle both Berkeley-derived socket // implementations and Solaris. if (rc == -1) err = errno; if (err != 0) { errno = err; errno_assert ( errno == ECONNREFUSED || errno == ECONNRESET || errno == ETIMEDOUT || errno == EHOSTUNREACH || errno == ENETUNREACH || errno == ENETDOWN || errno == EINVAL); return -1; } #endif rc = tune_tcp_socket (s); rc = rc | tune_tcp_keepalives (s, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl); if (rc != 0) return -1; return 0; }
void zmq::tcp_connecter_t::out_event () { if (connect_timer_started) { cancel_timer (connect_timer_id); connect_timer_started = false; } rm_fd (handle); handle_valid = false; const fd_t fd = connect (); // Handle the error condition by attempt to reconnect. if (fd == retired_fd) { close (); add_reconnect_timer (); return; } tune_tcp_socket (fd); tune_tcp_keepalives (fd, options.tcp_keepalive, options.tcp_keepalive_cnt, options.tcp_keepalive_idle, options.tcp_keepalive_intvl); tune_tcp_retransmit_timeout (fd, options.tcp_retransmit_timeout); // remember our fd for ZMQ_SRCFD in messages socket->set_fd (fd); // Create the engine object for this connection. stream_engine_t *engine = new (std::nothrow) stream_engine_t (fd, options, endpoint); alloc_assert (engine); // Attach the engine to the corresponding session object. send_attach (session, engine); // Shut the connecter down. terminate (); socket->event_connected (endpoint, (int) fd); }