public void Plug(IOThread ioThread, SessionBase session) { m_session = session; m_encoder.SetMsgSource(session); // get the first message from the session because we don't want to send identities var msg = new Msg(); msg.InitEmpty(); bool ok = session.PullMsg(ref msg); if (ok) { msg.Close(); } AddSocket(m_socket); if (!m_delayedStart) { StartConnecting(); } else { m_state = State.Delaying; AddTimer(GetNewReconnectIvl(), ReconnectTimerId); } }
public void Plug(IOThread ioThread, SessionBase session) { m_session = session; // get the first message from the session because we don't want to send identities var msg = new Msg(); msg.InitEmpty(); var pullResult = session.PullMsg(ref msg); if (pullResult == PullMsgResult.Ok) { msg.Close(); } Assumes.NotNull(m_socket); AddSocket(m_socket); if (!m_delayedStart) { StartConnecting(); } else { m_state = State.Delaying; AddTimer(GetNewReconnectIvl(), ReconnectTimerId); } }
private void BeginSending() { // If write buffer is empty, try to read new data from the encoder. if (m_writeSize == 0) { // First two bytes (sizeof uint16_t) are used to store message // offset in following steps. Note that by passing our buffer to // the get data function we prevent it from returning its own buffer. ushort offset = 0xffff; var buffer = new ByteArraySegment(m_outBuffer, sizeof(ushort)); int bufferSize = m_outBufferSize - sizeof(ushort); int bytes = m_encoder.Encode(ref buffer, bufferSize); while (bytes < bufferSize) { if (!m_moreFlag && offset == 0xffff) { offset = (ushort)bytes; } Msg msg = new Msg(); if (m_session.PullMsg(ref msg) != PullMsgResult.Ok) { break; } m_moreFlag = msg.HasMore; m_encoder.LoadMsg(ref msg); buffer = buffer + bytes; var n = m_encoder.Encode(ref buffer, bufferSize - bytes); bytes += n; } // If there are no data to write stop polling for output. if (bytes == 0) { m_state = State.ActiveSendingIdle; return; } // Put offset information in the buffer. m_writeSize = bytes + sizeof(ushort); m_outBuffer.PutUnsignedShort(m_options.Endian, offset, 0); } try { m_socket.Send((byte[])m_outBuffer, m_outBuffer.Offset, m_writeSize, SocketFlags.None); } catch (SocketException ex) { if (ex.SocketErrorCode == SocketError.ConnectionReset) { Error(); } else { throw NetMQException.Create(ex.SocketErrorCode, ex); } } }
private void DropSubscriptions() { var msg = new Msg(); msg.InitEmpty(); while (m_session.PullMsg(ref msg)) { msg.Close(); } }
public void Plug(IOThread ioThread, SessionBase session) { m_encoder.SetMsgSource(session); // get the first message from the session because we don't want to send identities var msg = new Msg(); msg.InitEmpty(); bool ok = session.PullMsg(ref msg); if (ok) { msg.Close(); } AddSocket(m_socket); m_state = State.Connecting; m_socket.Connect(m_pgmAddress.Address); }