private Receive ReadHandlers(ChannelRegistration registration) { return(message => { if (message is Udp.SuspendReading) { registration.DisableInterest(SocketAsyncOperation.Receive); return true; } if (message is Udp.ResumeReading) { registration.EnableInterest(SocketAsyncOperation.Receive); return true; } if (message is SelectionHandler.ChannelReadable) { DoReceive(registration, _bind.Handler); return true; } if (message is Udp.Unbind) { _log.Debug("Unbinding endpoint [{0}]", _bind.LocalAddress); try { Channel.Close(); Sender.Tell(IO.Udp.Unbound.Instance); _log.Debug("Unbound endpoint [{0}], stopping listener", _bind.LocalAddress); } finally { Context.Stop(Self); } return true; } return false; }); }
private Receive Connected(ChannelRegistration registration) { return(message => { if (message is UdpConnected.SuspendReading) { registration.DisableInterest(SocketAsyncOperation.Receive); return true; } if (message is UdpConnected.ResumeReading) { registration.EnableInterest(SocketAsyncOperation.Receive); return true; } if (message is SelectionHandler.ChannelReadable) { DoRead(registration, _connect.Handler); return true; } if (message is UdpConnected.Disconnect) { _log.Debug("Closing UDP connection to [{0}]", _connect.RemoteAddress); _channel.Close(); Sender.Tell(UdpConnected.Disconnected.Instance); _log.Debug("Connection closed to [{0}], stopping listener", _connect.RemoteAddress); Context.Stop(Self); return true; } var send = message as UdpConnected.Send; if (send != null && WritePending) { if (_udpConn.Settings.TraceLogging) { _log.Debug("Dropping write because queue is full"); } Sender.Tell(new UdpConnected.CommandFailed(send)); return true; } if (send != null && send.Payload.IsEmpty) { if (send.WantsAck) { Sender.Tell(send.Ack); } return true; } if (send != null) { _pendingSend = Tuple.Create(send, Sender); registration.EnableInterest(SocketAsyncOperation.Send); return true; } if (message is SelectionHandler.ChannelWritable) { DoWrite(); return true; } return false; }); }