public IMessage ReceiveMessage(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { var frames = new List <byte[]>(); var msg = new Msg(); msg.InitEmpty(); try { do { if (socket.TryReceive(ref msg, ReceiveWaitTimeout)) { frames.Add(msg.Data); } } while (msg.HasMore); if (frames.Count > 0) { ReceiveRate?.Increment(); return(Message.FromMultipartMessage(new MultipartMessage(frames))); } } finally { msg.Close(); } } return(null); }
public T TryReceive() { T lookup, message; if (!lookAheadQueue.TryTake(out message)) { messageQueue.TryTake(out message); } if (!messageQueue.TryTake(out lookup)) { dataAvailable.Reset(); if (messageQueue.TryTake(out lookup)) { lookAheadQueue.Add(lookup); dataAvailable.Set(); } } else { lookAheadQueue.Add(lookup); } ReceiveRate?.Increment(); return(message); }