Correction for java.net

Petter Reinholdtsen pere at games.no
Sat Aug 1 10:31:33 PDT 1998


Here is a patch to correct java.net.Socket.setSoLinger, to implement
java.net.Socket.getLocalAddress and to correct the magic numbers in
java.net.SocketOptions to match JDK 1.1.5.  I don't know the correct
values for SO_SNDBUF and SO_RCVBUF, as they don't exist in JDK 1.1.5.

Index: libraries/clib/net/SocketOptions.h
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/clib/net/SocketOptions.h,v
retrieving revision 1.2
diff -u -r1.2 SocketOptions.h
--- SocketOptions.h	1998/07/31 04:05:04	1.2
+++ SocketOptions.h	1998/08/01 17:13:20
@@ -11,14 +11,14 @@
 /* Header for class java_net_SocketOptions */
 
 typedef struct Classjava_net_SocketOptions {
-#define java_net_SocketOptions_SO_SNDBUF 1
-#define java_net_SocketOptions_SO_RCVBUF 2
-#define java_net_SocketOptions_SO_LINGER 3
-#define java_net_SocketOptions_SO_TIMEOUT 4
-#define java_net_SocketOptions_SO_BINDADDR 5
-#define java_net_SocketOptions_SO_REUSEADDR 6
-#define java_net_SocketOptions_TCP_NODELAY 7
-#define java_net_SocketOptions_IP_MULTICAST_IF 8
+#define java_net_SocketOptions_TCP_NODELAY 1
+#define java_net_SocketOptions_SO_REUSEADDR 4
+#define java_net_SocketOptions_SO_BINDADDR 15
+#define java_net_SocketOptions_IP_MULTICAST_IF 16
+#define java_net_SocketOptions_SO_LINGER 128
+#define java_net_SocketOptions_SO_TIMEOUT 4102
+#define java_net_SocketOptions_SO_SNDBUF 2
+#define java_net_SocketOptions_SO_RCVBUF 3
 	int __DUMMY__;
 } Classjava_net_SocketOptions;
 HandleTo(java_net_SocketOptions);
Index: libraries/javalib/Klasses.jar
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/Klasses.jar,v
retrieving revision 1.5
diff -u -r1.5 Klasses.jar
Binary files /tmp/cvs25842baa and Klasses.jar differ
Index: libraries/javalib/java/net/Socket.java
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/java/net/Socket.java,v
retrieving revision 1.2
diff -u -r1.2 Socket.java
--- Socket.java	1998/07/31 04:05:10	1.2
+++ Socket.java	1998/08/01 17:14:28
@@ -72,12 +72,28 @@
 	return impl.getPort();
 }
 
+public InetAddress getLocalAddress() {
+	InetAddress localAddress;
+	try {
+		localAddress =
+			(InetAddress)impl.getOption(SocketOptions.SO_BINDADDR); 
+	} catch (Exception e) {
+		localAddress = InetAddress.anyLocalAddress;
+	}
+	return localAddress;
+}
+
 public static synchronized void setSocketImplFactory(SocketImplFactory fac) throws IOException {
 	factory=fac;
 }
 
-public void setSoLinger(int timeout) throws SocketException {
+public void setSoLinger(boolean on, int timeout) throws SocketException {
 	impl.setOption(SocketOptions.SO_LINGER, new Integer(timeout));
+	if (on) {
+		impl.setOption(SocketOptions.SO_LINGER, new Integer(timeout));
+		return;
+	}
+	impl.setOption(SocketOptions.SO_LINGER, new Boolean(on));
 }
 
 public int getSoLinger() throws SocketException {
Index: libraries/javalib/java/net/SocketOptions.java
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/java/net/SocketOptions.java,v
retrieving revision 1.2
diff -u -r1.2 SocketOptions.java
--- SocketOptions.java	1998/07/31 04:05:12	1.2
+++ SocketOptions.java	1998/08/01 17:14:29
@@ -11,14 +11,17 @@
 package java.net;
 
 public interface SocketOptions {
-  static final int SO_SNDBUF = 1;
-  static final int SO_RCVBUF = 2;
-  static final int SO_LINGER = 3;
-  static final int SO_TIMEOUT = 4;
-  static final int SO_BINDADDR = 5;
-  static final int SO_REUSEADDR = 6;
-  static final int TCP_NODELAY = 7;
-  static final int IP_MULTICAST_IF = 8;
+  /* These values are from JDK 1.1.5 */
+  static final int TCP_NODELAY	    = 0x0001;
+  static final int SO_REUSEADDR    = 0x0004;
+  static final int SO_BINDADDR     = 0x000f;
+  static final int IP_MULTICAST_IF = 0x0010;
+  static final int SO_LINGER       = 0x0080;
+  static final int SO_TIMEOUT      = 0x1006;
+
+  /* Are these from JDK 1.2?  I don't know the correct values for these */
+  static final int SO_SNDBUF       = 0x0002;
+  static final int SO_RCVBUF	    = 0x0003;
 
   public void setOption(int option, Object data) throws SocketException;
   public Object getOption(int option) throws SocketException;
-- 
##>  Petter Reinholdtsen  <##  |  pere at td.org.uit.no


More information about the kaffe mailing list