public QueueDsl CreateQueue(out Queue queue, Action <Queue> config = null) { queue = Queue = new Queue { Name = TestData.RandomAlphaString(), Items = new List <QueueItem>() }; config?.Invoke(queue); _session.Context.Queues.Add(queue); _session.Flush(); return(this); }
public void ActivateIn() { if (m_state == State.Stuck) { Debug.Assert(m_decoder != null); Debug.Assert(m_pendingData != null); // Ask the decoder to process remaining data. int n = m_decoder.ProcessBuffer(m_pendingData, m_pendingBytes); m_pendingBytes -= n; m_session.Flush(); if (m_pendingBytes == 0) { m_state = State.Receiving; BeginReceive(); } } }
void ProcessInput() { while (m_pendingBytes > 0) { var result = m_decoder.Decode(m_pendingData, m_pendingBytes, out var processed); m_pendingData.AdvanceOffset(processed); m_pendingBytes -= processed; if (result == DecodeResult.Error) { m_joined = false; Error(); return; } if (result == DecodeResult.Processing) { break; } var pushResult = m_decoder.PushMsg(m_session.PushMsg); if (pushResult == PushMsgResult.Full) { m_state = State.Stuck; m_session.Flush(); return; } else if (pushResult == PushMsgResult.Error) { m_joined = false; Error(); return; } } m_session.Flush(); BeginReceive(); }
private void Handle(Action action, SocketError socketError, int bytesTransferred) { switch (m_state) { case State.Closed: switch (action) { case Action.Start: if (m_options.RawSocket) { m_encoder = new RawEncoder(Config.OutBatchSize, m_session, m_options.Endian); m_decoder = new RawDecoder(Config.InBatchSize, m_options.MaxMessageSize, m_session, m_options.Endian); Activate(); } else { m_state = State.Handshaking; m_handshakeState = HandshakeState.Closed; HandleHandshake(action, socketError, bytesTransferred); } break; } break; case State.Handshaking: HandleHandshake(action, socketError, bytesTransferred); break; case State.Active: switch (action) { case Action.InCompleted: m_insize = EndRead(socketError, bytesTransferred); ProcessInput(); break; case Action.ActivateIn: // if we stuck let's continue, other than that nothing to do if (m_receivingState == ReceiveState.Stuck) { m_receivingState = ReceiveState.Active; ProcessInput(); } break; case Action.OutCompleted: int bytesSent = EndWrite(socketError, bytesTransferred); // IO error has occurred. We stop waiting for output events. // The engine is not terminated until we detect input error; // this is necessary to prevent losing incoming messages. if (bytesSent == -1) { m_sendingState = SendState.Error; } else { m_outpos.AdvanceOffset(bytesSent); m_outsize -= bytesSent; BeginSending(); } break; case Action.ActivateOut: // if we idle we start sending, other than do nothing if (m_sendingState == SendState.Idle) { m_sendingState = SendState.Active; BeginSending(); } break; default: Debug.Assert(false); break; } break; case State.Stalled: switch (action) { case Action.ActivateIn: // 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. m_decoder.ProcessBuffer(m_inpos, 0); Debug.Assert(!m_decoder.Stalled()); m_session.Flush(); Error(); break; case Action.ActivateOut: break; } break; } }