Commit 6602dd4a by Michael Koch Committed by Michael Koch

PlainSocketImpl.java: Reworked imports.

2002-11-18  Michael Koch <konqueror@gmx.de>

	* java/net/PlainSocketImpl.java: Reworked imports.
	* java/net/ServerSocket.java
	(ServerSocket): Create socket.
	* java/net/SocketAddress.java: Documentation added.
	* java/net/natPlainSocketImpl.cc: Reindented.
	* java/nio/ReadOnlyBufferException.java: New file
	* java/nio/channels/ClosedChannelException.java: Documentation added.
	* java/nio/channels/ClosedSelectorException.java: New file.

From-SVN: r59214
parent 3503150c
2002-11-18 Michael Koch <konqueror@gmx.de>
* java/net/PlainSocketImpl.java: Reworked imports.
* java/net/ServerSocket.java
(ServerSocket): Create socket.
* java/net/SocketAddress.java: Documentation added.
* java/net/natPlainSocketImpl.cc: Reindented.
* java/nio/ReadOnlyBufferException.java: New file
* java/nio/channels/ClosedChannelException.java: Documentation added.
* java/nio/channels/ClosedSelectorException.java: New file.
2002-11-17 Mark Wielaard <mark@klomp.org> 2002-11-17 Mark Wielaard <mark@klomp.org>
* java/net/HttpURLConnection.java ((getPermission): Take port * java/net/HttpURLConnection.java ((getPermission): Take port
......
...@@ -9,8 +9,8 @@ Libgcj License. Please consult the file "LIBGCJ_LICENSE" for ...@@ -9,8 +9,8 @@ Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */ details. */
package java.net; package java.net;
import java.io.*;
import java.io.IOException;
/** /**
* The standard GCJ socket implementation. * The standard GCJ socket implementation.
......
...@@ -60,16 +60,11 @@ import java.nio.channels.ServerSocketChannel; ...@@ -60,16 +60,11 @@ import java.nio.channels.ServerSocketChannel;
*/ */
public class ServerSocket public class ServerSocket
{ {
// Class Variables
/** /**
* This is the user defined SocketImplFactory, if one is supplied * This is the user defined SocketImplFactory, if one is supplied
*/ */
private static SocketImplFactory factory; private static SocketImplFactory factory;
// Instance Variables
/** /**
* This is the SocketImp object to which most instance methods in this * This is the SocketImp object to which most instance methods in this
* class are redirected * class are redirected
...@@ -95,6 +90,8 @@ public class ServerSocket ...@@ -95,6 +90,8 @@ public class ServerSocket
impl = factory.createSocketImpl(); impl = factory.createSocketImpl();
else else
impl = new PlainSocketImpl(); impl = new PlainSocketImpl();
impl.create(true);
} }
/** /**
......
...@@ -37,20 +37,23 @@ exception statement from your version. */ ...@@ -37,20 +37,23 @@ exception statement from your version. */
package java.net; package java.net;
import java.io.*; import java.io.Serializable;
/** /**
* Abstract base class for InetSocketAddress. * Abstract base class for InetSocketAddress.
* InetSocketAddress is to my knowledge the only derived * InetSocketAddress is to my knowledge the only derived
* class. [Ronald] * class. [Ronald]
*
* @since 1.4
*/ */
public abstract class SocketAddress implements Serializable public abstract class SocketAddress implements Serializable
{ {
static final long serialVersionUID = 5215720748342549866L; static final long serialVersionUID = 5215720748342549866L;
/**
* Initializes the socket address.
*/
public SocketAddress() public SocketAddress()
{ {
} }
} }
...@@ -259,6 +259,7 @@ void ...@@ -259,6 +259,7 @@ void
java::net::PlainSocketImpl::create (jboolean stream) java::net::PlainSocketImpl::create (jboolean stream)
{ {
int sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0); int sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
if (sock < 0) if (sock < 0)
{ {
char* strerr = strerror (errno); char* strerr = strerror (errno);
...@@ -285,10 +286,12 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport) ...@@ -285,10 +286,12 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
if (len == 4) if (len == 4)
{ {
u.address.sin_family = AF_INET; u.address.sin_family = AF_INET;
if (host != NULL) if (host != NULL)
memcpy (&u.address.sin_addr, bytes, len); memcpy (&u.address.sin_addr, bytes, len);
else else
u.address.sin_addr.s_addr = htonl (INADDR_ANY); u.address.sin_addr.s_addr = htonl (INADDR_ANY);
len = sizeof (struct sockaddr_in); len = sizeof (struct sockaddr_in);
u.address.sin_port = htons (lport); u.address.sin_port = htons (lport);
} }
...@@ -311,14 +314,17 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport) ...@@ -311,14 +314,17 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
{ {
address = host; address = host;
socklen_t addrlen = sizeof(u); socklen_t addrlen = sizeof(u);
if (lport != 0) if (lport != 0)
localport = lport; localport = lport;
else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0) else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
localport = ntohs (u.address.sin_port); localport = ntohs (u.address.sin_port);
else else
goto error; goto error;
return; return;
} }
error: error:
char* strerr = strerror (errno); char* strerr = strerror (errno);
throw new java::net::BindException (JvNewStringUTF (strerr)); throw new java::net::BindException (JvNewStringUTF (strerr));
...@@ -326,7 +332,7 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport) ...@@ -326,7 +332,7 @@ java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
void void
java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr, java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr,
jint timeout) jint timeout)
{ {
java::net::InetSocketAddress *tmp = (java::net::InetSocketAddress*) addr; java::net::InetSocketAddress *tmp = (java::net::InetSocketAddress*) addr;
java::net::InetAddress *host = tmp->getAddress(); java::net::InetAddress *host = tmp->getAddress();
...@@ -376,10 +382,10 @@ java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr, ...@@ -376,10 +382,10 @@ java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr,
int retval; int retval;
if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0) if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
goto error; goto error;
else if (retval == 0) else if (retval == 0)
throw new java::net::SocketTimeoutException ( throw new java::net::SocketTimeoutException
JvNewStringUTF("Connect timed out")); (JvNewStringUTF ("Connect timed out"));
} }
else else
#endif #endif
...@@ -390,15 +396,18 @@ java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr, ...@@ -390,15 +396,18 @@ java::net::PlainSocketImpl::connect (java::net::SocketAddress *addr,
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.
if (localport == 0) if (localport == 0)
{ {
if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0) if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
localport = ntohs (u.address.sin_port); localport = ntohs (u.address.sin_port);
else else
goto error; goto error;
} }
return; return;
error: error:
char* strerr = strerror (errno); char* strerr = strerror (errno);
throw new java::net::ConnectException (JvNewStringUTF (strerr)); throw new java::net::ConnectException (JvNewStringUTF (strerr));
...@@ -434,14 +443,15 @@ java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s) ...@@ -434,14 +443,15 @@ java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s)
tv.tv_usec = (timeout % 1000) * 1000; tv.tv_usec = (timeout % 1000) * 1000;
int retval; int retval;
if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0) if ((retval = _Jv_select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
goto error; goto error;
else if (retval == 0) else if (retval == 0)
throw new java::io::InterruptedIOException ( throw new java::io::InterruptedIOException (
JvNewStringUTF("Accept timed out")); JvNewStringUTF("Accept timed out"));
} }
#endif /* WIN32 */ #endif /* WIN32 */
new_socket = _Jv_accept (fnum, (sockaddr*) &u, &addrlen); new_socket = _Jv_accept (fnum, (sockaddr*) &u, &addrlen);
if (new_socket < 0) if (new_socket < 0)
goto error; goto error;
...@@ -471,6 +481,7 @@ java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s) ...@@ -471,6 +481,7 @@ java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s)
s->address = new InetAddress (raddr, NULL); s->address = new InetAddress (raddr, NULL);
s->port = rport; s->port = rport;
return; return;
error: error:
char* strerr = strerror (errno); char* strerr = strerror (errno);
throw new java::io::IOException (JvNewStringUTF (strerr)); throw new java::io::IOException (JvNewStringUTF (strerr));
...@@ -491,7 +502,7 @@ java::net::PlainSocketImpl::close() ...@@ -491,7 +502,7 @@ java::net::PlainSocketImpl::close()
// These three errors are not errors according to tests performed // These three errors are not errors according to tests performed
// on the reference implementation. // on the reference implementation.
if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF) if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
throw new java::io::IOException (JvNewStringUTF (strerror (errno))); throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
} }
// Safe place to reset the file pointer. // Safe place to reset the file pointer.
fnum = -1; fnum = -1;
...@@ -509,20 +520,20 @@ java::net::PlainSocketImpl::write(jint b) ...@@ -509,20 +520,20 @@ java::net::PlainSocketImpl::write(jint b)
{ {
r = ::write (fnum, &d, 1); r = ::write (fnum, &d, 1);
if (r == -1) if (r == -1)
{ {
if (java::lang::Thread::interrupted()) if (java::lang::Thread::interrupted())
{ {
java::io::InterruptedIOException *iioe java::io::InterruptedIOException *iioe
= new java::io::InterruptedIOException = new java::io::InterruptedIOException
(JvNewStringLatin1 (strerror (errno))); (JvNewStringLatin1 (strerror (errno)));
iioe->bytesTransferred = 0; iioe->bytesTransferred = 0;
throw iioe; throw iioe;
} }
// Some errors should not cause exceptions. // Some errors should not cause exceptions.
if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF) if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
throw new java::io::IOException (JvNewStringUTF (strerror (errno))); throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
break; break;
} }
} }
} }
...@@ -537,24 +548,27 @@ java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len) ...@@ -537,24 +548,27 @@ java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
jbyte *bytes = elements (b) + offset; jbyte *bytes = elements (b) + offset;
int written = 0; int written = 0;
while (len > 0) while (len > 0)
{ {
int r = ::write (fnum, bytes, len); int r = ::write (fnum, bytes, len);
if (r == -1) if (r == -1)
{ {
if (java::lang::Thread::interrupted()) if (java::lang::Thread::interrupted())
{ {
java::io::InterruptedIOException *iioe java::io::InterruptedIOException *iioe
= new java::io::InterruptedIOException = new java::io::InterruptedIOException
(JvNewStringLatin1 (strerror (errno))); (JvNewStringLatin1 (strerror (errno)));
iioe->bytesTransferred = written; iioe->bytesTransferred = written;
throw iioe; throw iioe;
} }
// Some errors should not cause exceptions. // Some errors should not cause exceptions.
if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF) if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
throw new java::io::IOException (JvNewStringUTF (strerror (errno))); throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
break; break;
} }
written += r; written += r;
len -= r; len -= r;
bytes += r; bytes += r;
...@@ -578,37 +592,38 @@ java::net::PlainSocketImpl::read(void) ...@@ -578,37 +592,38 @@ java::net::PlainSocketImpl::read(void)
#ifndef WIN32 #ifndef WIN32
// Do timeouts via select. // Do timeouts via select.
if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE) if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
{ {
// Create the file descriptor set. // Create the file descriptor set.
fd_set read_fds; fd_set read_fds;
FD_ZERO (&read_fds); FD_ZERO (&read_fds);
FD_SET (fnum,&read_fds); FD_SET (fnum,&read_fds);
// Create the timeout struct based on our internal timeout value. // Create the timeout struct based on our internal timeout value.
struct timeval timeout_value; struct timeval timeout_value;
timeout_value.tv_sec = timeout / 1000; timeout_value.tv_sec = timeout / 1000;
timeout_value.tv_usec = (timeout % 1000) * 1000; timeout_value.tv_usec = (timeout % 1000) * 1000;
// Select on the fds. // Select on the fds.
int sel_retval = int sel_retval =
_Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value); _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
// If select returns 0 we've waited without getting data... // If select returns 0 we've waited without getting data...
// that means we've timed out. // that means we've timed out.
if (sel_retval == 0) if (sel_retval == 0)
throw new java::io::InterruptedIOException throw new java::io::InterruptedIOException
(JvNewStringUTF ("read timed out") ); (JvNewStringUTF ("read timed out") );
// If select returns ok we know we either got signalled or read some data... // If select returns ok we know we either got signalled or read some data...
// either way we need to try to read. // either way we need to try to read.
} }
#endif /* WIN32 */ #endif /* WIN32 */
int r = ::read (fnum, &b, 1); int r = ::read (fnum, &b, 1);
if (r == 0) if (r == 0)
return -1; return -1;
if (java::lang::Thread::interrupted()) if (java::lang::Thread::interrupted())
{ {
java::io::InterruptedIOException *iioe = java::io::InterruptedIOException *iioe =
new java::io::InterruptedIOException new java::io::InterruptedIOException
(JvNewStringUTF("read interrupted")); (JvNewStringUTF("read interrupted"));
iioe->bytesTransferred = r == -1 ? 0 : r; iioe->bytesTransferred = r == -1 ? 0 : r;
throw iioe; throw iioe;
} }
...@@ -616,10 +631,12 @@ java::net::PlainSocketImpl::read(void) ...@@ -616,10 +631,12 @@ java::net::PlainSocketImpl::read(void)
{ {
// Some errors cause us to return end of stream... // Some errors cause us to return end of stream...
if (errno == ENOTCONN) if (errno == ENOTCONN)
return -1; return -1;
// Other errors need to be signalled. // Other errors need to be signalled.
throw new java::io::IOException (JvNewStringUTF (strerror (errno))); throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
} }
return b & 0xFF; return b & 0xFF;
} }
...@@ -629,50 +646,55 @@ java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count) ...@@ -629,50 +646,55 @@ java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
{ {
if (! buffer) if (! buffer)
throw new java::lang::NullPointerException; throw new java::lang::NullPointerException;
jsize bsize = JvGetArrayLength (buffer); jsize bsize = JvGetArrayLength (buffer);
if (offset < 0 || count < 0 || offset + count > bsize) if (offset < 0 || count < 0 || offset + count > bsize)
throw new java::lang::ArrayIndexOutOfBoundsException; throw new java::lang::ArrayIndexOutOfBoundsException;
jbyte *bytes = elements (buffer) + offset; jbyte *bytes = elements (buffer) + offset;
// FIXME: implement timeout support for Win32 // FIXME: implement timeout support for Win32
#ifndef WIN32 #ifndef WIN32
// Do timeouts via select. // Do timeouts via select.
if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE) if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
{ {
// Create the file descriptor set. // Create the file descriptor set.
fd_set read_fds; fd_set read_fds;
FD_ZERO (&read_fds); FD_ZERO (&read_fds);
FD_SET (fnum, &read_fds); FD_SET (fnum, &read_fds);
// Create the timeout struct based on our internal timeout value. // Create the timeout struct based on our internal timeout value.
struct timeval timeout_value; struct timeval timeout_value;
timeout_value.tv_sec = timeout / 1000; timeout_value.tv_sec = timeout / 1000;
timeout_value.tv_usec =(timeout % 1000) * 1000; timeout_value.tv_usec =(timeout % 1000) * 1000;
// Select on the fds. // Select on the fds.
int sel_retval = int sel_retval =
_Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value); _Jv_select (fnum + 1, &read_fds, NULL, NULL, &timeout_value);
// We're only interested in the 0 return. // We're only interested in the 0 return.
// error returns still require us to try to read // error returns still require us to try to read
// the socket to see what happened. // the socket to see what happened.
if (sel_retval == 0) if (sel_retval == 0)
{ {
java::io::InterruptedIOException *iioe = java::io::InterruptedIOException *iioe =
new java::io::InterruptedIOException new java::io::InterruptedIOException
(JvNewStringUTF ("read interrupted")); (JvNewStringUTF ("read interrupted"));
iioe->bytesTransferred = 0; iioe->bytesTransferred = 0;
throw iioe; throw iioe;
} }
} }
#endif #endif
// Read the socket. // Read the socket.
int r = ::recv (fnum, (char *) bytes, count, 0); int r = ::recv (fnum, (char *) bytes, count, 0);
if (r == 0) if (r == 0)
return -1; return -1;
if (java::lang::Thread::interrupted()) if (java::lang::Thread::interrupted())
{ {
java::io::InterruptedIOException *iioe = java::io::InterruptedIOException *iioe =
new java::io::InterruptedIOException new java::io::InterruptedIOException
(JvNewStringUTF ("read interrupted")); (JvNewStringUTF ("read interrupted"));
iioe->bytesTransferred = r == -1 ? 0 : r; iioe->bytesTransferred = r == -1 ? 0 : r;
throw iioe; throw iioe;
} }
...@@ -680,10 +702,12 @@ java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count) ...@@ -680,10 +702,12 @@ java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
{ {
// Some errors cause us to return end of stream... // Some errors cause us to return end of stream...
if (errno == ENOTCONN) if (errno == ENOTCONN)
return -1; return -1;
// Other errors need to be signalled. // Other errors need to be signalled.
throw new java::io::IOException (JvNewStringUTF (strerror (errno))); throw new java::io::IOException (JvNewStringUTF (strerror (errno)));
} }
return r; return r;
} }
...@@ -698,6 +722,7 @@ java::net::PlainSocketImpl::available(void) ...@@ -698,6 +722,7 @@ java::net::PlainSocketImpl::available(void)
#if defined(FIONREAD) #if defined(FIONREAD)
r = ::ioctl (fnum, FIONREAD, &num); r = ::ioctl (fnum, FIONREAD, &num);
if (r == -1 && errno == ENOTTY) if (r == -1 && errno == ENOTTY)
{ {
// If the ioctl doesn't work, we don't care. // If the ioctl doesn't work, we don't care.
...@@ -718,34 +743,32 @@ java::net::PlainSocketImpl::available(void) ...@@ -718,34 +743,32 @@ java::net::PlainSocketImpl::available(void)
{ {
posix_error: posix_error:
throw new java::io::IOException(JvNewStringUTF(strerror(errno))); throw new java::io::IOException(JvNewStringUTF(strerror(errno)));
} }
// If we didn't get anything we can use select. // If we didn't get anything we can use select.
#if defined(HAVE_SELECT) #if defined(HAVE_SELECT)
if (! num_set) if (! num_set)
if (! num_set && fnum >= 0 && fnum < FD_SETSIZE) if (! num_set && fnum >= 0 && fnum < FD_SETSIZE)
{ {
fd_set rd; fd_set rd;
FD_ZERO (&rd); FD_ZERO (&rd);
FD_SET (fnum, &rd); FD_SET (fnum, &rd);
struct timeval tv; struct timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
r = _Jv_select (fnum + 1, &rd, NULL, NULL, &tv); r = _Jv_select (fnum + 1, &rd, NULL, NULL, &tv);
if(r == -1) if(r == -1)
goto posix_error; goto posix_error;
num = r == 0 ? 0 : 1; num = r == 0 ? 0 : 1;
} }
#endif /* HAVE_SELECT */ #endif /* HAVE_SELECT */
return (jint) num; return (jint) num;
#else #else
throw new java::io::IOException (JvNewStringUTF ("unimplemented")); throw new java::io::IOException (JvNewStringUTF ("unimplemented"));
#endif #endif
} }
void void
java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value) java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
...@@ -764,10 +787,10 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value) ...@@ -764,10 +787,10 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
val = 1; val = 1;
else else
{ {
if (optID == _Jv_SO_LINGER_) if (optID == _Jv_SO_LINGER_)
val = -1; val = -1;
else else
val = 0; val = 0;
} }
} }
else if (_Jv_IsInstanceOf (value, &java::lang::Integer::class$)) else if (_Jv_IsInstanceOf (value, &java::lang::Integer::class$))
...@@ -787,28 +810,28 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value) ...@@ -787,28 +810,28 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
case _Jv_TCP_NODELAY_ : case _Jv_TCP_NODELAY_ :
#ifdef TCP_NODELAY #ifdef TCP_NODELAY
if (::setsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val, if (::setsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
val_len) != 0) val_len) != 0)
goto error; goto error;
#else #else
throw new java::lang::InternalError ( throw new java::lang::InternalError
JvNewStringUTF ("TCP_NODELAY not supported")); (JvNewStringUTF ("TCP_NODELAY not supported"));
#endif /* TCP_NODELAY */ #endif /* TCP_NODELAY */
return; return;
case _Jv_SO_KEEPALIVE_ : case _Jv_SO_KEEPALIVE_ :
if (::setsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val, if (::setsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
val_len) != 0) val_len) != 0)
goto error; goto error;
break; break;
case _Jv_SO_BROADCAST_ : case _Jv_SO_BROADCAST_ :
throw new java::net::SocketException ( throw new java::net::SocketException
JvNewStringUTF ("SO_BROADCAST not valid for TCP")); (JvNewStringUTF ("SO_BROADCAST not valid for TCP"));
break; break;
case _Jv_SO_OOBINLINE_ : case _Jv_SO_OOBINLINE_ :
if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val, if (::setsockopt (fnum, SOL_SOCKET, SO_OOBINLINE, (char *) &val,
val_len) != 0) val_len) != 0)
goto error; goto error;
break; break;
...@@ -817,30 +840,34 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value) ...@@ -817,30 +840,34 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
struct linger l_val; struct linger l_val;
l_val.l_onoff = (val != -1); l_val.l_onoff = (val != -1);
l_val.l_linger = val; l_val.l_linger = val;
if (::setsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val, if (::setsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
sizeof(l_val)) != 0) sizeof(l_val)) != 0)
goto error; goto error;
#else #else
throw new java::lang::InternalError ( throw new java::lang::InternalError (
JvNewStringUTF ("SO_LINGER not supported")); JvNewStringUTF ("SO_LINGER not supported"));
#endif /* SO_LINGER */ #endif /* SO_LINGER */
return; return;
case _Jv_SO_SNDBUF_ : case _Jv_SO_SNDBUF_ :
case _Jv_SO_RCVBUF_ : case _Jv_SO_RCVBUF_ :
#if defined(SO_SNDBUF) && defined(SO_RCVBUF) #if defined(SO_SNDBUF) && defined(SO_RCVBUF)
int opt; int opt;
optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF; optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0) if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
goto error; goto error;
#else #else
throw new java::lang::InternalError ( throw new java::lang::InternalError (
JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported")); JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
#endif #endif
return; return;
case _Jv_SO_BINDADDR_ : case _Jv_SO_BINDADDR_ :
throw new java::net::SocketException ( throw new java::net::SocketException (
JvNewStringUTF ("SO_BINDADDR: read only option")); JvNewStringUTF ("SO_BINDADDR: read only option"));
return; return;
case _Jv_IP_MULTICAST_IF_ : case _Jv_IP_MULTICAST_IF_ :
throw new java::net::SocketException ( throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP")); JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
...@@ -854,21 +881,23 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value) ...@@ -854,21 +881,23 @@ java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
case _Jv_IP_MULTICAST_LOOP_ : case _Jv_IP_MULTICAST_LOOP_ :
throw new java::net::SocketException ( throw new java::net::SocketException (
JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP")); JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
break; break;
case _Jv_IP_TOS_ : case _Jv_IP_TOS_ :
if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val, if (::setsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
val_len) != 0) val_len) != 0)
goto error; goto error;
break; break;
case _Jv_SO_REUSEADDR_ : case _Jv_SO_REUSEADDR_ :
throw new java::net::SocketException ( throw new java::net::SocketException (
JvNewStringUTF ("SO_REUSEADDR: not valid for TCP")); JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
return; return;
case _Jv_SO_TIMEOUT_ : case _Jv_SO_TIMEOUT_ :
timeout = val; timeout = val;
return; return;
default : default :
errno = ENOPROTOOPT; errno = ENOPROTOOPT;
} }
...@@ -891,123 +920,129 @@ java::net::PlainSocketImpl::getOption (jint optID) ...@@ -891,123 +920,129 @@ java::net::PlainSocketImpl::getOption (jint optID)
switch (optID) switch (optID)
{ {
#ifdef TCP_NODELAY #ifdef TCP_NODELAY
case _Jv_TCP_NODELAY_ : case _Jv_TCP_NODELAY_ :
if (::getsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val, if (::getsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
&val_len) != 0) &val_len) != 0)
goto error; goto error;
else else
return new java::lang::Boolean (val != 0); return new java::lang::Boolean (val != 0);
#else #else
throw new java::lang::InternalError ( throw new java::lang::InternalError
JvNewStringUTF ("TCP_NODELAY not supported")); (JvNewStringUTF ("TCP_NODELAY not supported"));
#endif #endif
break; break;
case _Jv_SO_LINGER_ : case _Jv_SO_LINGER_ :
#ifdef SO_LINGER #ifdef SO_LINGER
if (::getsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val, if (::getsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
&l_val_len) != 0) &l_val_len) != 0)
goto error; goto error;
if (l_val.l_onoff)
return new java::lang::Integer (l_val.l_linger); if (l_val.l_onoff)
else return new java::lang::Integer (l_val.l_linger);
return new java::lang::Boolean ((jboolean)false); else
return new java::lang::Boolean ((jboolean)false);
#else #else
throw new java::lang::InternalError ( throw new java::lang::InternalError
JvNewStringUTF ("SO_LINGER not supported")); (JvNewStringUTF ("SO_LINGER not supported"));
#endif #endif
break; break;
case _Jv_SO_KEEPALIVE_ : case _Jv_SO_KEEPALIVE_ :
if (::getsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val, if (::getsockopt (fnum, SOL_SOCKET, SO_KEEPALIVE, (char *) &val,
&val_len) != 0) &val_len) != 0)
goto error; goto error;
else else
return new java::lang::Boolean (val != 0); return new java::lang::Boolean (val != 0);
case _Jv_SO_BROADCAST_ : case _Jv_SO_BROADCAST_ :
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 ((jboolean)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 ((jboolean)val); return new java::lang::Boolean ((jboolean)val);
case _Jv_SO_RCVBUF_ : case _Jv_SO_RCVBUF_ :
case _Jv_SO_SNDBUF_ : case _Jv_SO_SNDBUF_ :
#if defined(SO_SNDBUF) && defined(SO_RCVBUF) #if defined(SO_SNDBUF) && defined(SO_RCVBUF)
int opt; int opt;
optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF; optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0) if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
goto error; goto error;
else else
return new java::lang::Integer (val); return new java::lang::Integer (val);
#else #else
throw new java::lang::InternalError ( throw new java::lang::InternalError
JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported")); (JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported"));
#endif #endif
break; break;
case _Jv_SO_BINDADDR_: case _Jv_SO_BINDADDR_:
// cache the local address // cache the local address
if (localAddress == NULL) if (localAddress == NULL)
{ {
jbyteArray laddr; jbyteArray laddr;
if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
goto error; if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
if (u.address.sin_family == AF_INET) goto error;
{
laddr = JvNewByteArray (4); if (u.address.sin_family == AF_INET)
memcpy (elements (laddr), &u.address.sin_addr, 4); {
} laddr = JvNewByteArray (4);
memcpy (elements (laddr), &u.address.sin_addr, 4);
}
#ifdef HAVE_INET6 #ifdef HAVE_INET6
else if (u.address.sin_family == AF_INET6) else if (u.address.sin_family == AF_INET6)
{ {
laddr = JvNewByteArray (16); laddr = JvNewByteArray (16);
memcpy (elements (laddr), &u.address6.sin6_addr, 16); memcpy (elements (laddr), &u.address6.sin6_addr, 16);
} }
#endif #endif
else else
throw new java::net::SocketException ( throw new java::net::SocketException
JvNewStringUTF ("invalid family")); (JvNewStringUTF ("invalid family"));
localAddress = new java::net::InetAddress (laddr, NULL); localAddress = new java::net::InetAddress (laddr, NULL);
} }
return localAddress;
break; return localAddress;
case _Jv_IP_MULTICAST_IF_ : break;
throw new java::net::SocketException ( case _Jv_IP_MULTICAST_IF_ :
JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP")); throw new java::net::SocketException
break; (JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP"));
break;
case _Jv_IP_MULTICAST_IF2_ : case _Jv_IP_MULTICAST_IF2_ :
throw new java::net::SocketException ( throw new java::net::SocketException
JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP")); (JvNewStringUTF ("IP_MULTICAST_IF2: not valid for TCP"));
break; break;
case _Jv_IP_MULTICAST_LOOP_ : case _Jv_IP_MULTICAST_LOOP_ :
throw new java::net::SocketException( throw new java::net::SocketException
JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP")); (JvNewStringUTF ("IP_MULTICAST_LOOP: not valid for TCP"));
break; break;
case _Jv_IP_TOS_ : case _Jv_IP_TOS_ :
if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val, if (::getsockopt (fnum, SOL_SOCKET, IP_TOS, (char *) &val,
&val_len) != 0) &val_len) != 0)
goto error; goto error;
return new java::lang::Integer (val); return new java::lang::Integer (val);
break; break;
case _Jv_SO_REUSEADDR_ : case _Jv_SO_REUSEADDR_ :
throw new java::net::SocketException ( throw new java::net::SocketException
JvNewStringUTF ("SO_REUSEADDR: not valid for TCP")); (JvNewStringUTF ("SO_REUSEADDR: not valid for TCP"));
break; break;
case _Jv_SO_TIMEOUT_ :
return new java::lang::Integer (timeout); case _Jv_SO_TIMEOUT_ :
break; return new java::lang::Integer (timeout);
default : break;
errno = ENOPROTOOPT;
default :
errno = ENOPROTOOPT;
} }
error: error:
......
/* ReadOnlyBufferException.java --
Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.nio;
/**
* @author Michael Koch
* @since 1.4
*/
public class ReadOnlyBufferException extends UnsupportedOperationException
{
/**
* Creates the exception
*/
public ReadOnlyBufferException ()
{
}
}
...@@ -39,6 +39,10 @@ package java.nio.channels; ...@@ -39,6 +39,10 @@ package java.nio.channels;
import java.io.IOException; import java.io.IOException;
/**
* @author Michael Koch
* @since 1.4
*/
public class ClosedChannelException extends IOException public class ClosedChannelException extends IOException
{ {
/** /**
......
/* ClosedSelectorException.java --
Copyright (C) 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.nio.channels;
/**
* @author Michael Koch
* @since 1.4
*/
public class ClosedSelectorException extends IllegalStateException
{
/**
* Creates the exception
*/
public ClosedSelectorException()
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment