aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/net/Socket.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2002-09-11 10:16:00 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2002-09-11 10:16:00 +0000
commitb7caf8dd94741dd0f6cd277dcb669ee1809286b1 (patch)
tree29b4d322e1afd2e63388601bec364509ef956429 /libjava/java/net/Socket.java
parent35bb45c65bbad615d43c42f69b2949b10f5d7d05 (diff)
downloadgcc-b7caf8dd94741dd0f6cd277dcb669ee1809286b1.zip
gcc-b7caf8dd94741dd0f6cd277dcb669ee1809286b1.tar.gz
gcc-b7caf8dd94741dd0f6cd277dcb669ee1809286b1.tar.bz2
2002-09-11 Michael Koch <konqueror@gmx.de>
* java/net/Socket.java (Socket): protected to public (since JDK 1.4). Added @specnote. (bind): New method. (connect): Two new methods. (getKeepalive): Get correct socket option. (setKeepalive): Set correct socket option. (getOOBInline): New method. (setOOBInline): New method. * java/net/ServerSocket.java (bind): Two new methods. (getInetAddress): Reimplemented, catch exception. (getLocalSocketAddress): New method. (setReuseAddress): New method. (getReuseAdress): New method. (setReceiveBufferSize): New method. (getReceiveBufferSize): New method. (toString): Made string JDK 1.4 compliant. From-SVN: r57032
Diffstat (limited to 'libjava/java/net/Socket.java')
-rw-r--r--libjava/java/net/Socket.java95
1 files changed, 92 insertions, 3 deletions
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java
index 217e695..078bfff 100644
--- a/libjava/java/net/Socket.java
+++ b/libjava/java/net/Socket.java
@@ -84,8 +84,10 @@ public class Socket
* Initializes a new instance of <code>Socket</code> object without
* connecting to a remote host. This useful for subclasses of socket that
* might want this behavior.
+ *
+ * @specnote This constructor is public since JDK 1.4
*/
- protected Socket ()
+ public Socket ()
{
if (factory != null)
impl = factory.createSocketImpl();
@@ -266,6 +268,56 @@ public class Socket
}
/**
+ * Binds the socket to the givent local address/port
+ *
+ * @param bindpoint The address/port to bind to
+ *
+ * @exception If an error occurs
+ *
+ * @since 1.4
+ */
+ public void bind (SocketAddress bindpoint) throws IOException
+ {
+ if ( !(bindpoint instanceof InetSocketAddress))
+ throw new IllegalArgumentException ();
+
+ InetSocketAddress tmp = (InetSocketAddress) bindpoint;
+ impl.bind (tmp.getAddress(), tmp.getPort());
+ }
+
+ /**
+ * Connects the socket with a remote address.
+ *
+ * @param endpoint The address to connect to
+ *
+ * @exception IOException If an error occurs
+ *
+ * @since 1.4
+ */
+ public void connect (SocketAddress endpoint)
+ throws IOException
+ {
+ impl.connect (endpoint, 0);
+ }
+
+ /**
+ * Connects the socket with a remote address. A timeout of zero is
+ * interpreted as an infinite timeout. The connection will then block
+ * until established or an error occurs.
+ *
+ * @param endpoint The address to connect to
+ *
+ * @exception IOException If an error occurs
+ *
+ * @since 1.4
+ */
+ public void connect (SocketAddress endpoint, int timeout)
+ throws IOException
+ {
+ impl.connect (endpoint, timeout);
+ }
+
+ /**
* Returns the address of the remote end of the socket. If this socket
* is not connected, then <code>null</code> is returned.
*
@@ -473,6 +525,43 @@ public class Socket
}
/**
+ * Enables/disables the SO_OOBINLINE option
+ *
+ * @param on True if SO_OOBLINE should be enabled
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @since 1.4
+ */
+ public void setOOBInline (boolean on) throws SocketException
+ {
+ if (impl == null)
+ throw new SocketException("Not connected");
+
+ impl.setOption(SocketOptions.SO_OOBINLINE, new Boolean(on));
+ }
+
+ /**
+ * Returns the current setting of the SO_OOBINLINE option for this socket
+ *
+ * @exception SocketException If an error occurs
+ *
+ * @since 1.4
+ */
+ public boolean getOOBInline () throws SocketException
+ {
+ if (impl == null)
+ throw new SocketException("Not connected");
+
+ Object buf = impl.getOption(SocketOptions.SO_OOBINLINE);
+
+ if (buf instanceof Boolean)
+ return(((Boolean)buf).booleanValue());
+ else
+ throw new SocketException("Internal Error: Unexpected type");
+ }
+
+ /**
* Sets the value of the SO_TIMEOUT option on the socket. If this value
* is set, and an read/write is performed that does not complete within
* the timeout period, a short count is returned (or an EWOULDBLOCK signal
@@ -632,7 +721,7 @@ public class Socket
if (impl == null)
throw new SocketException("Not connected");
- impl.setOption(SocketOptions.SO_RCVBUF, new Boolean(on));
+ impl.setOption(SocketOptions.SO_KEEPALIVE, new Boolean(on));
}
/**
@@ -650,7 +739,7 @@ public class Socket
if (impl == null)
throw new SocketException("Not connected");
- Object buf = impl.getOption(SocketOptions.SO_RCVBUF);
+ Object buf = impl.getOption(SocketOptions.SO_KEEPALIVE);
if (buf instanceof Boolean)
return(((Boolean)buf).booleanValue());