Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 87902 invoked from network); 18 Apr 2006 06:00:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Apr 2006 06:00:33 -0000 Received: (qmail 79130 invoked by uid 500); 18 Apr 2006 06:00:33 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 79089 invoked by uid 500); 18 Apr 2006 06:00:32 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 79078 invoked by uid 99); 18 Apr 2006 06:00:32 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Apr 2006 23:00:32 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 17 Apr 2006 23:00:31 -0700 Received: (qmail 87728 invoked by uid 65534); 18 Apr 2006 06:00:10 -0000 Message-ID: <20060418060010.87727.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r394852 - in /directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support: DatagramSessionConfigImpl.java DatagramSessionImpl.java SocketSessionConfigImpl.java SocketSessionImpl.java Date: Tue, 18 Apr 2006 06:00:06 -0000 To: commits@directory.apache.org From: trustin@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: trustin Date: Mon Apr 17 23:00:01 2006 New Revision: 394852 URL: http://svn.apache.org/viewcvs?rev=394852&view=rev Log: Fixed issue: DIRMINA-200 (IBM iSeries throws unexpected SocketException) * Socket/DatagramSessionConfigImpl now pre-calculates default values and availability of socket options Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionConfigImpl.java directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionConfigImpl.java directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionConfigImpl.java URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionConfigImpl.java?rev=394852&r1=394851&r2=394852&view=diff ============================================================================== --- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionConfigImpl.java (original) +++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionConfigImpl.java Mon Apr 17 23:00:01 2006 @@ -31,11 +31,99 @@ */ public class DatagramSessionConfigImpl extends BaseIoSessionConfig implements DatagramSessionConfig { - private boolean broadcast; - private boolean reuseAddress; - private int receiveBufferSize; - private int sendBufferSize; - private int trafficClass; + private static boolean SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false; + private static boolean SET_SEND_BUFFER_SIZE_AVAILABLE = false; + private static boolean GET_TRAFFIC_CLASS_AVAILABLE = false; + private static boolean SET_TRAFFIC_CLASS_AVAILABLE = false; + + private static boolean DEFAULT_BROADCAST; + private static boolean DEFAULT_REUSE_ADDRESS; + private static int DEFAULT_RECEIVE_BUFFER_SIZE; + private static int DEFAULT_SEND_BUFFER_SIZE; + private static int DEFAULT_TRAFFIC_CLASS; + + static + { + initialize(); + } + + private static void initialize() + { + DatagramSocket socket = null; + + try + { + socket = new DatagramSocket(); + DEFAULT_BROADCAST = socket.getBroadcast(); + DEFAULT_REUSE_ADDRESS = socket.getReuseAddress(); + DEFAULT_RECEIVE_BUFFER_SIZE = socket.getReceiveBufferSize(); + DEFAULT_SEND_BUFFER_SIZE = socket.getSendBufferSize(); + + // Check if setReceiveBufferSize is supported. + try + { + socket.setReceiveBufferSize(DEFAULT_RECEIVE_BUFFER_SIZE); + SET_RECEIVE_BUFFER_SIZE_AVAILABLE = true; + } + catch( SocketException e ) + { + SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false; + } + + // Check if setSendBufferSize is supported. + try + { + socket.setSendBufferSize(DEFAULT_SEND_BUFFER_SIZE); + SET_SEND_BUFFER_SIZE_AVAILABLE = true; + } + catch( SocketException e ) + { + SET_SEND_BUFFER_SIZE_AVAILABLE = false; + } + + // Check if getTrafficClass is supported. + try + { + DEFAULT_TRAFFIC_CLASS = socket.getTrafficClass(); + GET_TRAFFIC_CLASS_AVAILABLE = true; + } + catch( SocketException e ) + { + GET_TRAFFIC_CLASS_AVAILABLE = false; + DEFAULT_TRAFFIC_CLASS = 0; + } + } catch (SocketException e) { + throw new ExceptionInInitializerError(e); + } + finally { + if( socket != null ) + { + socket.close(); + } + } + } + + public static boolean isSetReceiveBufferSizeAvailable() { + return SET_RECEIVE_BUFFER_SIZE_AVAILABLE; + } + + public static boolean isSetSendBufferSizeAvailable() { + return SET_SEND_BUFFER_SIZE_AVAILABLE; + } + + public static boolean isGetTrafficClassAvailable() { + return GET_TRAFFIC_CLASS_AVAILABLE; + } + + public static boolean isSetTrafficClassAvailable() { + return SET_TRAFFIC_CLASS_AVAILABLE; + } + + private boolean broadcast = DEFAULT_BROADCAST; + private boolean reuseAddress = DEFAULT_REUSE_ADDRESS; + private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE; + private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE; + private int trafficClass = DEFAULT_TRAFFIC_CLASS; /** * Creates a new instance. Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java?rev=394852&r1=394851&r2=394852&view=diff ============================================================================== --- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java (original) +++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramSessionImpl.java Mon Apr 17 23:00:01 2006 @@ -45,7 +45,7 @@ class DatagramSessionImpl extends BaseIoSession { private final IoService wrapperManager; - private final DatagramSessionConfig config = new DatagramSessionConfigImpl(); + private final DatagramSessionConfig config = new SessionConfigImpl(); private final DatagramService managerDelegate; private final DatagramFilterChain filterChain; private final DatagramChannel ch; @@ -199,7 +199,7 @@ return readBufferSize; } - private class DatagramSessionConfigImpl extends BaseIoSessionConfig implements DatagramSessionConfig + private class SessionConfigImpl extends BaseIoSessionConfig implements DatagramSessionConfig { public int getReceiveBufferSize() { @@ -215,15 +215,18 @@ public void setReceiveBufferSize( int receiveBufferSize ) { - try - { - ch.socket().setReceiveBufferSize( receiveBufferSize ); - DatagramSessionImpl.this.readBufferSize = receiveBufferSize; - } - catch( SocketException e ) - { - throw new RuntimeIOException( e ); - } + if( DatagramSessionConfigImpl.isSetReceiveBufferSizeAvailable() ) + { + try + { + ch.socket().setReceiveBufferSize( receiveBufferSize ); + DatagramSessionImpl.this.readBufferSize = receiveBufferSize; + } + catch( SocketException e ) + { + throw new RuntimeIOException( e ); + } + } } public boolean isBroadcast() @@ -264,14 +267,17 @@ public void setSendBufferSize( int sendBufferSize ) { - try - { - ch.socket().setSendBufferSize( sendBufferSize ); - } - catch( SocketException e ) - { - throw new RuntimeIOException( e ); - } + if( DatagramSessionConfigImpl.isSetSendBufferSizeAvailable() ) + { + try + { + ch.socket().setSendBufferSize( sendBufferSize ); + } + catch( SocketException e ) + { + throw new RuntimeIOException( e ); + } + } } public boolean isReuseAddress() @@ -300,26 +306,36 @@ public int getTrafficClass() { - try - { - return ch.socket().getTrafficClass(); - } - catch( SocketException e ) - { - throw new RuntimeIOException( e ); - } + if( DatagramSessionConfigImpl.isGetTrafficClassAvailable() ) + { + try + { + return ch.socket().getTrafficClass(); + } + catch( SocketException e ) + { + throw new RuntimeIOException( e ); + } + } + else + { + return 0; + } } public void setTrafficClass( int trafficClass ) { - try - { - ch.socket().setTrafficClass( trafficClass ); - } - catch( SocketException e ) - { - throw new RuntimeIOException( e ); - } + if( DatagramSessionConfigImpl.isSetTrafficClassAvailable() ) + { + try + { + ch.socket().setTrafficClass( trafficClass ); + } + catch( SocketException e ) + { + throw new RuntimeIOException( e ); + } + } } } } Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionConfigImpl.java URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionConfigImpl.java?rev=394852&r1=394851&r2=394852&view=diff ============================================================================== --- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionConfigImpl.java (original) +++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionConfigImpl.java Mon Apr 17 23:00:01 2006 @@ -24,7 +24,6 @@ import org.apache.mina.common.ExceptionMonitor; import org.apache.mina.common.IoConnectorConfig; -import org.apache.mina.common.RuntimeIOException; import org.apache.mina.common.support.BaseIoSessionConfig; import org.apache.mina.transport.socket.nio.SocketConnector; import org.apache.mina.transport.socket.nio.SocketSessionConfig; @@ -37,53 +36,122 @@ */ public class SocketSessionConfigImpl extends BaseIoSessionConfig implements SocketSessionConfig { - private boolean reuseAddress; - private int receiveBufferSize; - private int sendBufferSize; - private int trafficClass; - private boolean keepAlive; - private boolean oobInline; - private int soLinger; - private boolean tcpNoDelay; + private static boolean SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false; + private static boolean SET_SEND_BUFFER_SIZE_AVAILABLE = false; + private static boolean GET_TRAFFIC_CLASS_AVAILABLE = false; + private static boolean SET_TRAFFIC_CLASS_AVAILABLE = false; + + private static boolean DEFAULT_REUSE_ADDRESS; + private static int DEFAULT_RECEIVE_BUFFER_SIZE; + private static int DEFAULT_SEND_BUFFER_SIZE; + private static int DEFAULT_TRAFFIC_CLASS; + private static boolean DEFAULT_KEEP_ALIVE; + private static boolean DEFAULT_OOB_INLINE; + private static int DEFAULT_SO_LINGER; + private static boolean DEFAULT_TCP_NO_DELAY; + + static + { + initialize(); + } + + private static void initialize() + { + Socket socket = null; + + socket = new Socket(); + + try + { + DEFAULT_REUSE_ADDRESS = socket.getReuseAddress(); + DEFAULT_RECEIVE_BUFFER_SIZE = socket.getReceiveBufferSize(); + DEFAULT_SEND_BUFFER_SIZE = socket.getSendBufferSize(); + DEFAULT_KEEP_ALIVE = socket.getKeepAlive(); + DEFAULT_OOB_INLINE = socket.getOOBInline(); + DEFAULT_SO_LINGER = socket.getSoLinger(); + DEFAULT_TCP_NO_DELAY = socket.getTcpNoDelay(); + + // Check if setReceiveBufferSize is supported. + try + { + socket.setReceiveBufferSize(DEFAULT_RECEIVE_BUFFER_SIZE); + SET_RECEIVE_BUFFER_SIZE_AVAILABLE = true; + } + catch( SocketException e ) + { + SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false; + } + + // Check if setSendBufferSize is supported. + try + { + socket.setSendBufferSize(DEFAULT_SEND_BUFFER_SIZE); + SET_SEND_BUFFER_SIZE_AVAILABLE = true; + } + catch( SocketException e ) + { + SET_SEND_BUFFER_SIZE_AVAILABLE = false; + } + + // Check if getTrafficClass is supported. + try + { + DEFAULT_TRAFFIC_CLASS = socket.getTrafficClass(); + GET_TRAFFIC_CLASS_AVAILABLE = true; + } + catch( SocketException e ) + { + GET_TRAFFIC_CLASS_AVAILABLE = false; + DEFAULT_TRAFFIC_CLASS = 0; + } + } catch (SocketException e) { + throw new ExceptionInInitializerError(e); + } + finally { + if( socket != null ) + { + try + { + socket.close(); + } + catch( IOException e ) + { + ExceptionMonitor.getInstance().exceptionCaught(e); + } + } + } + } + + public static boolean isSetReceiveBufferSizeAvailable() { + return SET_RECEIVE_BUFFER_SIZE_AVAILABLE; + } + + public static boolean isSetSendBufferSizeAvailable() { + return SET_SEND_BUFFER_SIZE_AVAILABLE; + } + + public static boolean isGetTrafficClassAvailable() { + return GET_TRAFFIC_CLASS_AVAILABLE; + } + + public static boolean isSetTrafficClassAvailable() { + return SET_TRAFFIC_CLASS_AVAILABLE; + } + + private boolean reuseAddress = DEFAULT_REUSE_ADDRESS; + private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE; + private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE; + private int trafficClass = DEFAULT_TRAFFIC_CLASS; + private boolean keepAlive = DEFAULT_KEEP_ALIVE; + private boolean oobInline = DEFAULT_OOB_INLINE; + private int soLinger = DEFAULT_SO_LINGER; + private boolean tcpNoDelay = DEFAULT_TCP_NO_DELAY; /** * Creates a new instance. - * - * @throws RuntimeIOException if failed to get the default configuration */ public SocketSessionConfigImpl() { - Socket s = null; - try - { - s = new Socket(); - reuseAddress = s.getReuseAddress(); - receiveBufferSize = s.getReceiveBufferSize(); - sendBufferSize = s.getSendBufferSize(); - trafficClass = s.getTrafficClass(); - keepAlive = s.getKeepAlive(); - oobInline = s.getOOBInline(); - soLinger = s.getSoLinger(); - tcpNoDelay = s.getTcpNoDelay(); - } - catch( SocketException e ) - { - throw new RuntimeIOException( "Failed to get the default configuration.", e ); - } - finally - { - if( s != null ) - { - try - { - s.close(); - } - catch( IOException e ) - { - ExceptionMonitor.getInstance().exceptionCaught( e ); - } - } - } } public boolean isReuseAddress() Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java?rev=394852&r1=394851&r2=394852&view=diff ============================================================================== --- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java (original) +++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/SocketSessionImpl.java Mon Apr 17 23:00:01 2006 @@ -46,7 +46,7 @@ class SocketSessionImpl extends BaseIoSession { private final IoService manager; - private final SocketSessionConfig config = new SocketSessionConfigImpl(); + private final SocketSessionConfig config = new SessionConfigImpl(); private final SocketIoProcessor ioProcessor; private final SocketFilterChain filterChain; private final SocketChannel ch; @@ -205,7 +205,7 @@ return readBufferSize; } - private class SocketSessionConfigImpl extends BaseIoSessionConfig implements SocketSessionConfig + private class SessionConfigImpl extends BaseIoSessionConfig implements SocketSessionConfig { public boolean isKeepAlive() { @@ -336,26 +336,36 @@ public int getTrafficClass() { - try - { - return ch.socket().getTrafficClass(); - } - catch( SocketException e ) - { - throw new RuntimeIOException( e ); - } + if( SocketSessionConfigImpl.isGetTrafficClassAvailable() ) + { + try + { + return ch.socket().getTrafficClass(); + } + catch( SocketException e ) + { + throw new RuntimeIOException( e ); + } + } + else + { + return 0; + } } public void setTrafficClass( int tc ) { - try - { - ch.socket().setTrafficClass( tc ); - } - catch( SocketException e ) - { - throw new RuntimeIOException( e ); - } + if( SocketSessionConfigImpl.isSetTrafficClassAvailable() ) + { + try + { + ch.socket().setTrafficClass( tc ); + } + catch( SocketException e ) + { + throw new RuntimeIOException( e ); + } + } } public int getSendBufferSize() @@ -372,14 +382,17 @@ public void setSendBufferSize( int size ) { - try - { - ch.socket().setSendBufferSize( size ); - } - catch( SocketException e ) - { - throw new RuntimeIOException( e ); - } + if( SocketSessionConfigImpl.isSetSendBufferSizeAvailable() ) + { + try + { + ch.socket().setSendBufferSize( size ); + } + catch( SocketException e ) + { + throw new RuntimeIOException( e ); + } + } } public int getReceiveBufferSize() @@ -396,15 +409,18 @@ public void setReceiveBufferSize( int size ) { - try - { - ch.socket().setReceiveBufferSize( size ); - SocketSessionImpl.this.readBufferSize = size; - } - catch( SocketException e ) - { - throw new RuntimeIOException( e ); - } + if( SocketSessionConfigImpl.isSetReceiveBufferSizeAvailable() ) + { + try + { + ch.socket().setReceiveBufferSize( size ); + SocketSessionImpl.this.readBufferSize = size; + } + catch( SocketException e ) + { + throw new RuntimeIOException( e ); + } + } } } }