public void Run(Action <EstablishedConnectionTest> body) { Run((UnacceptedConnectionTest x) => { try { ServerSideChannel.Socket.Blocking = false; // JVM Akka always excpect CONNECT, which seems incorrect // We will not receive a CONNECT if Socket.BeginConnect completed synchronously // We therfore just igenore the CONNECT if it is in the queue //What JVM Akka does: InterestCallReceiver.ExpectMsg((int)SocketAsyncOperation.Connect); if (InterestCallReceiver.ReceiveWhile <object>(m => m is int && (int)m == (int)SocketAsyncOperation.Connect, TimeSpan.Zero, TimeSpan.Zero, 1).Any()) { Selector.Send(ConnectionActor, SelectionHandler.ChannelConnectable.Instance); // Only send ChannelConnectable if we did not complete synchronously } UserHandler.ExpectMsg <Tcp.Connected>(message => ((IPEndPoint)message.RemoteAddress).Port.ShouldBe(ServerAddress.Port)); //TODO: compare full endpoint, not only port UserHandler.Send(ConnectionActor, new Tcp.Register(ConnectionHandler.Ref, KeepOpenOnPeerClosed, UseResumeWriting)); if (!PullMode) { InterestCallReceiver.ExpectMsg((int)SocketAsyncOperation.Receive); } body(this); } finally { ServerSideChannel.Close(); } }); }
public void PullFromServerSide(int remaining, int remainingRetries, ByteBuffer into) { if (remainingRetries <= 0) { throw new AssertionFailedException("Pulling took too many loops, remaining data: " + remaining); } if (remaining > 0) { if (InterestCallReceiver.HasMessages) { InterestCallReceiver.ExpectMsg((int)SocketAsyncOperation.Send); } Selector.Send(ConnectionActor, SelectionHandler.ChannelWritable.Instance); var read = ServerSideChannel.Read(into); if (read == -1) { throw new IllegalStateException("Connection was closed unexpectedly with remaining bytes " + remaining); } if (read == 0) { throw new IllegalStateException("Made no progress"); } PullFromServerSide(remaining - read, remainingRetries - 1, into); } }