This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: java.net: TCP sockets


Hello,


The patch I commited was the following....


Michael
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.
Index: natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.45
retrieving revision 1.46
diff -b -p -u -r1.45 -r1.46
--- natPlainSocketImpl.cc	4 Sep 2002 17:35:22 -0000	1.45
+++ natPlainSocketImpl.cc	10 Sep 2002 18:02:02 -0000	1.46
@@ -118,7 +118,9 @@ _Jv_accept (int fd, struct sockaddr *add
 #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::
 }
 
 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(jbyteA
     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::
 }
 
 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 (jav
   else
     throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
 
+  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(jbyteA
     }
 }
 
+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
@@ -877,13 +923,13 @@ java::net::PlainSocketImpl::getOption (j
         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_ :
Index: PlainSocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/PlainSocketImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -b -p -u -r1.12 -r1.13
--- PlainSocketImpl.java	4 Sep 2002 17:35:22 -0000	1.12
+++ PlainSocketImpl.java	10 Sep 2002 18:02:02 -0000	1.13
@@ -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.
 
Index: SocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/SocketImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -b -p -u -r1.9 -r1.10
--- SocketImpl.java	30 Aug 2002 18:16:00 -0000	1.9
+++ SocketImpl.java	10 Sep 2002 18:02:02 -0000	1.10
@@ -120,6 +120,21 @@ public abstract class SocketImpl impleme
     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>
@@ -214,6 +229,31 @@ public abstract class SocketImpl impleme
    */
   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
    *

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]