This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Some 1.2 methods for DatagramSocket from Classpath
- From: Mark Wielaard <mark at klomp dot org>
- To: java-patches at gcc dot gnu dot org
- Date: 12 Jan 2002 21:24:07 +0100
- Subject: Some 1.2 methods for DatagramSocket from Classpath
Hi,
Since natPlainDatagramSocket.cc already had support for
SO_RCVBUF/SO_SNDBUF I added the corresponding 1.2 methods from Classpath
to DatagramSocket. The rest of the class has not yet been merged.
2002-01-12 Mark Wielaard <mark@klomp.org>
* java/net/DatagramSocket.java (getReceiveBufferSize): new 1.2 method.
* java/net/DatagramSocket.java (getSendBufferSize): Likewise.
* java/net/DatagramSocket.java (setReceiveBufferSize): Likewise.
* java/net/DatagramSocket.java (setSendBufferSize): Likewise.
OK to commit?
Cheers,
Mark
P.S. Funny thing that I noticed is that on Linux kernels the value
setsockopt is always multiplied with two. I looked in the source and it
just does a val*2 on a set, but dow not divide by 2 on a getsockopt.
Strange.
? .wget-log
? DatagramSocket.diff
? character-sets
? java-net.diff
Index: java/net/DatagramSocket.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/DatagramSocket.java,v
retrieving revision 1.9
diff -u -r1.9 DatagramSocket.java
--- DatagramSocket.java 2002/01/12 10:11:13 1.9
+++ DatagramSocket.java 2002/01/12 20:14:59
@@ -180,23 +180,83 @@
// {
// }
- // JDK1.2
- // public int getReceiveBufferSize() throws SocketException
- // {
- // }
+ /**
+ * This method returns the value of the system level socket option
+ * SO_RCVBUF, which is used by the operating system to tune buffer
+ * sizes for data transfers.
+ *
+ * @return The receive buffer size.
+ *
+ * @exception SocketException If an error occurs.
+ *
+ * @since 1.2
+ */
+ public int getReceiveBufferSize() throws SocketException
+ {
+ Object obj = impl.getOption(SocketOptions.SO_RCVBUF);
+
+ if (obj instanceof Integer)
+ return(((Integer)obj).intValue());
+ else
+ throw new SocketException("Unexpected type");
+ }
- // JDK1.2
- // public int getSendBufferSize() throws SocketException
- // {
- // }
+ /**
+ * This method returns the value of the system level socket option
+ * SO_SNDBUF, which is used by the operating system to tune buffer
+ * sizes for data transfers.
+ *
+ * @return The send buffer size.
+ *
+ * @exception SocketException If an error occurs.
+ *
+ * @since 1.2
+ */
+ public int getSendBufferSize() throws SocketException
+ {
+ Object obj = impl.getOption(SocketOptions.SO_SNDBUF);
- // JDK1.2
- // public void setReceiveBufferSize(int size) throws SocketException
- // {
- // }
+ if (obj instanceof Integer)
+ return(((Integer)obj).intValue());
+ else
+ throw new SocketException("Unexpected type");
+ }
- // JDK1.2
- // public void setSendBufferSize(int size) throws SocketException
- // {
- // }
+ /**
+ * This method sets the value for the system level socket option
+ * SO_RCVBUF to the specified value. Note that valid values for this
+ * option are specific to a given operating system.
+ *
+ * @param size The new receive buffer size.
+ *
+ * @exception SocketException If an error occurs.
+ *
+ * @since 1.2
+ */
+ public void setReceiveBufferSize(int size) throws SocketException
+ {
+ if (size < 0)
+ throw new IllegalArgumentException("Buffer size is less than 0");
+
+ impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
+ }
+
+ /**
+ * This method sets the value for the system level socket option
+ * SO_SNDBUF to the specified value. Note that valid values for this
+ * option are specific to a given operating system.
+ *
+ * @param size The new send buffer size.
+ *
+ * @exception SocketException If an error occurs.
+ *
+ * @since 1.2
+ */
+ public void setSendBufferSize(int size) throws SocketException
+ {
+ if (size < 0)
+ throw new IllegalArgumentException("Buffer size is less than 0");
+
+ impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size));
+ }
}