com.ibm.net
Class SocketUtils
- java.lang.Object
com.ibm.net.SocketUtils
- public class SocketUtils
- extends java.lang.Object
java.net.Socket
.
Developers need to guard against concurrency and consistency check between the
Java object and their own use of the native sockets, retrieved by the methods
provided by this class. For eg. if the Java Socket/ServerSocket/SocketChannel
/ServerSocketChannel is closed, previously obtained value for the native
socket and any further operations with the native socket is invalid.
Constructor Summary
Constructor and Description |
---|
SocketUtils()
|
Method Summary
Modifier and Type | Method and Description |
---|---|
|
configureKeepAlive(java.net.Socket s,SocketKeepAliveParameters p)
Control behaviour of socket keepalives for the supplied
Socket .
|
|
getFileDescriptor(java.net.ServerSocket s)
Retrieve the value of the Socket descriptor represented by the
supplied
ServerSocket .
|
|
getFileDescriptor(java.nio.channels.ServerSocketChannel channel)
Retrieve the value of the Socket descriptor represented by the
supplied
ServerSocketChannel .
|
|
getFileDescriptor(java.net.Socket s)
Retrieve the value of the Socket descriptor represented by the
supplied
Socket .
|
|
getFileDescriptor(java.nio.channels.SocketChannel channel)
Retrieve the value of the Socket descriptor represented by the
supplied
SocketChannel .
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail
SocketUtils
- public SocketUtils()
Method Detail
configureKeepAlive
- public static void configureKeepAlive( java.net.Socket s,
- SocketKeepAliveParameters p)
- throws java.net.SocketException
Parameters:
s
- The Socket
to configure. p
- The SocketKeepAliveParameters
containing the values to set. Throws:
java.net.SocketException
- If an error occurs while setting the keepalive parameters. See Also:
SocketKeepAliveParameters
,
Socket.setKeepAlive(boolean)
getFileDescriptor
- public static long[] getFileDescriptor( java.nio.channels.SocketChannel channel)
Retrieve the value of the Socket descriptor represented by the
supplied
SocketChannel
.
Parameters:
channel
- SocketChannel
. Returns:
The value of the socket represented by the supplied SocketChannel.
In case of Windows (Windows XP and Windows 2003), where IPv6 is
enabled, it returns an array of 2 socket descriptors, else a single
element array will be returned containing the value of the native
socket descriptor. It returns -1 if the socket is closed.
getFileDescriptor
- public static long[] getFileDescriptor( java.nio.channels.ServerSocketChannel channel)
Retrieve the value of the Socket descriptor represented by the
supplied
ServerSocketChannel
.
Parameters:
channel
- ServerSocketChannel
. Returns:
The value of the socket represented by the supplied ServerSocketChannel.
In case of Windows (Windows XP and Windows 2003), where IPv6 is
enabled, it returns an array of 2 socket descriptors, else a single
element array will be returned containing the value of the native
socket descriptor. It returns -1 if the socket is closed.
getFileDescriptor
- public static long[] getFileDescriptor( java.net.Socket s)
Retrieve the value of the Socket descriptor represented by the
supplied
Socket
.
Parameters:
s
- Socket
. Returns:
The value of the socket represented by the supplied Socket.
In case of Windows (Windows XP and Windows 2003), where IPv6 is
enabled, it returns an array of 2 socket descriptors, else a single
element array will be returned containing the value of the native
socket descriptor. It returns -1 if the socket is closed.
getFileDescriptor
- public static long[] getFileDescriptor( java.net.ServerSocket s)
Retrieve the value of the Socket descriptor represented by the
supplied
ServerSocket
.
Parameters:
s
- ServerSocket
. Returns:
The value of the socket represented by the supplied ServerSocket.
In case of Windows (Windows XP and Windows 2003), where IPv6 is
enabled, it returns an array of 2 socket descriptors, else a single
element array will be returned containing the value of the native
socket descriptor. It returns -1 if the socket is closed.
Socket
. To enable or disable socket keepalives useSocket.setKeepAlive(boolean)
. e.g. To enable keepalive and set the keepalive idle time for this socket to 1 hour and keepalive interval to 20 seconds: