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); } }