diff options
author | Aaron M. Renn <arenn@urbanophile.com> | 1998-12-06 19:19:24 +0000 |
---|---|---|
committer | Aaron M. Renn <arenn@urbanophile.com> | 1998-12-06 19:19:24 +0000 |
commit | 8e6bb4a0c16f1df9f962749e8ced9b6fcf05bf1e (patch) | |
tree | 8c4c6685186651ab795e3cc0c0a8b0dcf096f8bc /java/net/Socket.java | |
parent | fa90f58cf4bb2136332a053ebda7bfebcf54a853 (diff) | |
download | classpath-8e6bb4a0c16f1df9f962749e8ced9b6fcf05bf1e.tar.gz |
Added missing constructor. Added missing methods to get/set send and
receive buffer size.
Diffstat (limited to 'java/net/Socket.java')
-rw-r--r-- | java/net/Socket.java | 105 |
1 files changed, 103 insertions, 2 deletions
diff --git a/java/net/Socket.java b/java/net/Socket.java index 3462cb102..102e97095 100644 --- a/java/net/Socket.java +++ b/java/net/Socket.java @@ -54,7 +54,7 @@ public class Socket * This is the user SocketImplFactory for this class. If this variable is * null, a default factory is used. */ -protected static SocketImplFactory factory; +private static SocketImplFactory factory; /*************************************************************************/ @@ -65,7 +65,7 @@ protected static SocketImplFactory factory; /** * The implementation object to which calls are redirected */ -protected SocketImpl impl; +private SocketImpl impl; /** * The local address to which we are connected @@ -258,6 +258,29 @@ Socket(String hostname, int port, boolean stream) throws IOException /*************************************************************************/ /** + * This method connects to the named host on the specified port and + * binds to the specified local address and port. + * + * @param host The name of the remote host to connect to. + * @param port The remote port to connect to. + * @param loadAddr The local address to bind to. + * @param localPort The local port to bind to. + * + * @exception SecurityException If the <code>SecurityManager</code> + * exists and does not allow a connection to the specified host/port or + * binding to the specified local host/port. + * @exception IOException If a connection error occurs. + */ +public +Socket(String host, int port, InetAddress localAddr, int localPort) + throws IOException +{ + this(InetAddress.getByName(host), port, localAddr, localPort, true); +} + +/*************************************************************************/ + +/** * This constructor is where the real work takes place. Connect to the * specified address and port. Use default local values if not specified, * otherwise use the local host and port passed in. Create as stream or @@ -532,6 +555,84 @@ setSoTimeout(int timeout) throws SocketException /*************************************************************************/ /** + * This method returns the value of the system level socket option + * SO_SNDBUF, which is used by the operating system to tune buffer + * sizes for data transfers. + * + * @return The send buffer size. + * + * @exception SocketException If an error occurs. + */ +public synchronized int +getSendBufferSize() throws SocketException +{ + Object obj = impl.getOption(SocketOptions.SO_SNDBUF); + + if (obj instanceof Integer) + return(((Integer)obj).intValue()); + else + throw new SocketException("Unexpected type"); +} + +/*************************************************************************/ + +/** + * This method sets the value for the system level socket option + * SO_SNDBUF to the specified value. Note that valid values for this + * option are specific to a given operating system. + * + * @param size The new send buffer size. + * + * @exception SocketException If an error occurs. + */ +public synchronized void +setSendBufferSize(int size) throws SocketException +{ + impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size)); +} + +/*************************************************************************/ + +/** + * This method returns the value of the system level socket option + * SO_RCVBUF, which is used by the operating system to tune buffer + * sizes for data transfers. + * + * @return The receive buffer size. + * + * @exception SocketException If an error occurs. + */ +public synchronized int +getReceiveBufferSize() throws SocketException +{ + Object obj = impl.getOption(SocketOptions.SO_RCVBUF); + + if (obj instanceof Integer) + return(((Integer)obj).intValue()); + else + throw new SocketException("Unexpected type"); +} + +/*************************************************************************/ + +/** + * This method sets the value for the system level socket option + * SO_RCVBUF to the specified value. Note that valid values for this + * option are specific to a given operating system. + * + * @param size The new receive buffer size. + * + * @exception SocketException If an error occurs. + */ +public synchronized void +setReceiveBufferSize(int size) throws SocketException +{ + impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size)); +} + +/*************************************************************************/ + +/** * Tests whether or not the TCP_NODELAY option is set on the socket. * Returns true if enabled, false if disabled. *** Need good explanation * of this parameter. |