+1999-06-17 Bryce McKinlay <bryce@albatross.co.nz>
+
+ * java/net/natPlainSocketImpl.cc (bind): Bind to any/all network
+ interfaces if host==NULL.
+ (accept): Throw message with InterruptedIOException.
+ (getOption): Cache localAddress.
+ * java/net/natPlainDatagramSocketImpl.cc (bind): Don't need
+ 'address' for DatagramSocket.
+ (setTimeToLive): Fix compiler warnings.
+ (getOption): Cache localAddress.
+ * java/net/Socket.java (getLocalAddress): Don't need local
+ InetAddress object. Add FIXME comment about calling checkConnect().
+ * java/net/ServerSocket.java (ServerSocket(int)): Initialize
+ connection queue to 50 as per JDK 1.2 docs.
+ (ServerSocket(int,int)): Listen on all network interfaces by
+ default, per JDK 1.2 docs.
+ * java/net/PlainDatagramSocketImpl.java: Don't need 'address'.
+ Add localAddress caching.
+
1999-06-15 Bryce McKinlay <bryce@albatross.co.nz>
* java/io/FilterOutputStream.java (write(byte[])): Rewrite according
1999-05-30 Anthony Green <green@cygnus.com>
* java/net/URLStreamHandler.java (parseURL): Parse relative URLs
- correctly. Clean up "/../" and "/./" path fragments.
+ correctly. Clean up "/../" an\e[Bd "/./" path fragments.
1999-05-28 Warren Levy <warrenl@cygnus.com>
int fnum = -1;
// FIXME: Is this necessary? Could it help w/ DatagramSocket.getLocalAddress?
- InetAddress address;
+ // InetAddress address;
+
+ // localAddress cache
+ InetAddress localAddress;
// These values are set/read by setOption/getOption.
int timeout = 0;
- InetAddress iface = null;
+ /* InetAddress iface = null; */
int ttl = -1;
// FIXME: Probably should have bind (and create?) calls from DatagramSocket
// This value is set/read by setOption/getOption.
int timeout = 0;
+
+ // localAddress cache
+ InetAddress localAddress;
public native void setOption(int optID, Object value) throws SocketException;
public ServerSocket (int port)
throws java.io.IOException
{
- // FIXME: JCL p. 1526 says backlog defaults to 50; is 5 to save space
- // or a typo?
- this(port, 5);
+ this(port, 50);
}
public ServerSocket (int port, int backlog)
throws java.io.IOException
{
- this(port, backlog, InetAddress.getLocalHost());
+ this(port, backlog, null);
}
public ServerSocket (int port, int backlog, InetAddress bindAddr)
public InetAddress getLocalAddress ()
{
- InetAddress localAddress;
+ // FIXME: see note in DatagramSocket.java about checkConnect() and security
try
{
- localAddress = (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR);
+ return (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR);
}
catch (SocketException x)
{
System.err.println(x);
throw new java.lang.InternalError("Error in PlainSocketImpl.getOption");
}
- return localAddress;
}
public int getPort ()
goto error;
if (::bind (fnum, ptr, len) == 0)
{
- // FIXME: Is address really necessary to set?
- address = host;
socklen_t addrlen = sizeof(u);
if (lport != 0)
localport = lport;
void
java::net::PlainDatagramSocketImpl::setTimeToLive (jint ttl)
{
+ this->ttl = ttl;
// throws IOException;
// FIXME: TODO - PlainDatagramSocketImpl::setTimeToLive
}
{
// throws IOException;
// FIXME: TODO - PlainDatagramSocketImpl::getTimeToLive
- return 0;
+ return ttl;
}
void
#endif
break;
case _Jv_SO_BINDADDR_:
- // FIXME: Should cache the laddr as an optimization.
- jbyteArray laddr;
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
- goto error;
- if (u.address.sin_family == AF_INET)
- {
- laddr = JvNewByteArray (4);
- memcpy (elements (laddr), &u.address.sin_addr, 4);
- }
+ // cache the local address
+ if (localAddress == NULL)
+ {
+ jbyteArray laddr;
+ if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
+ goto error;
+ if (u.address.sin_family == AF_INET)
+ {
+ laddr = JvNewByteArray (4);
+ memcpy (elements (laddr), &u.address.sin_addr, 4);
+ }
#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- laddr = JvNewByteArray (16);
- memcpy (elements (laddr), &u.address6.sin6_addr, 16);
- }
+ else if (u.address.sin_family == AF_INET6)
+ {
+ laddr = JvNewByteArray (16);
+ memcpy (elements (laddr), &u.address6.sin6_addr, 16);
+ }
#endif
- else
- goto error;
- return new java::net::InetAddress (laddr, NULL);
+ else
+ goto error;
+ localAddress = new java::net::InetAddress (laddr, NULL);
+ }
+ return localAddress;
break;
case _Jv_SO_REUSEADDR_ :
#if defined(SO_REUSEADDR)
java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
{
union SockAddr u;
- jbyteArray haddress = host->address;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
struct sockaddr *ptr = (struct sockaddr *) &u.address;
+ jbyte *bytes = NULL;
+ // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
+ int len = 4; // Initialize for INADDR_ANY in case host is NULL.
+
+ if (host != NULL)
+ {
+ jbyteArray haddress = host->address;
+ bytes = elements (haddress);
+ len = haddress->length;
+ }
+
if (len == 4)
{
u.address.sin_family = AF_INET;
- memcpy (&u.address.sin_addr, bytes, len);
+ if (host != NULL)
+ memcpy (&u.address.sin_addr, bytes, len);
+ else
+ u.address.sin_addr.s_addr = htonl (INADDR_ANY);
len = sizeof (struct sockaddr_in);
u.address.sin_port = htons (lport);
}
if ((retval = select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
goto error;
else if (retval == 0)
- JvThrow (new java::io::InterruptedIOException ());
+ JvThrow (new java::io::InterruptedIOException (
+ JvNewStringUTF("Accept timed out")));
}
new_socket = ::accept (fnum, (sockaddr*) &u, &addrlen);
#endif
break;
case _Jv_SO_BINDADDR_:
- // FIXME: Should cache the laddr as an optimization.
- jbyteArray laddr;
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
- goto error;
- if (u.address.sin_family == AF_INET)
+ // cache the local address
+ if (localAddress == NULL)
{
- laddr = JvNewByteArray (4);
- memcpy (elements (laddr), &u.address.sin_addr, 4);
- }
+ jbyteArray laddr;
+ if (::getsockname (fnum, (sockaddr*) &u, &addrlen) != 0)
+ goto error;
+ if (u.address.sin_family == AF_INET)
+ {
+ laddr = JvNewByteArray (4);
+ memcpy (elements (laddr), &u.address.sin_addr, 4);
+ }
#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- laddr = JvNewByteArray (16);
- memcpy (elements (laddr), &u.address6.sin6_addr, 16);
- }
+ else if (u.address.sin_family == AF_INET6)
+ {
+ laddr = JvNewByteArray (16);
+ memcpy (elements (laddr), &u.address6.sin6_addr, 16);
+ }
#endif
- else
- goto error;
- return new java::net::InetAddress (laddr, NULL);
+ else
+ goto error;
+ localAddress = new java::net::InetAddress (laddr, NULL);
+ }
+ return localAddress;
break;
case _Jv_IP_MULTICAST_IF_ :
JvThrow (new java::net::SocketException (