// Called when our pipe is reactivated (able to accept more data). void zmq::udp_receiver_t::restart_input () { // Process any pending data. if (pending_bytes > 0) { ssize_t processed_bytes = 0; // decoder->process_buffer (pending_p, pending_bytes); // Flush any messages produced by the decoder to the pipe. session->flush (); if (processed_bytes < pending_bytes) { // Some data (still) could not be written to the pipe. pending_bytes -= processed_bytes; pending_p += processed_bytes; // Try again later. return; } // Done with unprocessed data. pending_bytes = 0; } // Reactivate polling. set_pollin (socket_handle); // Read any data that might have showed up on the socket in the mean time. in_event (retired_fd); }
void zmq::stream_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) { zmq_assert (!plugged); plugged = true; // Connect to session object. zmq_assert (!session); zmq_assert (session_); session = session_; socket = session-> get_socket (); // Connect to I/O threads poller object. io_object_t::plug (io_thread_); handle = add_fd (s); io_enabled = true; // Send the 'length' and 'flags' fields of the identity message. // The 'length' field is encoded in the long format. outpos = greeting_output_buffer; outpos [outsize++] = 0xff; put_uint64 (&outpos [outsize], options.identity_size + 1); outsize += 8; outpos [outsize++] = 0x7f; set_pollin (handle); set_pollout (handle); // Flush all the data that may have been already received downstream. in_event (); }
void xs::stream_engine_t::activate_in () { set_pollin (handle); // Speculative read. in_event (s); }
void zmq::pgm_receiver_t::activate_in () { // It is possible that the most recently used decoder // processed the whole buffer but failed to write // the last message into the pipe. if (pending_bytes == 0) { if (mru_decoder != NULL) mru_decoder->process_buffer (NULL, 0); return; } zmq_assert (mru_decoder != NULL); zmq_assert (pending_ptr != NULL); // Ask the decoder to process remaining data. size_t n = mru_decoder->process_buffer (pending_ptr, pending_bytes); pending_bytes -= n; if (pending_bytes > 0) return; // Resume polling. set_pollin (pipe_handle); set_pollin (socket_handle); in_event (); }
void Server::netupdate_IN(float deltaTime) { //Handle all new incomming messages while (true) { Packet* rec = connection.receive(); if (rec == 0) // no more messages to handle break; //extract net index Uint8 index_short; *rec >> index_short; NET_INDEX index = NET_INDEX(index_short); switch (index) { case PING: in_ping(rec); break; case PING_ACK: in_ping_ACK(rec); break; case NEW_CONNECTION: in_new_connection(rec); break; case NEW_CONNECTION_ACK: in_new_connection_ACK(rec); break; case EVENT: in_event(rec); break; case EVENT_ACK: in_event_ACK(rec); break; case FRAME: in_frame(rec); break; default: //package error? break; } delete rec; } }
void zmq::zmq_engine_t::activate_in () { set_pollin (handle); // Speculative read. in_event (); }
void zmq::stream_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) { zmq_assert (!plugged); plugged = true; // Connect to session object. zmq_assert (!session); zmq_assert (session_); session = session_; socket = session-> get_socket (); // Connect to I/O threads poller object. io_object_t::plug (io_thread_); handle = add_fd (s); io_error = false; if (options.raw_socket) { // no handshaking for raw sock, instantiate raw encoder and decoders encoder = new (std::nothrow) raw_encoder_t (out_batch_size); alloc_assert (encoder); decoder = new (std::nothrow) raw_decoder_t (in_batch_size); alloc_assert (decoder); // disable handshaking for raw socket handshaking = false; next_msg = &stream_engine_t::pull_msg_from_session; process_msg = &stream_engine_t::push_msg_to_session; if (options.raw_notify) { // For raw sockets, send an initial 0-length message to the // application so that it knows a peer has connected. msg_t connector; connector.init(); push_msg_to_session (&connector); connector.close(); session->flush (); } } else { // start optional timer, to prevent handshake hanging on no input set_handshake_timer (); // Send the 'length' and 'flags' fields of the identity message. // The 'length' field is encoded in the long format. outpos = greeting_send; outpos [outsize++] = 0xff; put_uint64 (&outpos [outsize], options.identity_size + 1); outsize += 8; outpos [outsize++] = 0x7f; } set_pollin (handle); set_pollout (handle); // Flush all the data that may have been already received downstream. in_event (); }
void zmq::udp_engine_t::restart_input () { if (!recv_enabled) return; set_pollin (handle); in_event (); }
void zmq::pgm_receiver_t::timer_event (int token) { zmq_assert (token == rx_timer_id); // Timer cancels on return by poller_base. has_rx_timer = false; in_event (); }
void xs::pgm_sender_t::timer_event (handle_t handle_) { // Timer cancels on return by io_thread. if (handle_ == rx_timer) { rx_timer = NULL; in_event (retired_fd); } else if (handle_ == tx_timer) { tx_timer = NULL; out_event (retired_fd); } else xs_assert (false); }
void zmq::pgm_sender_t::timer_event (int token) { // Timer cancels on return by poller_base. if (token == rx_timer_id) { has_rx_timer = false; in_event (); } else if (token == tx_timer_id) { has_tx_timer = false; out_event (); } else zmq_assert (false); }
void zmq::zmq_engine_t::plug (i_inout *inout_) { zmq_assert (!inout); encoder.set_inout (inout_); decoder.set_inout (inout_); handle = add_fd (tcp_socket.get_fd ()); set_pollin (handle); set_pollout (handle); inout = inout_; // Flush all the data that may have been already received downstream. in_event (); }
void zmq::stream_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) { zmq_assert (!plugged); plugged = true; // Connect to session object. zmq_assert (!session); zmq_assert (session_); session = session_; socket = session-> get_socket (); // Connect to I/O threads poller object. io_object_t::plug (io_thread_); handle = add_fd (s); io_error = false; if (options.raw_sock) { // no handshaking for raw sock, instantiate raw encoder and decoders encoder = new (std::nothrow) raw_encoder_t (out_batch_size); alloc_assert (encoder); decoder = new (std::nothrow) raw_decoder_t (in_batch_size); alloc_assert (decoder); // disable handshaking for raw socket handshaking = false; read_msg = &stream_engine_t::pull_msg_from_session; write_msg = &stream_engine_t::push_msg_to_session; } else { // Send the 'length' and 'flags' fields of the identity message. // The 'length' field is encoded in the long format. outpos = greeting_send; outpos [outsize++] = 0xff; put_uint64 (&outpos [outsize], options.identity_size + 1); outsize += 8; outpos [outsize++] = 0x7f; } set_pollin (handle); set_pollout (handle); // Flush all the data that may have been already received downstream. in_event (); }
void zmq::pgm_sender_t::timer_event (int token) { // Timer cancels on return by poller_base. if (token == rx_timer_id) { has_rx_timer = false; in_event (); } else if (token == tx_timer_id) { // Restart polling handle and retry sending has_tx_timer = false; set_pollout (handle); out_event (); } else zmq_assert (false); }
void zmq::stream_engine_t::restart_input () { zmq_assert (input_stopped); zmq_assert (session != NULL); zmq_assert (decoder != NULL); int rc = (this->*process_msg) (decoder->msg ()); if (rc == -1) { if (errno == EAGAIN) session->flush (); else error (protocol_error); return; } while (insize > 0) { size_t processed = 0; rc = decoder->decode (inpos, insize, processed); zmq_assert (processed <= insize); inpos += processed; insize -= processed; if (rc == 0 || rc == -1) break; rc = (this->*process_msg) (decoder->msg ()); if (rc == -1) break; } if (rc == -1 && errno == EAGAIN) session->flush (); else if (io_error) error (connection_error); else if (rc == -1) error (protocol_error); else { input_stopped = false; set_pollin (handle); session->flush (); // Speculative read. in_event (); } }
void zmq::stream_engine_t::activate_in () { if (input_error) { // There was an input error but the engine could not // be terminated (due to the stalled decoder). // Flush the pending message and terminate the engine now. decoder.process_buffer (inpos, 0); zmq_assert (!decoder.stalled ()); session->flush (); error (); return; } set_pollin (handle); // Speculative read. in_event (); }
void zmq::stream_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) { zmq_assert (!plugged); plugged = true; // Connect to session object. zmq_assert (!session); zmq_assert (session_); encoder.set_session (session_); decoder.set_session (session_); session = session_; // Connect to I/O threads poller object. io_object_t::plug (io_thread_); handle = add_fd (s); set_pollin (handle); set_pollout (handle); // Flush all the data that may have been already received downstream. in_event (); }
void zmq::zmq_engine_t::plug (io_thread_t *io_thread_, i_inout *inout_) { zmq_assert (!plugged); plugged = true; ephemeral_inout = NULL; // Connect to session/init object. zmq_assert (!inout); zmq_assert (inout_); encoder.set_inout (inout_); decoder.set_inout (inout_); inout = inout_; // Connect to I/O threads poller object. io_object_t::plug (io_thread_); handle = add_fd (tcp_socket.get_fd ()); set_pollin (handle); set_pollout (handle); // Flush all the data that may have been already received downstream. in_event (); }
void xs::stream_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) { xs_assert (!plugged); plugged = true; leftover_session = NULL; // Connect to session object. xs_assert (!session); xs_assert (session_); encoder.set_session (session_); decoder.set_session (session_); session = session_; // Connect to the io_thread object. io_object_t::plug (io_thread_); handle = add_fd (s); set_pollin (handle); set_pollout (handle); // Flush all the data that may have been already received downstream. in_event (s); }
void zmq::pgm_receiver_t::restart_input () { zmq_assert (session != NULL); zmq_assert (active_tsi != NULL); const peers_t::iterator it = peers.find (*active_tsi); zmq_assert (it != peers.end ()); zmq_assert (it->second.joined); // Push the pending message into the session. int rc = session->push_msg (it->second.decoder->msg ()); errno_assert (rc == 0); if (insize > 0) { rc = process_input (it->second.decoder); if (rc == -1) { // HWM reached; we will try later. if (errno == EAGAIN) { session->flush (); return; } // Data error. Delete message decoder, mark the // peer as not joined and drop remaining data. it->second.joined = false; delete it->second.decoder; it->second.decoder = NULL; insize = 0; } } // Resume polling. set_pollin (pipe_handle); set_pollin (socket_handle); active_tsi = NULL; in_event (); }
void zmq::sctp_engine_t::head (pipe_t *pipe_, int64_t position_) { engine_base_t <true,true>::head (pipe_, position_); in_event (handle); }
void zmq::zmq_engine_t::resume_input () { set_pollin (handle); in_event (); }
void zmq::stream_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) { zmq_assert (!_plugged); _plugged = true; // Connect to session object. zmq_assert (!_session); zmq_assert (session_); _session = session_; _socket = _session->get_socket (); // Connect to I/O threads poller object. io_object_t::plug (io_thread_); _handle = add_fd (_s); _io_error = false; if (_options.raw_socket) { // no handshaking for raw sock, instantiate raw encoder and decoders _encoder = new (std::nothrow) raw_encoder_t (out_batch_size); alloc_assert (_encoder); _decoder = new (std::nothrow) raw_decoder_t (in_batch_size); alloc_assert (_decoder); // disable handshaking for raw socket _handshaking = false; _next_msg = &stream_engine_t::pull_msg_from_session; _process_msg = &stream_engine_t::push_raw_msg_to_session; properties_t properties; if (init_properties (properties)) { // Compile metadata. zmq_assert (_metadata == NULL); _metadata = new (std::nothrow) metadata_t (properties); alloc_assert (_metadata); } if (_options.raw_notify) { // For raw sockets, send an initial 0-length message to the // application so that it knows a peer has connected. msg_t connector; connector.init (); push_raw_msg_to_session (&connector); connector.close (); _session->flush (); } } else { // start optional timer, to prevent handshake hanging on no input set_handshake_timer (); // Send the 'length' and 'flags' fields of the routing id message. // The 'length' field is encoded in the long format. _outpos = _greeting_send; _outpos[_outsize++] = UCHAR_MAX; put_uint64 (&_outpos[_outsize], _options.routing_id_size + 1); _outsize += 8; _outpos[_outsize++] = 0x7f; } set_pollin (_handle); set_pollout (_handle); // Flush all the data that may have been already received downstream. in_event (); }
void xs::pgm_receiver_t::timer_event (handle_t handle_) { xs_assert (handle_ == rx_timer); rx_timer = NULL; in_event (retired_fd); }