aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2002-09-10 18:02:02 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2002-09-10 18:02:02 +0000
commita886956a40a502e3b7ae25e6b79195985c30a1bf (patch)
treeefa74de037bafc64f9022b0f9ef627af5465a3cb /libjava
parentbfae804050ac712d29b556ea0cd1f6e06199ae12 (diff)
downloadgcc-a886956a40a502e3b7ae25e6b79195985c30a1bf.zip
gcc-a886956a40a502e3b7ae25e6b79195985c30a1bf.tar.gz
gcc-a886956a40a502e3b7ae25e6b79195985c30a1bf.tar.bz2
2002-09-10 Michael Koch <konqueror@gmx.de>
* java/net/SocketImpl.java (connect): New method. (supportsUrgentData): New method. (sendUrgentData): New method. * java/net/PlainSocketImpl.java (connect): One new method and two new implementation. (sendUrgentData): New method. * java/natPlainSocketImpl.cc (connect): Arguments changed, added support for timeouts. (getOption): Another __java_boolean to jboolean. From-SVN: r57009
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog13
-rw-r--r--libjava/java/net/PlainSocketImpl.java11
-rw-r--r--libjava/java/net/SocketImpl.java40
-rw-r--r--libjava/java/net/natPlainSocketImpl.cc66
4 files changed, 118 insertions, 12 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 80409c3..9ba9325 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,16 @@
+2002-09-10 Michael Koch <konqueror@gmx.de>
+
+ * java/net/SocketImpl.java
+ (connect): New method.
+ (supportsUrgentData): New method.
+ (sendUrgentData): New method.
+ * java/net/PlainSocketImpl.java
+ (connect): One new method and two new implementation.
+ (sendUrgentData): New method.
+ * java/natPlainSocketImpl.cc
+ (connect): Arguments changed, added support for timeouts.
+ (getOption): Another __java_boolean to jboolean.
+
2002-09-07 Adam Megacz <adam@xwt.org>
* java/net/natPlainDatagramSocket.cc: include ws2tcpip.h for
diff --git a/libjava/java/net/PlainSocketImpl.java b/libjava/java/net/PlainSocketImpl.java
index dd04a14..2b65ba0 100644
--- a/libjava/java/net/PlainSocketImpl.java
+++ b/libjava/java/net/PlainSocketImpl.java
@@ -67,10 +67,15 @@ class PlainSocketImpl extends SocketImpl
protected void connect (String host, int port) throws IOException
{
- connect(InetAddress.getByName(host), port);
+ connect (new InetSocketAddress (InetAddress.getByName(host), port), 0);
}
- protected native void connect (InetAddress host, int port)
+ protected void connect (InetAddress host, int port) throws IOException
+ {
+ connect (new InetSocketAddress (host, port), 0);
+ }
+
+ protected native void connect (SocketAddress addr, int timeout)
throws IOException;
protected native void bind (InetAddress host, int port) throws IOException;
@@ -88,6 +93,8 @@ class PlainSocketImpl extends SocketImpl
protected native void close () throws IOException;
+ protected native void sendUrgentData(int data)
+ throws IOException;
// Stream handling.
diff --git a/libjava/java/net/SocketImpl.java b/libjava/java/net/SocketImpl.java
index 7dcf87d..1c90499 100644
--- a/libjava/java/net/SocketImpl.java
+++ b/libjava/java/net/SocketImpl.java
@@ -120,6 +120,21 @@ public abstract class SocketImpl implements SocketOptions
throws IOException;
/**
+ * Connects to the socket to the host specified in address. This
+ * method blocks until successful connected or the timeout occurs.
+ * A timeout of zero means no timout.
+ *
+ * @param address Data of remote host
+ * @param timeout time to wait to stop connecting
+ *
+ * @exception IOException If an error occurs
+ *
+ * @since 1.4
+ */
+ protected abstract void connect(SocketAddress address, int timeout)
+ throws IOException;
+
+ /**
* Binds to the specified port on the specified addr. Note that this addr
* must represent a local IP address.
* <p>
@@ -215,6 +230,31 @@ public abstract class SocketImpl implements SocketOptions
protected int getPort() { return port; }
/**
+ * Returns true or false when this socket supports sending urgent data
+ * or not.
+ *
+ * @since 1.4
+ */
+ protected boolean supportsUrgentData()
+ {
+ // This method has to be overwritten by socket classes that support
+ // sending urgend data.
+ return false;
+ }
+
+ /**
+ * Sends one byte of urgent data to the socket.
+ *
+ * @param data The byte to send, the low eight bits of it
+ *
+ * @exception IOException If an error occurs
+ *
+ * @since 1.4
+ */
+ protected abstract void sendUrgentData(int data)
+ throws IOException;
+
+ /**
* Returns the local port this socket is bound to
*
* @return The local port
diff --git a/libjava/java/net/natPlainSocketImpl.cc b/libjava/java/net/natPlainSocketImpl.cc
index a785b1b..37813cb 100644
--- a/libjava/java/net/natPlainSocketImpl.cc
+++ b/libjava/java/net/natPlainSocketImpl.cc
@@ -118,7 +118,9 @@ _Jv_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
#include <java/net/ConnectException.h>
#include <java/net/PlainSocketImpl.h>
#include <java/net/InetAddress.h>
+#include <java/net/InetSocketAddress.h>
#include <java/net/SocketException.h>
+#include <java/net/SocketTimeoutException.h>
#include <java/lang/InternalError.h>
#include <java/lang/Object.h>
#include <java/lang/Boolean.h>
@@ -146,7 +148,7 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *, jint)
}
void
-java::net::PlainSocketImpl::connect (java::net::InetAddress *, jint)
+java::net::PlainSocketImpl::connect (java::net::SocketAddress *, jint)
{
throw new ConnectException (
JvNewStringLatin1 ("SocketImpl.connect: unimplemented"));
@@ -208,6 +210,13 @@ java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
}
+void
+java::net::PlainSocketImpl::sendUrgentData(jint data)
+{
+ throw new SocketException (
+ JvNewStringLatin1 ("SocketImpl.sendUrgentData: unimplemented"));
+}
+
jint
java::net::PlainSocketImpl::available(void)
{
@@ -316,8 +325,13 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
}
void
-java::net::PlainSocketImpl::connect (java::net::InetAddress *host, jint rport)
+java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr,
+ jint timeout)
{
+ java::net::InetSocketAddress *tmp = (java::net::InetSocketAddress*) addr;
+ java::net::InetAddress *host = tmp->getAddress();
+ jint rport = tmp->getPort();
+
union SockAddr u;
socklen_t addrlen = sizeof(u);
jbyteArray haddress = host->addr;
@@ -343,8 +357,34 @@ java::net::PlainSocketImpl::connect (java::net::InetAddress *host, jint rport)
else
throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
- if (_Jv_connect (fnum, ptr, len) != 0)
- goto error;
+ if (timeout > 0)
+ {
+ int flags = ::fcntl (fnum, F_GETFL);
+ ::fcntl (fnum, F_SETFL, flags | O_NONBLOCK);
+
+ if ((_Jv_connect (fnum, ptr, len) != 0) && (errno != EINPROGRESS))
+ goto error;
+
+ fd_set rset;
+ struct timeval tv;
+ FD_ZERO(&rset);
+ FD_SET(fnum, &rset);
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ int retval;
+
+ if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
+ goto error;
+ else if (retval == 0)
+ throw new java::net::SocketTimeoutException (
+ JvNewStringUTF("Connect timed out"));
+ }
+ else
+ {
+ if (_Jv_connect (fnum, ptr, len) != 0)
+ goto error;
+ }
+
address = host;
port = rport;
// A bind may not have been done on this socket; if so, set localport now.
@@ -518,6 +558,12 @@ java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
}
}
+void
+java::net::PlainSocketImpl::sendUrgentData (jint)
+{
+ throw new SocketException (JvNewStringLatin1 (
+ "PlainSocketImpl: sending of urgent data not supported by this socket"));
+}
// Read a single byte from the socket.
jint
@@ -756,10 +802,10 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
case _Jv_SO_OOBINLINE_ :
if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
- val_len) != 0)
- goto error;
- break;
-
+ val_len) != 0)
+ goto error;
+ break;
+
case _Jv_SO_LINGER_ :
#ifdef SO_LINGER
struct linger l_val;
@@ -877,13 +923,13 @@ java::net::PlainSocketImpl::getOption (jint optID)
if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
&val_len) != 0)
goto error;
- return new java::lang::Boolean ((__java_boolean)val);
+ return new java::lang::Boolean ((jboolean)val);
case _Jv_SO_OOBINLINE_ :
if (::getsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
&val_len) != 0)
goto error;
- return new java::lang::Boolean ((__java_boolean)val);
+ return new java::lang::Boolean ((jboolean)val);
case _Jv_SO_RCVBUF_ :
case _Jv_SO_SNDBUF_ :