Browse files

fix window size negotiation

  • Loading branch information...
1 parent 846775e commit 378c2d665a67e7f3b3a145355a63a46f4d42e80c @emuckenhuber committed May 30, 2012
View
4 src/main/java/org/jboss/remoting3/remote/RemoteConnectionChannel.java
@@ -397,6 +397,10 @@ public boolean supportsOption(final Option<?> option) {
return option.cast(maxInboundMessages);
} else if (option == RemotingOptions.MAX_OUTBOUND_MESSAGES) {
return option.cast(maxOutboundMessages);
+ } else if (option == RemotingOptions.RECEIVE_WINDOW_SIZE) {
+ return option.cast(inboundWindow);
+ } else if (option == RemotingOptions.TRANSMIT_WINDOW_SIZE) {
+ return option.cast(outboundWindow);
} else {
return null;
}
View
6 src/main/java/org/jboss/remoting3/remote/RemoteReadListener.java
@@ -201,8 +201,10 @@ public void handleEvent(final ConnectedMessageChannel channel) {
replyBuffer.clear();
replyBuffer.put(Protocol.CHANNEL_OPEN_ACK);
replyBuffer.putInt(channelId);
- ProtocolUtils.writeInt(replyBuffer, 0x80, outboundWindow);
- ProtocolUtils.writeShort(replyBuffer, 0x81, outboundMessages);
+ ProtocolUtils.writeInt(replyBuffer, 0x80, inboundWindow);
+ ProtocolUtils.writeShort(replyBuffer, 0x81, inboundMessages);
+ ProtocolUtils.writeInt(replyBuffer, 0x82, outboundWindow);
+ ProtocolUtils.writeShort(replyBuffer, 0x83, outboundMessages);
replyBuffer.put((byte) 0);
replyBuffer.flip();
ok2 = true;
View
44 src/test/java/org/jboss/remoting3/test/ConnectionTestCase.java
@@ -38,10 +38,12 @@
import org.jboss.remoting3.OpenListener;
import org.jboss.remoting3.Registration;
import org.jboss.remoting3.Remoting;
+import org.jboss.remoting3.RemotingOptions;
import org.jboss.remoting3.remote.RemoteConnectionProviderFactory;
import org.jboss.remoting3.security.SimpleServerAuthenticationProvider;
import org.jboss.remoting3.spi.NetworkServerProvider;
import org.junit.After;
+import org.junit.Assert;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
@@ -198,5 +200,47 @@ public void rejectUnknownService() throws IOException {
}
}
+ private static final int MAX_SERVER_RECEIVE = 0x18000;
+ private static final int MAX_SERVER_TRANSMIT = 0x14000;
+
+ @Test
+ public void testChannelOptions() throws IOException {
+ serverEndpoint.registerService("test", new OpenListener() {
+ @Override
+ public void channelOpened(Channel channel) {
+ //
+ Assert.assertTrue(channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE) <= MAX_SERVER_RECEIVE);
+ Assert.assertTrue(channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE) <= MAX_SERVER_TRANSMIT);
+ }
+
+ @Override
+ public void registrationTerminated() {
+ //
+ }
+ }, OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, MAX_SERVER_RECEIVE, RemotingOptions.TRANSMIT_WINDOW_SIZE, MAX_SERVER_TRANSMIT));
+
+ final Connection connection = clientEndpoint.connect("remote", new InetSocketAddress("::1", 0), new InetSocketAddress("::1", 30123), OptionMap.EMPTY, "bob", "test", "pass".toCharArray()).get();
+ IoFuture<Channel> future = connection.openChannel("test", OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, 0x8000, RemotingOptions.TRANSMIT_WINDOW_SIZE, 0x12000));
+ Channel channel = future.get();
+ try {
+ Assert.assertEquals("transmit", 0x12000, (int) channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE));
+ Assert.assertEquals("receive", 0x8000, (int) channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE));
+ } finally {
+ if(channel != null) {
+ channel.close();
+ }
+ }
+ future = connection.openChannel("test", OptionMap.create(RemotingOptions.RECEIVE_WINDOW_SIZE, 0x24000, RemotingOptions.TRANSMIT_WINDOW_SIZE, 0x24000));
+ channel = future.get();
+ try {
+ Assert.assertEquals("transmit", MAX_SERVER_RECEIVE, (int) channel.getOption(RemotingOptions.TRANSMIT_WINDOW_SIZE));
+ Assert.assertEquals("receive", MAX_SERVER_TRANSMIT, (int) channel.getOption(RemotingOptions.RECEIVE_WINDOW_SIZE));
+ } finally {
+ if(channel != null) {
+ channel.close();
+ }
+ }
+ }
+
}

0 comments on commit 378c2d6

Please sign in to comment.