/// <summary> /// Begins receiving data first from the local buffer. If nothing is available /// from the remote endpoint. In both cases the caller will be notified in /// asynchronous way. /// </summary> /// <param name="handler">An instance of the incoming message handler.</param> public void ReceiveOrCallback(NetworkIncomingMessageHandler handler) { if (listener.IsAvailable(identifier)) { if (length > 0) { listener.Schedule(new NetworkPoolReceive(handler, new NetworkIncomingBufferMessage(this))); } else { Receive(handler); } } }
private TcpSocketSendCallback OnSent(Action callback) { return(sent => { listener.Schedule(() => { if (listener.IsAvailable(identifier)) { if (sent.Status != SocketStatus.OK || sent.Count == 0) { listener.Disconnect(identifier); } if (sent.Count > 0) { listener.HandleSent(identifier, sent.Count); } } parts.Remove(sent.Buffer.Offset + sent.Buffer.Count); offset = parts.Count > 0 ? parts.Max() : 0; callback.Invoke(); }); }); }
/// <summary> /// Sends the outgoing message to the remote endpoint. /// </summary> /// <param name="message">An instance of the outgoing message.</param> public void Send(NetworkOutgoingMessage message) { if (listener.IsAvailable(identifier)) { listener.Schedule(new NetworkPoolSend(identifier, outgoing, message)); } else { message.Release(); } }