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]

java.net: TCP sockets


Hello list,


Another patch, same procedure.
Please review and comment.

The sendUrgentData is in natPlainSocketImpl.cc and not only 
PlainSocketImpl.java because it will later be implemented (probably).

If there are portability issues I would like to fix them after commit as they 
are reported. I cant test other systems a Linux 2.4/Glibc 2.2.5 here. 
Especially Windows users may have problems, I dont know.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1430
diff -u -b -r1.1430 ChangeLog
--- ChangeLog	4 Sep 2002 17:35:22 -0000	1.1430
+++ ChangeLog	5 Sep 2002 18:37:20 -0000
@@ -1,3 +1,16 @@
+2002-09-05  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-04  Michael Koch  <konqueror@gmx.de>
 
 	* java/net/DatagramSocket.java
Index: java/net/SocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/SocketImpl.java,v
retrieving revision 1.9
diff -u -b -r1.9 SocketImpl.java
--- java/net/SocketImpl.java	30 Aug 2002 18:16:00 -0000	1.9
+++ java/net/SocketImpl.java	5 Sep 2002 18:37:20 -0000
@@ -120,6 +120,21 @@
     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 @@
    */
   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: java/net/PlainSocketImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/PlainSocketImpl.java,v
retrieving revision 1.12
diff -u -b -r1.12 PlainSocketImpl.java
--- java/net/PlainSocketImpl.java	4 Sep 2002 17:35:22 -0000	1.12
+++ java/net/PlainSocketImpl.java	5 Sep 2002 18:37:20 -0000
@@ -67,11 +67,15 @@
 
   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)
-    throws IOException;
+  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 +92,8 @@
 
   protected native void close () throws IOException;
 
+  protected native void sendUrgentData(int data)
+    throws IOException;
 
   // Stream handling.
 
Index: java/net/natPlainSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/natPlainSocketImpl.cc,v
retrieving revision 1.45
diff -u -b -r1.45 natPlainSocketImpl.cc
--- java/net/natPlainSocketImpl.cc	4 Sep 2002 17:35:22 -0000	1.45
+++ java/net/natPlainSocketImpl.cc	5 Sep 2002 18:37:20 -0000
@@ -53,6 +53,7 @@
 #include <sys/filio.h>
 #endif
 
+#include <sys/poll.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
@@ -118,6 +119,7 @@
 #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/lang/InternalError.h>
 #include <java/lang/Object.h>
@@ -146,7 +148,7 @@
 }
 
 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 @@
     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,12 @@
 }
 
 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 +356,26 @@
   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;
+
+      struct pollfd pfd;
+      pfd.fd = fnum;
+      pfd.events = POLLOUT;
+      pfd.revents = POLLOUT;
+      ::poll (&pfd, 1, timeout);
+    }
+  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 +549,12 @@
     }
 }
 
+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 +914,13 @@
         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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]