2002-09-04 Michael Koch <konqueror@gmx.de>

* java/net/DatagramSocket.java
	(DatagramSocket): Added documentation.
	(close): Likewise.
	(getLocalAddress): Likewise.
	(getLocalPort): Likewise.
	(receive): Likewise.
	(send): Likewise.
	(setSoTimeout): Likewise.
	(connect): New method.
	(disconnect): New method.
	(getInetAddress): New method (FIXME)
	(getPort): New method.
	(setReuseAddress): New method.
	(getReuseAddress): New method.
	(setBroadcast): New method.
	(getBroadcast): New method.
	(setTrafficClass): New method.
	(getTrafficClass): New method.
	* java/net/MulticastSocket.java):
	(getTTL): Added @see in documentation.
	(setTTL): Added @see in documentation.
	(setLoopbackMode): New method.
	(getLoopbackMode): New method.
	* java/net/PlainSocketImpl.java:
	Added new constants for the options SO_BROADCAST, SO_OOBINLINE,
	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
	* java/net/PlainDatagramSocketImpl.java
	Added new constants for the options SO_BROADCAST, SO_OOBINLINE,
	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
	* java/net/natPlainSocketImpl.cc
	(getOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
	(setOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
	This should also fix SO_KEEPALIVE
	* java/net/natPlainDatagramSocketImpl.cc
	(getOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
	(setOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
	IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS

From-SVN: r56801
This commit is contained in:
Michael Koch 2002-09-04 17:35:22 +00:00 committed by Michael Koch
parent 77e8a0cc9d
commit 7b98d4549b
7 changed files with 417 additions and 22 deletions

View File

@ -1,3 +1,46 @@
2002-09-04 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java
(DatagramSocket): Added documentation.
(close): Likewise.
(getLocalAddress): Likewise.
(getLocalPort): Likewise.
(receive): Likewise.
(send): Likewise.
(setSoTimeout): Likewise.
(connect): New method.
(disconnect): New method.
(getInetAddress): New method (FIXME)
(getPort): New method.
(setReuseAddress): New method.
(getReuseAddress): New method.
(setBroadcast): New method.
(getBroadcast): New method.
(setTrafficClass): New method.
(getTrafficClass): New method.
* java/net/MulticastSocket.java):
(getTTL): Added @see in documentation.
(setTTL): Added @see in documentation.
(setLoopbackMode): New method.
(getLoopbackMode): New method.
* java/net/PlainSocketImpl.java:
Added new constants for the options SO_BROADCAST, SO_OOBINLINE,
IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
* java/net/PlainDatagramSocketImpl.java
Added new constants for the options SO_BROADCAST, SO_OOBINLINE,
IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
* java/net/natPlainSocketImpl.cc
(getOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
(setOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
This should also fix SO_KEEPALIVE
* java/net/natPlainDatagramSocketImpl.cc
(getOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
(setOption): Implemented the options SO_BROADCAST, SO_OOBINLINE,
IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS
2002-09-04 Michael Koch <konqueror@gmx.de>
* java/net/SocketOptions.java: added static variables to be JDK 1.4

View File

@ -31,11 +31,26 @@ public class DatagramSocket
this(0, null);
}
/**
* Creates a datagram socket that is bound to a specific port
*
* @param port The port number to bind to
*
* @exception SocketException If an error occurs
*/
public DatagramSocket(int port) throws SocketException
{
this(port, null);
}
/**
* Creates a datagram socket that is bound to a specific port/inet address
*
* @param port The port number to bind to
* @param laddr The local address to bind to
*
* @exception SocketException If an error occurs
*/
public DatagramSocket(int port, InetAddress laddr) throws SocketException
{
if (port < 0 || port > 65535)
@ -69,11 +84,19 @@ public class DatagramSocket
impl.bind(port, laddr == null ? InetAddress.ANY_IF : laddr);
}
/**
* Closes the datagram socket
*/
public void close()
{
impl.close();
}
/**
* Returns the local address of the datagram socket
*
* @since 1.1
*/
public InetAddress getLocalAddress()
{
SecurityManager s = System.getSecurityManager();
@ -112,12 +135,23 @@ public class DatagramSocket
}
}
/**
* Returns the local port this socket uses
*
* @return The local port number
*/
public int getLocalPort()
{
return impl.getLocalPort();
}
/**
* Gets the SO_TIMEOUT value
*
* @return The current timeout in milliseconds
*
* @exception SocketException If an error occurs
*
* @since 1.1
*/
public synchronized int getSoTimeout() throws SocketException
@ -129,6 +163,13 @@ public class DatagramSocket
return 0;
}
/**
* Receive a datagram packet
*
* @param p The datagram packet to put the incoming data into
*
* @exception IOException If an error occurs
*/
public synchronized void receive(DatagramPacket p) throws IOException
{
SecurityManager s = System.getSecurityManager();
@ -138,6 +179,13 @@ public class DatagramSocket
impl.receive(p);
}
/**
* Sends a datagram packet
*
* @param p The datagram packet to send
*
* @exception IOException If an error occurs
*/
public void send(DatagramPacket p) throws IOException
{
// JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api.
@ -151,11 +199,17 @@ public class DatagramSocket
s.checkConnect(addr.getHostAddress(), p.getPort());
}
// FIXME: if this is a subclass of MulticastSocket, use getTTL for TTL val.
// FIXME: if this is a subclass of MulticastSocket, use getTimeToLive for TTL val.
impl.send(p);
}
/**
* Sets a new value for SO_TIMEOUT
*
* @param timeout The timeout in milliseconds
*
* @exception SocketException If an error occurs
*
* @since 1.1
*/
public synchronized void setSoTimeout(int timeout) throws SocketException
@ -166,25 +220,53 @@ public class DatagramSocket
impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
}
// JDK1.2
// public void connect(InetAddress address, int port)
// {
// }
/**
* Connects the datagrem socket to a specified address/port
*
* @param address The address to connect to
* @param port The port to connect to
*
* @exception SocketException If an error occurs
*
* @since 1.2
*/
public void connect(InetAddress address, int port)
throws SocketException
{
//impl.connect(address, port);
}
// JDK1.2
// public void disconnect()
// {
// }
/**
* Disconnects the datagram socket
*
* @since 1.2
*/
public void disconnect()
{
//impl.disconnect();
}
// JDK1.2
// public InetAddress getInetAddress()
// {
// }
/**
* Returns the InetAddress the socket is connected to
* or null if the socket is not connected
*
* @since 1.2
*/
public InetAddress getInetAddress()
{
// FIXME:
return null;
}
// JDK1.2
// public int getPort()
// {
// }
/**
* Returns the local port number of the socket
*
* @since 1.2
*/
public int getPort()
{
return impl.localPort;
}
/**
* This method returns the value of the system level socket option
@ -207,6 +289,108 @@ public class DatagramSocket
throw new SocketException("Unexpected type");
}
/**
* Enables/Disables SO_REUSEADDR
*
* @param on Whether or not to have SO_REUSEADDR turned on
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public void setReuseAddress(boolean on) throws SocketException
{
impl.setOption (SocketOptions.SO_REUSEADDR, new Boolean (on));
}
/**
* Checks if SO_REUSEADDR is enabled
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public boolean getReuseAddress() throws SocketException
{
Object obj = impl.getOption (SocketOptions.SO_REUSEADDR);
if (obj instanceof Boolean)
return(((Boolean) obj).booleanValue ());
else
throw new SocketException ("Unexpected type");
}
/**
* Enables/Disables SO_BROADCAST
*
* @param on Whether or not to have SO_BROADCAST turned on
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public void setBroadcast(boolean on) throws SocketException
{
impl.setOption (SocketOptions.SO_BROADCAST, new Boolean (on));
}
/**
* Checks if SO_BROADCAST is enabled
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public boolean getBroadcast() throws SocketException
{
Object obj = impl.getOption (SocketOptions.SO_BROADCAST);
if (obj instanceof Boolean)
return ((Boolean) obj).booleanValue ();
else
throw new SocketException ("Unexpected type");
}
/**
* Sets the traffic class value
*
* @param tc The traffic class
*
* @exception SocketException If an error occurs
* @exception IllegalArgumentException If tc < 0 or rc > 255
*
* @see DatagramSocket:getTrafficClass
*
* @since 1.4
*/
public void setTrafficClass(int tc)
throws SocketException
{
if (tc < 0 || tc > 255)
throw new IllegalArgumentException();
impl.setOption (SocketOptions.IP_TOS, new Integer (tc));
}
/**
* Returns the current traffic class
*
* @see DatagramSocket:setTrafficClass
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public int getTrafficClass() throws SocketException
{
Object obj = impl.getOption(SocketOptions.IP_TOS);
if (obj instanceof Integer)
return ((Integer) obj).intValue ();
else
throw new SocketException ("Unexpected type");
}
/**
* This method returns the value of the system level socket option
* SO_SNDBUF, which is used by the operating system to tune buffer

View File

@ -114,6 +114,8 @@ public class MulticastSocket extends DatagramSocket
* @exception IOException If an error occurs
*
* @deprecated 1.2 Replaced by getTimeToLive()
*
* @see Multicastsocket:getTimeToLive
*/
public byte getTTL() throws IOException
{
@ -150,6 +152,42 @@ public class MulticastSocket extends DatagramSocket
impl.setOption(SocketOptions.IP_MULTICAST_IF, inf);
}
/**
* Disable/Enable local loopback of multicast packets. The option is used by
* the platform's networking code as a hint for setting whether multicast
* data will be looped back to the local socket.
*
* Because this option is a hint, applications that want to verify what
* loopback mode is set to should call #getLoopbackMode
*
* @param disable True to disable loopback mode
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public void setLoopbackMode(boolean disable) throws SocketException
{
impl.setOption (SocketOptions.IP_MULTICAST_LOOP, new Boolean (disable));
}
/**
* Checks if local loopback mode is enabled or not
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public boolean getLoopbackMode() throws SocketException
{
Object obj = impl.getOption (SocketOptions.IP_MULTICAST_LOOP);
if (obj instanceof Boolean)
return ((Boolean) obj).booleanValue ();
else
throw new SocketException ("Unexpected type");
}
/**
* Sets the "Time to Live" value for a socket. The value must be between
* 1 and 255.
@ -159,6 +197,8 @@ public class MulticastSocket extends DatagramSocket
* @exception IOException If an error occurs
*
* @deprecated 1.2 Replaced by <code>setTimeToLive</code>
*
* @see MulticastSocket:setTimeToLive
*/
public void setTTL(byte ttl) throws IOException
{

View File

@ -29,7 +29,12 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl
static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
_Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
_Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
_Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
_Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
_Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
_Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
_Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
_Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
_Jv_IP_TOS_ = SocketOptions.IP_TOS,
_Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
_Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
_Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
@ -67,7 +72,7 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl
public native void setOption(int optID, Object value) throws SocketException;
public native Object getOption(int optID) throws SocketException;
private native void mcastGrp(InetAddress inetaddr, boolean join)
throws IOException;
throws IOException;
protected native void close();
// Deprecated in JDK 1.2.

View File

@ -28,7 +28,12 @@ class PlainSocketImpl extends SocketImpl
static final int _Jv_TCP_NODELAY_ = SocketOptions.TCP_NODELAY,
_Jv_SO_BINDADDR_ = SocketOptions.SO_BINDADDR,
_Jv_SO_REUSEADDR_ = SocketOptions.SO_REUSEADDR,
_Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
_Jv_SO_BROADCAST_ = SocketOptions.SO_BROADCAST,
_Jv_SO_OOBINLINE_ = SocketOptions.SO_OOBINLINE,
_Jv_IP_MULTICAST_IF_ = SocketOptions.IP_MULTICAST_IF,
_Jv_IP_MULTICAST_IF2_ = SocketOptions.IP_MULTICAST_IF2,
_Jv_IP_MULTICAST_LOOP_ = SocketOptions.IP_MULTICAST_LOOP,
_Jv_IP_TOS_ = SocketOptions.IP_TOS,
_Jv_SO_LINGER_ = SocketOptions.SO_LINGER,
_Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
_Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,

View File

@ -528,6 +528,18 @@ java::net::PlainDatagramSocketImpl::setOption (jint optID,
throw new java::net::SocketException (
JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
return;
case _Jv_SO_BROADCAST_ :
if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
val_len) != 0)
goto error;
break;
case _Jv_SO_OOBINLINE_ :
throw new java::net::SocketException (
JvNewStringUTF ("SO_OOBINLINE: not valid for UDP"));
break;
case _Jv_SO_SNDBUF_ :
case _Jv_SO_RCVBUF_ :
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
@ -591,6 +603,23 @@ java::net::PlainDatagramSocketImpl::setOption (jint optID,
if (::setsockopt (fnum, level, opname, ptr, len) != 0)
goto error;
return;
case _Jv_IP_MULTICAST_IF2_ :
throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
break;
case _Jv_IP_MULTICAST_LOOP_ :
throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_LOOP: not yet implemented"));
break;
case _Jv_IP_TOS_ :
if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
val_len) != 0)
goto error;
return;
case _Jv_SO_TIMEOUT_ :
timeout = val;
return;
@ -625,6 +654,18 @@ java::net::PlainDatagramSocketImpl::getOption (jint optID)
throw new java::net::SocketException (
JvNewStringUTF ("SO_KEEPALIVE not valid for UDP"));
break;
case _Jv_SO_BROADCAST_ :
if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
&val_len) != 0)
goto error;
return new java::lang::Boolean (val != 0);
case _Jv_SO_OOBINLINE_ :
throw new java::net::SocketException (
JvNewStringUTF ("SO_OOBINLINE not valid for UDP"));
break;
case _Jv_SO_RCVBUF_ :
case _Jv_SO_SNDBUF_ :
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
@ -697,6 +738,24 @@ java::net::PlainDatagramSocketImpl::getOption (jint optID)
case _Jv_SO_TIMEOUT_ :
return new java::lang::Integer (timeout);
break;
case _Jv_IP_MULTICAST_IF2_ :
throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_IF2: not yet implemented"));
break;
case _Jv_IP_MULTICAST_LOOP_ :
if (::getsockopt (fnum, SOL_SOCKET, IP_MULTICAST_LOOP, (char *) &val,
&val_len) != 0)
goto error;
return new java::lang::Boolean (val != 0);
case _Jv_IP_TOS_ :
if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
&val_len) != 0)
goto error;
return new java::lang::Integer (val);
default :
errno = ENOPROTOOPT;
}

View File

@ -747,7 +747,19 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
if (::setsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
val_len) != 0)
goto error;
break;
case _Jv_SO_BROADCAST_ :
throw new java::net::SocketException (
JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
break;
case _Jv_SO_OOBINLINE_ :
if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
val_len) != 0)
goto error;
break;
case _Jv_SO_LINGER_ :
#ifdef SO_LINGER
struct linger l_val;
@ -781,6 +793,23 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
return;
case _Jv_IP_MULTICAST_IF2_ :
throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
break;
case _Jv_IP_MULTICAST_LOOP_ :
throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
break;
case _Jv_IP_TOS_ :
if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
val_len) != 0)
goto error;
break;
case _Jv_SO_REUSEADDR_ :
throw new java::net::SocketException (
JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
@ -830,7 +859,7 @@ java::net::PlainSocketImpl::getOption (jint optID)
if (l_val.l_onoff)
return new java::lang::Integer (l_val.l_linger);
else
return new java::lang::Boolean ((__java_boolean)false);
return new java::lang::Boolean ((jboolean)false);
#else
throw new java::lang::InternalError (
JvNewStringUTF ("SO_LINGER not supported"));
@ -844,6 +873,18 @@ java::net::PlainSocketImpl::getOption (jint optID)
else
return new java::lang::Boolean (val != 0);
case _Jv_SO_BROADCAST_ :
if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
&val_len) != 0)
goto error;
return new java::lang::Boolean ((__java_boolean)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);
case _Jv_SO_RCVBUF_ :
case _Jv_SO_SNDBUF_ :
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
@ -888,6 +929,24 @@ java::net::PlainSocketImpl::getOption (jint optID)
throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
break;
case _Jv_IP_MULTICAST_IF2_ :
throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
break;
case _Jv_IP_MULTICAST_LOOP_ :
throw new java::net::SocketException(
JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
break;
case _Jv_IP_TOS_ :
if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
&val_len) != 0)
goto error;
return new java::lang::Integer (val);
break;
case _Jv_SO_REUSEADDR_ :
throw new java::net::SocketException (
JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));