tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1358586 - in /tomcat/trunk/java/org/apache/catalina/tribes/transport/nio: NioReceiver.java NioSender.java
Date Sat, 07 Jul 2012 15:09:10 GMT
Author: markt
Date: Sat Jul  7 15:09:10 2012
New Revision: 1358586

URL: http://svn.apache.org/viewvc?rev=1358586&view=rev
Log:
Java 7 throws an exception when a socket option cannot be set.
Move option setting to before connection is completed since at least one option (traffic class)
can not be set after the connection is completed.

For NioReceiver, I don't see a way to set traffic class on an accepted connection so simply
remove it (it is ignored when using Java 6)

Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
    tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java

Modified: tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java?rev=1358586&r1=1358585&r2=1358586&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioReceiver.java Sat Jul  7
15:09:10 2012
@@ -130,13 +130,19 @@ public class NioReceiver extends Receive
         //set up the datagram channel
         if (this.getUdpPort()>0) {
             datagramChannel = DatagramChannel.open();
-            datagramChannel.configureBlocking(false);
+            configureDatagraChannel();
             //bind to the address to avoid security checks
             bindUdp(datagramChannel.socket(),getUdpPort(),getAutoBind());
         }
+    }
 
-
-
+    private void configureDatagraChannel() throws IOException {
+        datagramChannel.configureBlocking(false);
+        datagramChannel.socket().setSendBufferSize(getUdpTxBufSize());
+        datagramChannel.socket().setReceiveBufferSize(getUdpRxBufSize());
+        datagramChannel.socket().setReuseAddress(getSoReuseAddress());
+        datagramChannel.socket().setSoTimeout(getTimeout());
+        datagramChannel.socket().setTrafficClass(getSoTrafficClass());
     }
 
     public void addEvent(Runnable event) {
@@ -242,11 +248,6 @@ public class NioReceiver extends Receive
 
         if (selector!=null && datagramChannel!=null) {
             ObjectReader oreader = new ObjectReader(MAX_UDP_SIZE); //max size for a datagram
packet
-            datagramChannel.socket().setSendBufferSize(getUdpTxBufSize());
-            datagramChannel.socket().setReceiveBufferSize(getUdpRxBufSize());
-            datagramChannel.socket().setReuseAddress(getSoReuseAddress());
-            datagramChannel.socket().setSoTimeout(getTimeout());
-            datagramChannel.socket().setTrafficClass(getSoTrafficClass());
             registerChannel(selector,datagramChannel,SelectionKey.OP_READ,oreader);
         }
 
@@ -279,14 +280,13 @@ public class NioReceiver extends Receive
                     if (key.isAcceptable()) {
                         ServerSocketChannel server = (ServerSocketChannel) key.channel();
                         SocketChannel channel = server.accept();
-                        channel.socket().setReceiveBufferSize(getRxBufSize());
+                        channel.socket().setReceiveBufferSize(getTxBufSize());
                         channel.socket().setSendBufferSize(getTxBufSize());
                         channel.socket().setTcpNoDelay(getTcpNoDelay());
                         channel.socket().setKeepAlive(getSoKeepAlive());
                         channel.socket().setOOBInline(getOoBInline());
                         channel.socket().setReuseAddress(getSoReuseAddress());
                         channel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
-                        channel.socket().setTrafficClass(getSoTrafficClass());
                         channel.socket().setSoTimeout(getTimeout());
                         Object attach = new ObjectReader(channel);
                         registerChannel(selector,

Modified: tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java?rev=1358586&r1=1358585&r2=1358586&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/transport/nio/NioSender.java Sat Jul  7 15:09:10
2012
@@ -20,7 +20,6 @@ package org.apache.catalina.tribes.trans
 import java.io.EOFException;
 import java.io.IOException;
 import java.net.InetSocketAddress;
-import java.net.SocketException;
 import java.nio.ByteBuffer;
 import java.nio.channels.DatagramChannel;
 import java.nio.channels.SelectionKey;
@@ -132,13 +131,9 @@ public class NioSender extends AbstractS
         return false;
     }
 
-    private void completeConnect() throws SocketException {
-        //we connected, register ourselves for writing
-        setConnected(true);
-        connecting = false;
-        setRequestCount(0);
-        setConnectTime(System.currentTimeMillis());
+    private void configureSocket() throws IOException {
         if (socketChannel!=null) {
+            socketChannel.configureBlocking(false);
             socketChannel.socket().setSendBufferSize(getTxBufSize());
             socketChannel.socket().setReceiveBufferSize(getRxBufSize());
             socketChannel.socket().setSoTimeout((int)getTimeout());
@@ -150,6 +145,7 @@ public class NioSender extends AbstractS
             socketChannel.socket().setSoLinger(getSoLingerOn(),getSoLingerTime());
             socketChannel.socket().setTrafficClass(getSoTrafficClass());
         } else if (dataChannel!=null) {
+            dataChannel.configureBlocking(false);
             dataChannel.socket().setSendBufferSize(getUdpTxBufSize());
             dataChannel.socket().setReceiveBufferSize(getUdpRxBufSize());
             dataChannel.socket().setSoTimeout((int)getTimeout());
@@ -158,6 +154,14 @@ public class NioSender extends AbstractS
         }
     }
 
+    private void completeConnect() {
+        //we connected, register ourselves for writing
+        setConnected(true);
+        connecting = false;
+        setRequestCount(0);
+        setConnectTime(System.currentTimeMillis());
+    }
+
 
 
     protected boolean read() throws IOException {
@@ -232,7 +236,7 @@ public class NioSender extends AbstractS
             InetSocketAddress daddr = new InetSocketAddress(getAddress(),getUdpPort());
             if ( dataChannel != null ) throw new IOException("Datagram channel has already
been established. Connection might be in progress.");
             dataChannel = DatagramChannel.open();
-            dataChannel.configureBlocking(false);
+            configureSocket();
             dataChannel.connect(daddr);
             completeConnect();
             dataChannel.register(getSelector(),SelectionKey.OP_WRITE, this);
@@ -241,7 +245,7 @@ public class NioSender extends AbstractS
             InetSocketAddress addr = new InetSocketAddress(getAddress(),getPort());
             if ( socketChannel != null ) throw new IOException("Socket channel has already
been established. Connection might be in progress.");
             socketChannel = SocketChannel.open();
-            socketChannel.configureBlocking(false);
+            configureSocket();
             if ( socketChannel.connect(addr) ) {
                 completeConnect();
                 socketChannel.register(getSelector(), SelectionKey.OP_WRITE, this);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message