2002-09-10 Michael Koch <konqueror@gmx.de>
* java/net/SocketImpl.java (connect): New method. (supportsUrgentData): New method. (sendUrgentData): New method. * java/net/PlainSocketImpl.java (connect): One new method and two new implementation. (sendUrgentData): New method. * java/natPlainSocketImpl.cc (connect): Arguments changed, added support for timeouts. (getOption): Another __java_boolean to jboolean. From-SVN: r57009
This commit is contained in:
parent
bfae804050
commit
a886956a40
4 changed files with 118 additions and 12 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
2002-09-10 Michael Koch <konqueror@gmx.de>
|
||||||
|
|
||||||
|
* java/net/SocketImpl.java
|
||||||
|
(connect): New method.
|
||||||
|
(supportsUrgentData): New method.
|
||||||
|
(sendUrgentData): New method.
|
||||||
|
* java/net/PlainSocketImpl.java
|
||||||
|
(connect): One new method and two new implementation.
|
||||||
|
(sendUrgentData): New method.
|
||||||
|
* java/natPlainSocketImpl.cc
|
||||||
|
(connect): Arguments changed, added support for timeouts.
|
||||||
|
(getOption): Another __java_boolean to jboolean.
|
||||||
|
|
||||||
2002-09-07 Adam Megacz <adam@xwt.org>
|
2002-09-07 Adam Megacz <adam@xwt.org>
|
||||||
|
|
||||||
* java/net/natPlainDatagramSocket.cc: include ws2tcpip.h for
|
* java/net/natPlainDatagramSocket.cc: include ws2tcpip.h for
|
||||||
|
|
|
@ -67,10 +67,15 @@ class PlainSocketImpl extends SocketImpl
|
||||||
|
|
||||||
protected void connect (String host, int port) throws IOException
|
protected void connect (String host, int port) throws IOException
|
||||||
{
|
{
|
||||||
connect(InetAddress.getByName(host), port);
|
connect (new InetSocketAddress (InetAddress.getByName(host), port), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected native void connect (InetAddress host, int port)
|
protected void connect (InetAddress host, int port) throws IOException
|
||||||
|
{
|
||||||
|
connect (new InetSocketAddress (host, port), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected native void connect (SocketAddress addr, int timeout)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
protected native void bind (InetAddress host, int port) throws IOException;
|
protected native void bind (InetAddress host, int port) throws IOException;
|
||||||
|
@ -88,6 +93,8 @@ class PlainSocketImpl extends SocketImpl
|
||||||
|
|
||||||
protected native void close () throws IOException;
|
protected native void close () throws IOException;
|
||||||
|
|
||||||
|
protected native void sendUrgentData(int data)
|
||||||
|
throws IOException;
|
||||||
|
|
||||||
// Stream handling.
|
// Stream handling.
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,21 @@ public abstract class SocketImpl implements SocketOptions
|
||||||
protected abstract void connect(InetAddress host, int port)
|
protected abstract void connect(InetAddress host, int port)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connects to the socket to the host specified in address. This
|
||||||
|
* method blocks until successful connected or the timeout occurs.
|
||||||
|
* A timeout of zero means no timout.
|
||||||
|
*
|
||||||
|
* @param address Data of remote host
|
||||||
|
* @param timeout time to wait to stop connecting
|
||||||
|
*
|
||||||
|
* @exception IOException If an error occurs
|
||||||
|
*
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
protected abstract void connect(SocketAddress address, int timeout)
|
||||||
|
throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds to the specified port on the specified addr. Note that this addr
|
* Binds to the specified port on the specified addr. Note that this addr
|
||||||
* must represent a local IP address.
|
* must represent a local IP address.
|
||||||
|
@ -214,6 +229,31 @@ public abstract class SocketImpl implements SocketOptions
|
||||||
*/
|
*/
|
||||||
protected int getPort() { return port; }
|
protected int getPort() { return port; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true or false when this socket supports sending urgent data
|
||||||
|
* or not.
|
||||||
|
*
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
protected boolean supportsUrgentData()
|
||||||
|
{
|
||||||
|
// This method has to be overwritten by socket classes that support
|
||||||
|
// sending urgend data.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends one byte of urgent data to the socket.
|
||||||
|
*
|
||||||
|
* @param data The byte to send, the low eight bits of it
|
||||||
|
*
|
||||||
|
* @exception IOException If an error occurs
|
||||||
|
*
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
protected abstract void sendUrgentData(int data)
|
||||||
|
throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the local port this socket is bound to
|
* Returns the local port this socket is bound to
|
||||||
*
|
*
|
||||||
|
|
|
@ -118,7 +118,9 @@ _Jv_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
|
||||||
#include <java/net/ConnectException.h>
|
#include <java/net/ConnectException.h>
|
||||||
#include <java/net/PlainSocketImpl.h>
|
#include <java/net/PlainSocketImpl.h>
|
||||||
#include <java/net/InetAddress.h>
|
#include <java/net/InetAddress.h>
|
||||||
|
#include <java/net/InetSocketAddress.h>
|
||||||
#include <java/net/SocketException.h>
|
#include <java/net/SocketException.h>
|
||||||
|
#include <java/net/SocketTimeoutException.h>
|
||||||
#include <java/lang/InternalError.h>
|
#include <java/lang/InternalError.h>
|
||||||
#include <java/lang/Object.h>
|
#include <java/lang/Object.h>
|
||||||
#include <java/lang/Boolean.h>
|
#include <java/lang/Boolean.h>
|
||||||
|
@ -146,7 +148,7 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *, jint)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
java::net::PlainSocketImpl::connect (java::net::InetAddress *, jint)
|
java::net::PlainSocketImpl::connect (java::net::SocketAddress *, jint)
|
||||||
{
|
{
|
||||||
throw new ConnectException (
|
throw new ConnectException (
|
||||||
JvNewStringLatin1 ("SocketImpl.connect: unimplemented"));
|
JvNewStringLatin1 ("SocketImpl.connect: unimplemented"));
|
||||||
|
@ -208,6 +210,13 @@ java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
|
||||||
JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
|
JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
java::net::PlainSocketImpl::sendUrgentData(jint data)
|
||||||
|
{
|
||||||
|
throw new SocketException (
|
||||||
|
JvNewStringLatin1 ("SocketImpl.sendUrgentData: unimplemented"));
|
||||||
|
}
|
||||||
|
|
||||||
jint
|
jint
|
||||||
java::net::PlainSocketImpl::available(void)
|
java::net::PlainSocketImpl::available(void)
|
||||||
{
|
{
|
||||||
|
@ -316,8 +325,13 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
java::net::PlainSocketImpl::connect (java::net::InetAddress *host, jint rport)
|
java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr,
|
||||||
|
jint timeout)
|
||||||
{
|
{
|
||||||
|
java::net::InetSocketAddress *tmp = (java::net::InetSocketAddress*) addr;
|
||||||
|
java::net::InetAddress *host = tmp->getAddress();
|
||||||
|
jint rport = tmp->getPort();
|
||||||
|
|
||||||
union SockAddr u;
|
union SockAddr u;
|
||||||
socklen_t addrlen = sizeof(u);
|
socklen_t addrlen = sizeof(u);
|
||||||
jbyteArray haddress = host->addr;
|
jbyteArray haddress = host->addr;
|
||||||
|
@ -343,8 +357,34 @@ java::net::PlainSocketImpl::connect (java::net::InetAddress *host, jint rport)
|
||||||
else
|
else
|
||||||
throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
|
throw new java::net::SocketException (JvNewStringUTF ("invalid length"));
|
||||||
|
|
||||||
|
if (timeout > 0)
|
||||||
|
{
|
||||||
|
int flags = ::fcntl (fnum, F_GETFL);
|
||||||
|
::fcntl (fnum, F_SETFL, flags | O_NONBLOCK);
|
||||||
|
|
||||||
|
if ((_Jv_connect (fnum, ptr, len) != 0) && (errno != EINPROGRESS))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
fd_set rset;
|
||||||
|
struct timeval tv;
|
||||||
|
FD_ZERO(&rset);
|
||||||
|
FD_SET(fnum, &rset);
|
||||||
|
tv.tv_sec = timeout / 1000;
|
||||||
|
tv.tv_usec = (timeout % 1000) * 1000;
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
|
||||||
|
goto error;
|
||||||
|
else if (retval == 0)
|
||||||
|
throw new java::net::SocketTimeoutException (
|
||||||
|
JvNewStringUTF("Connect timed out"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (_Jv_connect (fnum, ptr, len) != 0)
|
if (_Jv_connect (fnum, ptr, len) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
address = host;
|
address = host;
|
||||||
port = rport;
|
port = rport;
|
||||||
// A bind may not have been done on this socket; if so, set localport now.
|
// A bind may not have been done on this socket; if so, set localport now.
|
||||||
|
@ -518,6 +558,12 @@ java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
java::net::PlainSocketImpl::sendUrgentData (jint)
|
||||||
|
{
|
||||||
|
throw new SocketException (JvNewStringLatin1 (
|
||||||
|
"PlainSocketImpl: sending of urgent data not supported by this socket"));
|
||||||
|
}
|
||||||
|
|
||||||
// Read a single byte from the socket.
|
// Read a single byte from the socket.
|
||||||
jint
|
jint
|
||||||
|
@ -877,13 +923,13 @@ java::net::PlainSocketImpl::getOption (jint optID)
|
||||||
if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
|
if (::getsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &val,
|
||||||
&val_len) != 0)
|
&val_len) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
return new java::lang::Boolean ((__java_boolean)val);
|
return new java::lang::Boolean ((jboolean)val);
|
||||||
|
|
||||||
case _Jv_SO_OOBINLINE_ :
|
case _Jv_SO_OOBINLINE_ :
|
||||||
if (::getsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
|
if (::getsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
|
||||||
&val_len) != 0)
|
&val_len) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
return new java::lang::Boolean ((__java_boolean)val);
|
return new java::lang::Boolean ((jboolean)val);
|
||||||
|
|
||||||
case _Jv_SO_RCVBUF_ :
|
case _Jv_SO_RCVBUF_ :
|
||||||
case _Jv_SO_SNDBUF_ :
|
case _Jv_SO_SNDBUF_ :
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue