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

* java/net/Socket.java
	(sendUrgentData): New method.
	(getChannel): New method.
	* java/net/ServerSocket.java
	(getChannel): New method.
	(isBound): New method.
	* java/net/DatagramSocket.java
	(DatagramSocket): Two new methods.
	(bind): New method.
	(getChannel): New method.
	(isBound): New method.
	(send): Added newline to to make shorter lines.
	* java/net/PlainDatagramSocketImpl.java
	(mcastGrp): Added argument.
	(join): Use new mcastGrp.
	(leave): Use new mcastGrp.
	(joinGroup): New method.
	(leaveGroup): New method.
	* java/net/natPlainDatagramSocketImpl.cc
	(mcastGrp): Added argument, no yet really implemented.
	(getOption): Added newline for shorter lines.
	* java/net/natPlainSocketImpl.cc
	(read, setOption, getOption): Added newline for shorter lines.

From-SVN: r57380
This commit is contained in:
Michael Koch 2002-09-21 06:59:20 +00:00 committed by Michael Koch
parent 84d7dd4a53
commit be362a0d5b
7 changed files with 205 additions and 13 deletions

View File

@ -1,3 +1,29 @@
2002-09-21 Michael Koch <konqueror@gmx.de>
* java/net/Socket.java
(sendUrgentData): New method.
(getChannel): New method.
* java/net/ServerSocket.java
(getChannel): New method.
(isBound): New method.
* java/net/DatagramSocket.java
(DatagramSocket): Two new methods.
(bind): New method.
(getChannel): New method.
(isBound): New method.
(send): Added newline to to make shorter lines.
* java/net/PlainDatagramSocketImpl.java
(mcastGrp): Added argument.
(join): Use new mcastGrp.
(leave): Use new mcastGrp.
(joinGroup): New method.
(leaveGroup): New method.
* java/net/natPlainDatagramSocketImpl.cc
(mcastGrp): Added argument, no yet really implemented.
(getOption): Added newline for shorter lines.
* java/net/natPlainSocketImpl.cc
(read, setOption, getOption): Added newline for shorter lines.
2002-09-19 Tom Tromey <tromey@redhat.com>
* java/lang/ClassLoader.java (resolveClass0): Set cause for

View File

@ -1,6 +1,6 @@
// DatagramSocket.java
/* Copyright (C) 1999, 2000 Free Software Foundation
/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
This file is part of libgcj.
@ -10,6 +10,7 @@ details. */
package java.net;
import java.io.IOException;
import java.nio.channels.DatagramChannel;
/**
* @author Warren Levy <warrenl@cygnus.com>
@ -26,11 +27,41 @@ public class DatagramSocket
{
DatagramSocketImpl impl;
DatagramChannel ch;
public DatagramSocket() throws SocketException
{
this(0, null);
}
/**
* Creates a DatagramSocket from a specified DatagramSocketImpl instance
*
* @param impl The DatagramSocketImpl the socket will be created from
*
* @since 1.4
*/
protected DatagramSocket (DatagramSocketImpl impl)
{
this.impl = impl;
}
/**
* Creates a datagram socket that is bound to a given socket address
*
* @param bindaddr The socket address to bind to
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public DatagramSocket (SocketAddress bindaddr)
throws SocketException
{
this (((InetSocketAddress) bindaddr).getPort (),
((InetSocketAddress) bindaddr).getAddress ());
}
/**
* Creates a datagram socket that is bound to a specific port
*
@ -84,6 +115,22 @@ public class DatagramSocket
impl.bind(port, laddr == null ? InetAddress.ANY_IF : laddr);
}
/**
* Binds the socket to the given socket addres
*
* @param address The socket address to bind to
*
* @exception SocketException If an error occurs
*
* @since 1.4
*/
public void bind (SocketAddress address)
throws SocketException
{
InetSocketAddress tmp = (InetSocketAddress) address;
impl.bind (tmp.getPort (), tmp.getAddress ());
}
/**
* Closes the datagram socket
*/
@ -92,6 +139,16 @@ public class DatagramSocket
impl.close();
}
/**
* Gets a datagram channel assoziated with the socket
*
* @since 1.4
*/
public DatagramChannel getChannel()
{
return ch;
}
/**
* Returns the local address of the datagram socket
*
@ -199,7 +256,8 @@ public class DatagramSocket
s.checkConnect(addr.getHostAddress(), p.getPort());
}
// FIXME: if this is a subclass of MulticastSocket, use getTimeToLive for TTL val.
// FIXME: if this is a subclass of MulticastSocket,
// use getTimeToLive for TTL val.
impl.send(p);
}
@ -246,6 +304,25 @@ public class DatagramSocket
//impl.disconnect();
}
/**
* Returns the binding state of the socket
*
* @since 1.4
*/
public boolean isBound()
{
try
{
Object bindaddr = impl.getOption (SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
return false;
}
return true;
}
/**
* Returns the InetAddress the socket is connected to
* or null if the socket is not connected

View File

@ -72,8 +72,8 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl
protected native void receive(DatagramPacket p) throws IOException;
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;
private native void mcastGrp(InetAddress inetaddr, NetworkInterface netIf,
boolean join) throws IOException;
protected native void close();
// Deprecated in JDK 1.2.
@ -90,12 +90,24 @@ class PlainDatagramSocketImpl extends DatagramSocketImpl
protected void join(InetAddress inetaddr) throws IOException
{
mcastGrp(inetaddr, true);
mcastGrp(inetaddr, null, true);
}
protected void leave(InetAddress inetaddr) throws IOException
{
mcastGrp(inetaddr, false);
mcastGrp(inetaddr, null, false);
}
protected void joinGroup (SocketAddress mcastaddr, NetworkInterface netIf)
throws IOException
{
mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, true);
}
protected void leaveGroup (SocketAddress mcastaddr, NetworkInterface netIf)
throws IOException
{
mcastGrp(((InetSocketAddress)mcastaddr).getAddress(), netIf, false);
}
protected void finalize() throws Throwable

View File

@ -38,6 +38,7 @@ exception statement from your version. */
package java.net;
import java.io.IOException;
import java.nio.channels.ServerSocketChannel;
/* Written using on-line Java Platform 1.2 API Specification.
* Status: I believe all methods are implemented.
@ -74,6 +75,12 @@ public class ServerSocket
*/
private SocketImpl impl;
/**
* ServerSocketChannel of this ServerSocket. This channel only exists
* when the socket is created by ServerSocketChannel.open().
*/
private ServerSocketChannel ch;
/**
* Private constructor that simply sets the implementation.
*/
@ -281,6 +288,39 @@ public class ServerSocket
impl.close();
}
/**
* Returns the unique ServerSocketChannel object
* associated with this socket, if any.
*
* The socket only has a ServerSocketChannel if its created
* by ServerSocketChannel.open.
*
* @since 1.4
*/
public ServerSocketChannel getChannel()
{
return ch;
}
/**
* Returns true then the socket is bound, otherwise false
*
* @since 1.4
*/
public boolean isBound()
{
try
{
Object bindaddr = impl.getOption (SocketOptions.SO_BINDADDR);
}
catch (SocketException e)
{
return false;
}
return true;
}
/**
* Sets the value of SO_TIMEOUT. A value of 0 implies that SO_TIMEOUT is
* disabled (ie, operations never time out). This is the number of

View File

@ -38,6 +38,7 @@ exception statement from your version. */
package java.net;
import java.io.*;
import java.nio.channels.SocketChannel;
/* Written using on-line Java Platform 1.2 API Specification.
* Status: I believe all methods are implemented.
@ -78,6 +79,8 @@ public class Socket
*/
SocketImpl impl;
SocketChannel ch; // this field must have been set if created by SocketChannel
// Constructors
/**
@ -524,6 +527,21 @@ public class Socket
return -1;
}
/**
* Sends urgent data through the socket
*
* @param data The data to send.
* Only the lowest eight bits of data are sent
*
* @exception IOException If an error occurs
*
* @since 1.4
*/
public void sendUrgentData (int data) throws IOException
{
impl.sendUrgentData (data);
}
/**
* Enables/disables the SO_OOBINLINE option
*
@ -819,4 +837,14 @@ public class Socket
if (impl != null)
impl.shutdownOutput();
}
/**
* Returns the socket channel associated with this socket.
*
* It returns null if no associated socket exists.
*/
public SocketChannel getChannel()
{
return ch;
}
}

View File

@ -63,6 +63,7 @@ _Jv_bind (int fd, struct sockaddr *addr, int addrlen)
#include <java/net/SocketException.h>
#include <java/net/PlainDatagramSocketImpl.h>
#include <java/net/InetAddress.h>
#include <java/net/NetworkInterface.h>
#include <java/net/DatagramPacket.h>
#include <java/lang/InternalError.h>
#include <java/lang/Object.h>
@ -136,6 +137,7 @@ java::net::PlainDatagramSocketImpl::getTimeToLive ()
void
java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *,
java::net::NetworkInterface *,
jboolean)
{
throw new java::io::IOException (
@ -504,8 +506,11 @@ java::net::PlainDatagramSocketImpl::getTimeToLive ()
void
java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *inetaddr,
java::net::NetworkInterface *,
jboolean join)
{
// FIXME: implement use of NetworkInterface
union McastReq u;
jbyteArray haddress = inetaddr->addr;
jbyte *bytes = elements (haddress);
@ -769,7 +774,8 @@ java::net::PlainDatagramSocketImpl::getOption (jint optID)
}
#endif
else
throw new java::net::SocketException (JvNewStringUTF ("invalid family"));
throw new java::net::SocketException (
JvNewStringUTF ("invalid family"));
localAddress = new java::net::InetAddress (laddr, NULL);
}
return localAddress;

View File

@ -381,7 +381,7 @@ java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr,
throw new java::net::SocketTimeoutException (
JvNewStringUTF("Connect timed out"));
}
else
else
#endif
{
if (_Jv_connect (fnum, ptr, len) != 0)
@ -588,7 +588,8 @@ java::net::PlainSocketImpl::read(void)
timeout_value.tv_sec = timeout / 1000;
timeout_value.tv_usec = (timeout % 1000) * 1000;
// Select on the fds.
int sel_retval = _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
int sel_retval =
_Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
// If select returns 0 we've waited without getting data...
// that means we've timed out.
if (sel_retval == 0)
@ -647,7 +648,8 @@ java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
timeout_value.tv_sec = timeout / 1000;
timeout_value.tv_usec =(timeout % 1000) * 1000;
// Select on the fds.
int sel_retval = _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
int sel_retval =
_Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
// We're only interested in the 0 return.
// error returns still require us to try to read
// the socket to see what happened.
@ -776,7 +778,8 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
}
else
{
throw new java::lang::IllegalArgumentException (JvNewStringLatin1 ("`value' must be Boolean or Integer"));
throw new java::lang::IllegalArgumentException (
JvNewStringLatin1 ("`value' must be Boolean or Integer"));
}
switch (optID)
@ -968,8 +971,8 @@ java::net::PlainSocketImpl::getOption (jint optID)
}
#endif
else
throw
new java::net::SocketException (JvNewStringUTF ("invalid family"));
throw new java::net::SocketException (
JvNewStringUTF ("invalid family"));
localAddress = new java::net::InetAddress (laddr, NULL);
}
return localAddress;