You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/04/05 11:36:44 UTC
svn commit: r525781 - in /mina:
branches/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/
branches/1.1/core/src/main/java/org/apache/mina/transport/socket/nio/
trunk/core/src/main/java/org/apache/mina/transport/socket/nio/
Author: trustin
Date: Thu Apr 5 02:36:43 2007
New Revision: 525781
URL: http://svn.apache.org/viewvc?view=rev&rev=525781
Log:
Fixed issue: DIRMINA-366 Default socket option values are retrieved incorrectly.
* sendBufferSize is calculated correctly now.
Modified:
mina/branches/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java
mina/branches/1.1/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java
mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/DefaultSocketSessionConfig.java
Modified: mina/branches/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java
URL: http://svn.apache.org/viewvc/mina/branches/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java?view=diff&rev=525781&r1=525780&r2=525781
==============================================================================
--- mina/branches/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java (original)
+++ mina/branches/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java Thu Apr 5 02:36:43 2007
@@ -24,6 +24,8 @@
import org.apache.mina.common.support.BaseIoSessionConfig;
import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
@@ -56,12 +58,24 @@
private static void initialize()
{
+ ServerSocket ss = null;
Socket socket = null;
- socket = new Socket();
+ try {
+ ss = new ServerSocket();
+ ss.bind(new InetSocketAddress("localhost", 0));
+ socket = new Socket();
+ try {
+ // Timeout is set to 10 seconds in case of infinite blocking
+ // on some platform.
+ socket.connect(
+ new InetSocketAddress("localhost", ss.getLocalPort()), 10000);
+ } catch (IOException e) {
+ // We can retrieve the values even if the connection
+ // attempt fails, although it might be somewhat incorrect
+ // on some platform.
+ }
- try
- {
DEFAULT_REUSE_ADDRESS = socket.getReuseAddress();
DEFAULT_RECEIVE_BUFFER_SIZE = socket.getReceiveBufferSize();
DEFAULT_SEND_BUFFER_SIZE = socket.getSendBufferSize();
@@ -104,7 +118,7 @@
DEFAULT_TRAFFIC_CLASS = 0;
}
}
- catch( SocketException e )
+ catch( Exception e )
{
throw new ExceptionInInitializerError(e);
}
@@ -118,6 +132,14 @@
}
catch( IOException e )
{
+ ExceptionMonitor.getInstance().exceptionCaught(e);
+ }
+ }
+
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
ExceptionMonitor.getInstance().exceptionCaught(e);
}
}
Modified: mina/branches/1.1/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java
URL: http://svn.apache.org/viewvc/mina/branches/1.1/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java?view=diff&rev=525781&r1=525780&r2=525781
==============================================================================
--- mina/branches/1.1/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java (original)
+++ mina/branches/1.1/core/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionConfigImpl.java Thu Apr 5 02:36:43 2007
@@ -24,6 +24,8 @@
import org.apache.mina.common.support.BaseIoSessionConfig;
import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
@@ -56,12 +58,24 @@
private static void initialize()
{
+ ServerSocket ss = null;
Socket socket = null;
- socket = new Socket();
+ try {
+ ss = new ServerSocket();
+ ss.bind(new InetSocketAddress("localhost", 0));
+ socket = new Socket();
+ try {
+ // Timeout is set to 10 seconds in case of infinite blocking
+ // on some platform.
+ socket.connect(
+ new InetSocketAddress("localhost", ss.getLocalPort()), 10000);
+ } catch (IOException e) {
+ // We can retrieve the values even if the connection
+ // attempt fails, although it might be somewhat incorrect
+ // on some platform.
+ }
- try
- {
DEFAULT_REUSE_ADDRESS = socket.getReuseAddress();
DEFAULT_RECEIVE_BUFFER_SIZE = socket.getReceiveBufferSize();
DEFAULT_SEND_BUFFER_SIZE = socket.getSendBufferSize();
@@ -104,7 +118,7 @@
DEFAULT_TRAFFIC_CLASS = 0;
}
}
- catch( SocketException e )
+ catch( Exception e )
{
throw new ExceptionInInitializerError(e);
}
@@ -118,6 +132,14 @@
}
catch( IOException e )
{
+ ExceptionMonitor.getInstance().exceptionCaught(e);
+ }
+ }
+
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
ExceptionMonitor.getInstance().exceptionCaught(e);
}
}
Modified: mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/DefaultSocketSessionConfig.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/DefaultSocketSessionConfig.java?view=diff&rev=525781&r1=525780&r2=525781
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/DefaultSocketSessionConfig.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/transport/socket/nio/DefaultSocketSessionConfig.java Thu Apr 5 02:36:43 2007
@@ -20,6 +20,8 @@
package org.apache.mina.transport.socket.nio;
import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
@@ -51,16 +53,30 @@
static
{
initialize();
+ System.out.println(DEFAULT_REUSE_ADDRESS);
+ System.out.println(DEFAULT_SEND_BUFFER_SIZE);
}
private static void initialize()
{
+ ServerSocket ss = null;
Socket socket = null;
- socket = new Socket();
+ try {
+ ss = new ServerSocket();
+ ss.bind(new InetSocketAddress("localhost", 0));
+ socket = new Socket();
+ try {
+ // Timeout is set to 10 seconds in case of infinite blocking
+ // on some platform.
+ socket.connect(
+ new InetSocketAddress("localhost", ss.getLocalPort()), 10000);
+ } catch (IOException e) {
+ // We can retrieve the values even if the connection
+ // attempt fails, although it might be somewhat incorrect
+ // on some platform.
+ }
- try
- {
DEFAULT_REUSE_ADDRESS = socket.getReuseAddress();
DEFAULT_RECEIVE_BUFFER_SIZE = socket.getReceiveBufferSize();
DEFAULT_SEND_BUFFER_SIZE = socket.getSendBufferSize();
@@ -103,7 +119,7 @@
DEFAULT_TRAFFIC_CLASS = 0;
}
}
- catch( SocketException e )
+ catch( Exception e )
{
throw new ExceptionInInitializerError(e);
}
@@ -117,6 +133,14 @@
}
catch( IOException e )
{
+ ExceptionMonitor.getInstance().exceptionCaught(e);
+ }
+ }
+
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
ExceptionMonitor.getInstance().exceptionCaught(e);
}
}