[kaffe] CVS kaffe (guilhem): Fix for ServerSocket + Fixed some warnings.

Kaffe CVS cvs-commits at kaffe.org
Wed Sep 15 02:29:38 PDT 2004


PatchSet 5170 
Date: 2004/09/15 09:25:48
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Fix for ServerSocket + Fixed some warnings.

        * libraries/javalib/java/net/ServerSocket.java
        (implAccept): Set bound to true.

        * libraries/javalib/java/net/Socket.java
        (bound): Make bound package-private.

        Patch from: Ito Kazumitsu  <kaz at maczuka.gcd.org>

        * libraries/clib/net/PlainSocketImpl.c
        (socketAccept): Init localport.
        (socketBind): Fixed localport reporting when using IPV6.
        (socketSetOption): Fixed some warnings.
        (socketGetOption): Fixed some warnings.
        Use *_ADDRESS_SIZE instead of raw values.

Members: 
	ChangeLog:1.2725->1.2726 
	libraries/clib/net/PlainSocketImpl.c:1.45->1.46 
	libraries/javalib/java/net/ServerSocket.java:1.27->1.28 
	libraries/javalib/java/net/Socket.java:1.36->1.37 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2725 kaffe/ChangeLog:1.2726
--- kaffe/ChangeLog:1.2725	Tue Sep 14 22:09:30 2004
+++ kaffe/ChangeLog	Wed Sep 15 09:25:48 2004
@@ -1,3 +1,20 @@
+2004-09-15  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* libraries/javalib/java/net/ServerSocket.java
+	(implAccept): Set bound to true.
+
+	* libraries/javalib/java/net/Socket.java
+	(bound): Make bound package-private.
+
+	Patch from: Ito Kazumitsu  <kaz at maczuka.gcd.org>
+	
+	* libraries/clib/net/PlainSocketImpl.c
+	(socketAccept): Init localport.
+	(socketBind): Fixed localport reporting when using IPV6.
+	(socketSetOption): Fixed some warnings.
+	(socketGetOption): Fixed some warnings.
+	Use *_ADDRESS_SIZE instead of raw values.
+	
 2004-09-14  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/javalib/javax/naming/CompoundName.java:
Index: kaffe/libraries/clib/net/PlainSocketImpl.c
diff -u kaffe/libraries/clib/net/PlainSocketImpl.c:1.45 kaffe/libraries/clib/net/PlainSocketImpl.c:1.46
--- kaffe/libraries/clib/net/PlainSocketImpl.c:1.45	Fri May 28 13:40:13 2004
+++ kaffe/libraries/clib/net/PlainSocketImpl.c	Wed Sep 15 09:25:51 2004
@@ -30,6 +30,9 @@
 
 #include "dummyin6.h"
 
+#define IPV4_ADDRESS_SIZE 4
+#define IPV6_ADDRESS_SIZE 16
+
 #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
 #include "getaddrinfo.h"
 #endif /* !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO) */
@@ -188,7 +191,7 @@
 	int alen;
 
 	memset(&addr, 0, sizeof(addr));
-	if (obj_length(unhand(daddr)->addr) == 4) {
+	if (obj_length(unhand(daddr)->addr) == IPV4_ADDRESS_SIZE) {
 	        alen = sizeof(addr.addr4); 
 
 #if defined(BSD44)
@@ -201,7 +204,7 @@
 		       unhand_byte_array(unhand(daddr)->addr), sizeof(addr.addr4.sin_addr));
 
 #if defined(HAVE_STRUCT_SOCKADDR_IN6)
-	} else if (obj_length(unhand(daddr)->addr) == 16) {
+	} else if (obj_length(unhand(daddr)->addr) == IPV6_ADDRESS_SIZE) {
 	        alen = sizeof(addr.addr6);
 
 #if defined(BSD44)
@@ -280,7 +283,7 @@
 	    )
 
 	memset(&addr, 0, sizeof(addr));
-	if (obj_length(unhand(laddr)->addr) == 4) {
+	if (obj_length(unhand(laddr)->addr) == IPV4_ADDRESS_SIZE) {
 	        alen = sizeof(addr.addr4);
 
 #if defined(BSD44)
@@ -298,7 +301,7 @@
 		    );
 
 #if defined(HAVE_STRUCT_SOCKADDR_IN6)
-	} else if (obj_length(unhand(laddr)->addr) == 16) {
+	} else if (obj_length(unhand(laddr)->addr) == IPV6_ADDRESS_SIZE) {
 	        alen = sizeof(addr.addr6);
 
 #if defined(BSD44)
@@ -346,7 +349,14 @@
 		if (r) {
 			SignalError("java.io.IOException", SYS_ERROR(r));
 		}
-		lport = ntohs(addr.addr4.sin_port);
+#if defined(HAVE_STRUCT_SOCKADDR_IN6)
+		if (obj_length(unhand(laddr)->addr) == IPV6_ADDRESS_SIZE) {
+		  lport = ntohs(addr.addr6.sin6_port);
+		} else
+#endif
+		{
+		  lport = ntohs(addr.addr4.sin_port);
+		}
 	}
 	unhand(this)->localport = lport;
 }
@@ -380,7 +390,9 @@
 	int alen;
 	struct sockaddr_in addr;
 	HArrayOfByte *remote_addr;
-	
+	struct Hgnu_java_net_PlainSocketImpl* accepted_socket =
+	  (struct Hgnu_java_net_PlainSocketImpl *)sock;
+
 	remote_addr = NULL;
 	memset(&addr, 0, sizeof(addr));
 
@@ -413,14 +425,14 @@
 	if (rc) {
 		SignalError("java.io.IOException", SYS_ERROR(rc));
 	}
-	if (unhand((struct Hgnu_java_net_PlainSocketImpl *)sock)->native_fd != -1) {
+	if (unhand(accepted_socket)->native_fd != -1) {
 		rc1 = KSOCKCLOSE(unhand((struct Hgnu_java_net_PlainSocketImpl *)sock)->native_fd);
 		if (rc1) {
 			SignalError("java.io.IOException", SYS_ERROR(rc1));
 		}
 	}
 
-	unhand((struct Hgnu_java_net_PlainSocketImpl *)sock)->native_fd = r;
+	unhand(accepted_socket)->native_fd = r;
 
 	/* Enter information into socket object */
 	alen = sizeof(addr);
@@ -462,6 +474,13 @@
 							      remote_addr).l;
 	unhand(sock)->port = ntohs(addr.sin_port);
 
+	alen = sizeof(addr);
+	r = KGETSOCKNAME(unhand(accepted_socket)->native_fd, (struct sockaddr*)&addr, &alen);
+	if (r) {
+	  SignalError("java.io.IOException", SYS_ERROR(r));
+	}
+	unhand(accepted_socket)->localport = ntohs(addr.sin_port);
+	
 	DBG(NATIVENET,
 	    dprintf("socketAccept(%p, localport=-, addr=-) -> (sock: %p; addr: %s; port:%d)\n", 
 		    this, sock, ip2str(addr.sin_addr.s_addr), ntohs(addr.sin_port));
@@ -547,7 +566,8 @@
 					     jint opt, 
 					     struct Hjava_lang_Object* arg)
 {
-	int k, r, v;
+	int r, v;
+	unsigned int k;
 
 	DBG(NATIVENET,
 	    char *optstr = "UNKNOWN";
@@ -605,8 +625,9 @@
 {
 	struct sockaddr_in addr;
 	int alen = sizeof(addr);
-	int k, r, v;
+	int r, v;
 	int vsize = sizeof(v);
+	unsigned int k;
 
 	DBG(NATIVENET,
 	    char *optstr = "UNKNOWN";
Index: kaffe/libraries/javalib/java/net/ServerSocket.java
diff -u kaffe/libraries/javalib/java/net/ServerSocket.java:1.27 kaffe/libraries/javalib/java/net/ServerSocket.java:1.28
--- kaffe/libraries/javalib/java/net/ServerSocket.java:1.27	Mon May 17 22:25:06 2004
+++ kaffe/libraries/javalib/java/net/ServerSocket.java	Wed Sep 15 09:25:51 2004
@@ -376,6 +376,7 @@
 
     impl.accept(socket.impl);
     socket.implCreated = true;
+    socket.bound = true;
   }
 
   /**
Index: kaffe/libraries/javalib/java/net/Socket.java
diff -u kaffe/libraries/javalib/java/net/Socket.java:1.36 kaffe/libraries/javalib/java/net/Socket.java:1.37
--- kaffe/libraries/javalib/java/net/Socket.java:1.36	Tue Sep 14 14:15:51 2004
+++ kaffe/libraries/javalib/java/net/Socket.java	Wed Sep 15 09:25:51 2004
@@ -91,7 +91,8 @@
   /**
    * True if the socket is bound.
    */
-  private boolean bound;
+  // package-private because ServerSocket.implAccept() needs to access it.
+  boolean bound;
 
   /**
    * True if input is shutdown.




More information about the kaffe mailing list