aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/net
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java/net')
-rw-r--r--libjava/java/net/BindException.java35
-rw-r--r--libjava/java/net/ConnectException.java35
-rw-r--r--libjava/java/net/ContentHandler.java29
-rw-r--r--libjava/java/net/ContentHandlerFactory.java27
-rw-r--r--libjava/java/net/DatagramPacket.java175
-rw-r--r--libjava/java/net/DatagramSocket.java202
-rw-r--r--libjava/java/net/DatagramSocketImpl.java62
-rw-r--r--libjava/java/net/FileNameMap.java27
-rw-r--r--libjava/java/net/HttpURLConnection.java174
-rw-r--r--libjava/java/net/InetAddress.java256
-rw-r--r--libjava/java/net/JarURLConnection.java301
-rw-r--r--libjava/java/net/MalformedURLException.java35
-rw-r--r--libjava/java/net/MulticastSocket.java134
-rw-r--r--libjava/java/net/NoRouteToHostException.java35
-rw-r--r--libjava/java/net/PlainDatagramSocketImpl.java112
-rw-r--r--libjava/java/net/PlainSocketImpl.java97
-rw-r--r--libjava/java/net/ProtocolException.java35
-rw-r--r--libjava/java/net/ServerSocket.java114
-rw-r--r--libjava/java/net/Socket.java263
-rw-r--r--libjava/java/net/SocketException.java33
-rw-r--r--libjava/java/net/SocketImpl.java76
-rw-r--r--libjava/java/net/SocketImplFactory.java25
-rw-r--r--libjava/java/net/SocketOptions.java40
-rw-r--r--libjava/java/net/URL.java373
-rw-r--r--libjava/java/net/URLClassLoader.java221
-rw-r--r--libjava/java/net/URLConnection.java454
-rw-r--r--libjava/java/net/URLDecoder.java48
-rw-r--r--libjava/java/net/URLEncoder.java71
-rw-r--r--libjava/java/net/URLStreamHandler.java156
-rw-r--r--libjava/java/net/URLStreamHandlerFactory.java27
-rw-r--r--libjava/java/net/UnknownHostException.java34
-rw-r--r--libjava/java/net/UnknownServiceException.java35
-rw-r--r--libjava/java/net/natInetAddress.cc339
-rw-r--r--libjava/java/net/natPlainDatagramSocketImpl.cc632
-rw-r--r--libjava/java/net/natPlainSocketImpl.cc477
35 files changed, 0 insertions, 5189 deletions
diff --git a/libjava/java/net/BindException.java b/libjava/java/net/BindException.java
deleted file mode 100644
index 3e3255c7e1f..00000000000
--- a/libjava/java/net/BindException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// BindException.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class BindException extends SocketException
-{
- public BindException()
- {
- super();
- }
-
- public BindException(String msg)
- {
- super(msg);
- }
-}
diff --git a/libjava/java/net/ConnectException.java b/libjava/java/net/ConnectException.java
deleted file mode 100644
index 449056fc791..00000000000
--- a/libjava/java/net/ConnectException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// ConnectException.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class ConnectException extends SocketException
-{
- public ConnectException()
- {
- super();
- }
-
- public ConnectException(String msg)
- {
- super(msg);
- }
-}
diff --git a/libjava/java/net/ContentHandler.java b/libjava/java/net/ContentHandler.java
deleted file mode 100644
index 59bdb1e6370..00000000000
--- a/libjava/java/net/ContentHandler.java
+++ /dev/null
@@ -1,29 +0,0 @@
-// ContentHandler.java - Superclass of classes that read from a URLConnection.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-import java.io.IOException;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public abstract class ContentHandler
-{
- public abstract Object getContent(URLConnection urlc) throws IOException;
-}
diff --git a/libjava/java/net/ContentHandlerFactory.java b/libjava/java/net/ContentHandlerFactory.java
deleted file mode 100644
index d2727611d9c..00000000000
--- a/libjava/java/net/ContentHandlerFactory.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// ContentHandlerFactory.java - Abstract Content Handler factory.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public abstract interface ContentHandlerFactory
-{
- public ContentHandler createContentHandler(String mimetype);
-}
diff --git a/libjava/java/net/DatagramPacket.java b/libjava/java/net/DatagramPacket.java
deleted file mode 100644
index d2abb7fa9a2..00000000000
--- a/libjava/java/net/DatagramPacket.java
+++ /dev/null
@@ -1,175 +0,0 @@
-// DatagramPacket.java - Represents packets in a connectionless protocol.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date April 28, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public final class DatagramPacket
-{
- private byte[] buffer;
- private int offset;
- private int length;
- private InetAddress address;
- private int port;
-
- // JDK1.2
- public DatagramPacket(byte[] buf, int offset, int length)
- {
- // FIXME: We can't currently rely on NullPointerException being
- // thrown when we invoke a method on a null object.
- if (buf == null)
- throw new NullPointerException("Null buffer");
- if (offset < 0)
- throw new IllegalArgumentException("Invalid offset: " + offset);
- if (length < 0)
- throw new IllegalArgumentException("Invalid length: " + length);
- if (offset + length > buf.length)
- throw new IllegalArgumentException("Potential buffer overflow - offset: "
- + offset + " length: " + length);
-
- buffer = buf;
- this.offset = offset;
- this.length = length;
- this.address = null;
- this.port = -1;
- }
-
- public DatagramPacket(byte[] buf, int length)
- {
- this(buf, 0, length);
- }
-
- // JDK1.2
- public DatagramPacket(byte[] buf, int offset, int length,
- InetAddress address, int port)
- {
- // FIXME: We can't currently rely on NullPointerException being
- // thrown when we invoke a method on a null object.
- if (buf == null)
- throw new NullPointerException("Null buffer");
- if (offset < 0)
- throw new IllegalArgumentException("Invalid offset: " + offset);
- if (length < 0)
- throw new IllegalArgumentException("Invalid length: " + length);
- if (offset + length > buf.length)
- throw new IllegalArgumentException("Potential buffer overflow - offset: "
- + offset + " length: " + length);
- if (port < 0 || port > 65535)
- throw new IllegalArgumentException("Invalid port: " + port);
- if (address == null)
- throw new NullPointerException("Null address");
-
- buffer = buf;
- this.offset = offset;
- this.length = length;
- this.address = address;
- this.port = port;
- }
-
- public DatagramPacket(byte[] buf, int length, InetAddress address, int port)
- {
- this(buf, 0, length, address, port);
- }
-
- public synchronized InetAddress getAddress()
- {
- return address;
- }
-
- public synchronized int getPort()
- {
- return port;
- }
-
- public synchronized byte[] getData()
- {
- return buffer;
- }
-
- // JDK1.2
- public synchronized int getOffset()
- {
- return offset;
- }
-
- public synchronized int getLength()
- {
- return length;
- }
-
- public synchronized void setAddress(InetAddress iaddr)
- {
- if (iaddr == null)
- throw new NullPointerException("Null address");
-
- address = iaddr;
- }
-
- public synchronized void setPort(int iport)
- {
- if (iport < 0 || iport > 65535)
- throw new IllegalArgumentException("Invalid port: " + iport);
-
- port = iport;
- }
-
- public synchronized void setData(byte[] buf)
- {
- // This form of setData requires setLength to be called separately
- // and subsequently.
- if (buf == null)
- throw new NullPointerException("Null buffer");
-
- buffer = buf;
- }
-
- // JDK1.2
- public synchronized void setData(byte[] buf, int offset, int length)
- {
- // This form of setData must be used if offset is to be changed.
-
- // FIXME: We can't currently rely on NullPointerException being
- // thrown when we invoke a method on a null object.
- if (buf == null)
- throw new NullPointerException("Null buffer");
- if (offset < 0)
- throw new IllegalArgumentException("Invalid offset: " + offset);
- if (length < 0)
- throw new IllegalArgumentException("Invalid length: " + length);
- if (offset + length > buf.length)
- throw new IllegalArgumentException("Potential buffer overflow - offset: "
- + offset + " length: " + length);
-
- buffer = buf;
- this.offset = offset;
- this.length = length;
- }
-
- public synchronized void setLength(int length)
- {
- if (length < 0)
- throw new IllegalArgumentException("Invalid length: " + length);
- if (offset + length > buffer.length)
- throw new IllegalArgumentException("Potential buffer overflow - offset: "
- + offset + " length: " + length);
-
- this.length = length;
- }
-}
diff --git a/libjava/java/net/DatagramSocket.java b/libjava/java/net/DatagramSocket.java
deleted file mode 100644
index 334e003f71f..00000000000
--- a/libjava/java/net/DatagramSocket.java
+++ /dev/null
@@ -1,202 +0,0 @@
-// DatagramSocket.java
-
-/* Copyright (C) 1999, 2000 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-import java.io.IOException;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date May 3, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class DatagramSocket
-{
- DatagramSocketImpl impl;
-
- public DatagramSocket() throws SocketException
- {
- this(0, ServerSocket.ANY_IF);
- }
-
- public DatagramSocket(int port) throws SocketException
- {
- this(port, ServerSocket.ANY_IF);
- }
-
- public DatagramSocket(int port, InetAddress laddr) throws SocketException
- {
- if (port < 0 || port > 65535)
- throw new IllegalArgumentException("Invalid port: " + port);
-
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkListen(port);
-
- String propVal = System.getProperty("impl.prefix");
- if (propVal == null || propVal.equals(""))
- impl = new PlainDatagramSocketImpl();
- else
- try
- {
- impl = (DatagramSocketImpl) Class.forName("java.net." + propVal +
- "DatagramSocketImpl").newInstance();
- }
- catch (Exception e)
- {
- System.err.println("Could not instantiate class: java.net." +
- propVal + "DatagramSocketImpl");
- impl = new PlainDatagramSocketImpl();
- }
- impl.create();
-
- // For multicasting, set the socket to be reused (Stevens pp. 195-6).
- if (this instanceof MulticastSocket)
- impl.setOption(SocketOptions.SO_REUSEADDR, new Boolean(true));
-
- impl.bind(port, laddr == null ? ServerSocket.ANY_IF : laddr);
- }
-
- public void close()
- {
- impl.close();
- }
-
- public InetAddress getLocalAddress()
- {
- SecurityManager s = System.getSecurityManager();
- // FIXME: JCL p. 510 says this should call checkConnect. But what
- // string should be used as the hostname? Maybe this is just a side
- // effect of calling InetAddress.getLocalHost.
- //
- // And is getOption with SO_BINDADDR the right way to get the address?
- // Doesn't seem to be since this method doesn't throw a SocketException
- // and SO_BINADDR can throw one.
- //
- // Also see RETURNS section in JCL p. 510 about returning any local
- // addr "if the current execution context is not allowed to connect to
- // the network interface that is actually bound to this datagram socket."
- // How is that done? via InetAddress.getLocalHost? But that throws
- // an UnknownHostException and this method doesn't.
- //
- // if (s != null)
- // s.checkConnect("localhost", -1);
- try
- {
- return (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR);
- }
- catch (SocketException ex)
- {
- }
-
- try
- {
- return InetAddress.getLocalHost();
- }
- catch (UnknownHostException ex)
- {
- // FIXME: This should never happen, so how can we avoid this construct?
- return null;
- }
- }
-
- public int getLocalPort()
- {
- return impl.getLocalPort();
- }
-
- public synchronized int getSoTimeout() throws SocketException
- {
- Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
- if (timeout instanceof Integer)
- return ((Integer)timeout).intValue();
- else
- return 0;
- }
-
- public synchronized void receive(DatagramPacket p) throws IOException
- {
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkAccept(p.getAddress().getHostAddress(), p.getPort());
-
- impl.receive(p);
- }
-
- public void send(DatagramPacket p) throws IOException
- {
- // JDK1.2: Don't do security checks if socket is connected; see jdk1.2 api.
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- {
- InetAddress addr = p.getAddress();
- if (addr.isMulticastAddress())
- s.checkMulticast(addr);
- else
- s.checkConnect(addr.getHostAddress(), p.getPort());
- }
-
- // FIXME: if this is a subclass of MulticastSocket, use getTTL for TTL val.
- impl.send(p);
- }
-
- public synchronized void setSoTimeout(int timeout) throws SocketException
- {
- if (timeout < 0)
- throw new IllegalArgumentException("Invalid timeout: " + timeout);
-
- impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
- }
-
- // JDK1.2
- // public void connect(InetAddress address, int port)
- // {
- // }
-
- // JDK1.2
- // public void disconnect()
- // {
- // }
-
- // JDK1.2
- // public InetAddress getInetAddress()
- // {
- // }
-
- // JDK1.2
- // public int getPort()
- // {
- // }
-
- // JDK1.2
- // public int getReceiveBufferSize() throws SocketException
- // {
- // }
-
- // JDK1.2
- // public int getSendBufferSize() throws SocketException
- // {
- // }
-
- // JDK1.2
- // public void setReceiveBufferSize(int size) throws SocketException
- // {
- // }
-
- // JDK1.2
- // public void setSendBufferSize(int size) throws SocketException
- // {
- // }
-}
diff --git a/libjava/java/net/DatagramSocketImpl.java b/libjava/java/net/DatagramSocketImpl.java
deleted file mode 100644
index 0d1cab7904e..00000000000
--- a/libjava/java/net/DatagramSocketImpl.java
+++ /dev/null
@@ -1,62 +0,0 @@
-// DatagramSocketImpl.java - Abstract datagram socket implementation.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-import java.io.IOException;
-import java.io.FileDescriptor;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date May 3, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public abstract class DatagramSocketImpl implements SocketOptions
-{
- protected int localPort;
- protected FileDescriptor fd;
-
- public DatagramSocketImpl()
- {
- }
-
- protected abstract void bind(int lport, InetAddress laddr)
- throws SocketException;
- protected abstract void close();
- protected abstract void create() throws SocketException;
- protected abstract int peek(InetAddress i) throws IOException;
- protected abstract void send(DatagramPacket p) throws IOException;
- protected abstract void receive(DatagramPacket p) throws IOException;
- protected abstract void setTTL(byte ttl) throws IOException;
- protected abstract byte getTTL() throws IOException;
- protected abstract void setTimeToLive(int ttl) throws IOException;
- protected abstract int getTimeToLive() throws IOException;
- protected abstract void join(InetAddress inetaddr) throws IOException;
- protected abstract void leave(InetAddress inetaddr) throws IOException;
-
- public abstract Object getOption(int optID) throws SocketException;
- public abstract void setOption(int optID, Object value)
- throws SocketException;
-
- protected FileDescriptor getFileDescriptor()
- {
- return fd;
- }
-
- protected int getLocalPort()
- {
- return localPort;
- }
-}
diff --git a/libjava/java/net/FileNameMap.java b/libjava/java/net/FileNameMap.java
deleted file mode 100644
index cc70aa221da..00000000000
--- a/libjava/java/net/FileNameMap.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// FileNameMap.java - Abstract interface to map from a File Name to MIME type.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public abstract interface FileNameMap
-{
- public String getContentTypeFor(String fileName);
-}
diff --git a/libjava/java/net/HttpURLConnection.java b/libjava/java/net/HttpURLConnection.java
deleted file mode 100644
index 673cc8aa2b0..00000000000
--- a/libjava/java/net/HttpURLConnection.java
+++ /dev/null
@@ -1,174 +0,0 @@
-// HttpURLConnection.java - Subclass of communications links using
-// Hypertext Transfer Protocol.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-import java.io.*;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 29, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public abstract class HttpURLConnection extends URLConnection
-{
- /* HTTP Success Response Codes */
- public static final int HTTP_OK = 200;
- public static final int HTTP_CREATED = 201;
- public static final int HTTP_ACCEPTED = 202;
- public static final int HTTP_NOT_AUTHORITATIVE = 203;
- public static final int HTTP_NO_CONTENT = 204;
- public static final int HTTP_RESET = 205;
- public static final int HTTP_PARTIAL = 206;
-
- /* HTTP Redirection Response Codes */
- public static final int HTTP_MULT_CHOICE = 300;
- public static final int HTTP_MOVED_PERM = 301;
- public static final int HTTP_MOVED_TEMP = 302;
- public static final int HTTP_SEE_OTHER = 303;
- public static final int HTTP_NOT_MODIFIED = 304;
- public static final int HTTP_USE_PROXY = 305;
-
- /* HTTP Client Error Response Codes */
- public static final int HTTP_BAD_REQUEST = 400;
- public static final int HTTP_UNAUTHORIZED = 401;
- public static final int HTTP_PAYMENT_REQUIRED = 402;
- public static final int HTTP_FORBIDDEN = 403;
- public static final int HTTP_NOT_FOUND = 404;
- public static final int HTTP_BAD_METHOD = 405;
- public static final int HTTP_NOT_ACCEPTABLE = 406;
- public static final int HTTP_PROXY_AUTH = 407;
- public static final int HTTP_CLIENT_TIMEOUT = 408;
- public static final int HTTP_CONFLICT = 409;
- public static final int HTTP_GONE = 410;
- public static final int HTTP_LENGTH_REQUIRED = 411;
- public static final int HTTP_PRECON_FAILED = 412;
- public static final int HTTP_ENTITY_TOO_LARGE = 413;
- public static final int HTTP_REQ_TOO_LONG = 414;
- public static final int HTTP_UNSUPPORTED_TYPE = 415;
-
- /* HTTP Server Error Response Codes */
- public static final int HTTP_SERVER_ERROR = 500;
- public static final int HTTP_INTERNAL_ERROR = 501;
- public static final int HTTP_BAD_GATEWAY = 502;
- public static final int HTTP_UNAVAILABLE = 503;
- public static final int HTTP_GATEWAY_TIMEOUT = 504;
- public static final int HTTP_VERSION = 505;
-
- protected String method = "GET";
- protected int responseCode = -1;
- protected String responseMessage;
-
- static boolean followRedirects = true;
-
- protected HttpURLConnection(URL url)
- {
- super(url);
- }
-
- public abstract void disconnect();
-
- public abstract boolean usingProxy();
-
- public static void setFollowRedirects(boolean set)
- {
- // Throw an exception if an extant security mgr precludes
- // setting the factory.
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkSetFactory();
-
- followRedirects = set;
- }
-
- public static boolean getFollowRedirects()
- {
- return followRedirects;
- }
-
- public void setRequestMethod(String method) throws ProtocolException
- {
- if (connected)
- throw new ProtocolException("Already connected");
-
- if (method.equals("GET") || method.equals("POST") ||
- method.equals("HEAD") || method.equals("OPTIONS") ||
- method.equals("PUT") || method.equals("DELETE") ||
- method.equals("TRACE"))
- this.method = method;
- else
- throw new ProtocolException("Invalid HTTP request method");
- }
-
- public String getRequestMethod()
- {
- return method;
- }
-
- public int getResponseCode() throws IOException
- {
- getResponseVals();
- return responseCode;
- }
-
- public String getResponseMessage() throws IOException
- {
- getResponseVals();
- return responseMessage;
- }
-
- private void getResponseVals() throws IOException
- {
- // Response is the first header received from the connection.
- String respField = getHeaderField(0);
- if (! respField.startsWith("HTTP/"))
- {
- // Set to default values on failure.
- responseCode = -1;
- responseMessage = null;
- return;
- }
-
- int firstSpc, nextSpc;
- firstSpc = respField.indexOf(' ');
- nextSpc = respField.indexOf(' ', firstSpc + 1);
- responseMessage = respField.substring(nextSpc + 1);
- String codeStr = respField.substring(firstSpc + 1, nextSpc);
- try
- {
- responseCode = Integer.parseInt(codeStr);
- }
- catch (NumberFormatException e)
- {
- // Set to default values on failure.
- responseCode = -1;
- responseMessage = null;
- }
- if (responseCode == HTTP_NOT_FOUND)
- throw new FileNotFoundException(url.toString());
- else if (responseCode >= 400)
- throw new IOException(url.toString() + " " + respField);
- }
-
- // TODO12: public Permission getPermission() throws IOException
- // {
- // }
-
- // TODO12: public InputStream getErrorStream()
- // {
- // }
-}
diff --git a/libjava/java/net/InetAddress.java b/libjava/java/net/InetAddress.java
deleted file mode 100644
index 1a1aeced22a..00000000000
--- a/libjava/java/net/InetAddress.java
+++ /dev/null
@@ -1,256 +0,0 @@
-// INetAddress.java -- An Internet Protocol (IP) address.
-
-/* Copyright (C) 1998, 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Per Bothner
- * @date January 6, 1999.
- */
-
-/*
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * (The latter turns out to have some errors ...)
- * Status: Believed complete and correct.
- */
-
-public final class InetAddress
-{
- String hostname;
- byte[] address;
-
- InetAddress (byte[] address, String hostname)
- {
- this.address = address;
- this.hostname = hostname;
- }
-
- public boolean isMulticastAddress ()
- {
- int len = address.length;
- if (len == 4)
- return (address[0] & 0xF0) == 0xE0;
- if (len == 16)
- return address[0] == (byte) 0xFF;
- return false;
- }
-
- public String getHostName ()
- {
- if (hostname == null)
- lookup (null, this, false);
- return hostname;
- }
-
- public byte[] getAddress ()
- {
- // An experiment shows that JDK1.2 returns a different byte array each
- // time. This makes sense, in terms of security.
- return (byte[]) address.clone();
- }
-
- /* Helper function due to a CNI limitation. */
- private static InetAddress[] allocArray (int count)
- {
- return new InetAddress[count];
- }
-
- /* Helper function due to a CNI limitation. */
- private static SecurityException checkConnect (String hostname)
- {
- SecurityManager s = System.getSecurityManager();
- if (s == null)
- return null;
- try
- {
- s.checkConnect(hostname, -1);
- return null;
- }
- catch (SecurityException ex)
- {
- return ex;
- }
- }
-
- public String getHostAddress ()
- {
- StringBuffer sbuf = new StringBuffer(40);
- int len = address.length;
- int i = 0;
- if (len == 16)
- { // An IPv6 address.
- for (; ; i += 2)
- {
- if (i >= 16)
- return sbuf.toString();
- int x = ((address[i] & 0xFF) << 8) | (address[i+1] & 0xFF);
- boolean empty = sbuf.length() == 0;
- if (empty)
- {
- if (i == 10 && x == 0xFFFF)
- { // IPv4-mapped IPv6 address.
- sbuf.append(":FFFF:");
- break; // Continue as IPv4 address;
- }
- else if (i == 12)
- { // IPv4-compatible IPv6 address.
- sbuf.append(':');
- break; // Continue as IPv4 address.
- }
- else if (i > 0)
- sbuf.append("::");
- }
- else
- sbuf.append(':');
- if (x != 0 || i >= 14)
- sbuf.append(Integer.toHexString(x).toUpperCase());
- }
- }
- for ( ; ; )
- {
- sbuf.append(address[i] & 0xFF);
- i++;
- if (i == len)
- break;
- sbuf.append('.');
- }
- return sbuf.toString();
- }
-
- public int hashCode()
- {
- // There hashing algorithm is not specified, but a simple experiment
- // shows that it is equal to the address, as a 32-bit big-endian integer.
- int hash = 0;
- int len = address.length;
- int i = len > 4 ? len - 4 : 0;
- for ( ; i < len; i++)
- hash = (hash << 8) | (address[i] & 0xFF);
- return hash;
- }
-
- public boolean equals (Object obj)
- {
- if (obj == null || ! (obj instanceof InetAddress))
- return false;
- // "The Java Class Libraries" 2nd edition says "If a machine has
- // multiple names instances of InetAddress for different name of
- // that same machine are not equal. This is because they have
- // different host names." This violates the description in the
- // JDK 1.2 API documentation. A little experiementation
- // shows that the latter is correct.
- byte[] addr1 = address;
- byte[] addr2 = ((InetAddress) obj).address;
- if (addr1.length != addr2.length)
- return false;
- for (int i = addr1.length; --i >= 0; )
- if (addr1[i] != addr2[i])
- return false;
- return true;
- }
-
- public String toString()
- {
- return getHostName()+'/'+getHostAddress();
- }
-
- /** If host is a valid numeric IP address, return the numeric address.
- * Otherwise, return null. */
- private static native byte[] aton (String host);
-
- private static native InetAddress[] lookup
- (String hostname, InetAddress addr, boolean all);
-
- public static InetAddress getByName (String host)
- throws UnknownHostException
- {
- if (host == null)
- return getLocalHost();
- byte[] address = aton(host);
- if (address != null)
- return new InetAddress(address, null);
- InetAddress iaddr = new InetAddress(null, host);
- lookup(host, iaddr, false);
- return iaddr;
- }
-
- public static InetAddress[] getAllByName (String host)
- throws UnknownHostException
- {
- byte[] address = aton(host);
- if (address != null)
- {
- InetAddress[] result = new InetAddress[1];
- result[0] = new InetAddress(address, null);
- return result;
- }
- return lookup(host, null, true);
- }
-
- private static final byte[] localhostAddress = { 127, 0, 0, 1 };
-
- private static native String getLocalHostname ();
-
- private static InetAddress localhost = null;
-
- public static InetAddress getLocalHost() throws UnknownHostException
- {
- SecurityManager s = System.getSecurityManager();
- // Experimentation shows that JDK1.2 does cache the result.
- // However, if there is a security manager, and the cached result
- // is other than "localhost", we need to check again.
- if (localhost == null
- || (s != null && localhost.address != localhostAddress))
- getLocalHost(s);
- return localhost;
- }
-
- private static synchronized void getLocalHost(SecurityManager s)
- throws UnknownHostException
- {
- // Check the localhost cache again, now that we've synchronized.
- if (s == null && localhost != null)
- return;
- String hostname = getLocalHostname();
- if (s != null)
- {
- // "The Java Class Libraries" suggests that if the security
- // manager disallows getting the local host name, then
- // we use the loopback host.
- // However, the JDK 1.2 API claims to throw SecurityException,
- // which seems to suggest SecurityException is *not* caught.
- // In this case, experimentation shows that former is correct.
- try
- {
- // This is wrong, if the name returned from getLocalHostname()
- // is not a fully qualified name. FIXME.
- s.checkConnect(hostname, -1);
- }
- catch (SecurityException ex)
- {
- hostname = null;
- }
- }
- if (hostname != null)
- {
- try
- {
- localhost = new InetAddress(null, null);
- lookup(hostname, localhost, false);
- }
- catch (Exception ex)
- {
- }
- }
- if (localhost == null)
- localhost = new InetAddress (localhostAddress, "localhost");
- }
-}
diff --git a/libjava/java/net/JarURLConnection.java b/libjava/java/net/JarURLConnection.java
deleted file mode 100644
index 86a7291ac37..00000000000
--- a/libjava/java/net/JarURLConnection.java
+++ /dev/null
@@ -1,301 +0,0 @@
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-import java.net.*;
-import java.io.*;
-import java.util.jar.*;
-import java.util.zip.*;
-import java.util.Vector;
-import java.util.Hashtable;
-
-/**
- * @author Kresten Krab Thorup <krab@gnu.org>
- * @date Aug 10, 1999.
- */
-
-
-public abstract class JarURLConnection extends URLConnection
-{
- // three different ways to say the same thing
- private final URL jarFileURL;
-
- /** The connection to the jar file itself. A JarURLConnection
- * can represent an entry in a jar file or an entire jar file. In
- * either case this describes just the jar file itself. */
- protected URLConnection jarFileURLConnection;
-
- // If this is a connection to a jar file element this is set, otherwose null.
- private final String element;
-
- // Cached JarURLConnection's
- static Hashtable conn_cache = new Hashtable();
-
- public URL getJarFileURL ()
- {
- return jarFileURL;
- }
-
- public String getEntryName ()
- {
- return element;
- }
-
- public JarURLConnection(URL url)
- throws MalformedURLException
- {
- super(url);
-
- String spec = url.getFile();
- int bang = spec.indexOf ("!/", 0);
- if (bang == -1)
- throw new MalformedURLException (url + ": No `!/' in spec.");
-
- // Extact the url for the jar itself.
- jarFileURL = new URL(spec.substring (0, bang));
-
- // Get the name of the element, if any.
- element = (bang+2==spec.length() ? null : spec.substring (bang+2));
- }
-
- public synchronized void connect() throws IOException
- {
- // Call is ignored if already connected.
- if (connected)
- return;
-
- if (getUseCaches())
- {
- jarFileURLConnection = (URLConnection) conn_cache.get (jarFileURL);
-
- if (jarFileURLConnection == null)
- {
- jarFileURLConnection = jarFileURL.openConnection ();
- jarFileURLConnection.setUseCaches (true);
- jarFileURLConnection.connect ();
- conn_cache.put (jarFileURL, jarFileURLConnection);
- }
- }
- else
- {
- jarFileURLConnection = jarFileURL.openConnection ();
- jarFileURLConnection.connect ();
- }
-
- connected = true;
- }
-
- public InputStream getInputStream() throws IOException
- {
- if (!connected)
- connect();
-
- if (! doInput)
- throw new ProtocolException("Can't open InputStream if doInput is false");
-
- if (element == null)
- {
- // This is a JarURLConnection for the entire jar file.
-
- InputStream jar_is = new BufferedInputStream(jarFileURLConnection.getInputStream ());
- return new JarInputStream(jar_is);
- }
-
- // Reaching this point, we're looking for an element of a jar file.
-
- JarFile jarfile = null;
-
- try
- {
- jarfile = getJarFile ();
- }
- catch (java.io.IOException x)
- {
- /* ignore */
- }
-
- if (jarfile != null)
- {
- // this is the easy way...
- return jarfile.getInputStream (jarfile.getEntry (element));
- }
- else
- {
- // If the jar file is not local, ...
- JarInputStream zis = new JarInputStream(jarFileURLConnection.getInputStream ());
-
- // This is hideous, we're doing a linear search...
- for (ZipEntry ent = zis.getNextEntry ();
- ent != null;
- ent = zis.getNextEntry ())
- {
- if (element.equals (ent.getName ()))
- {
- int size = (int)ent.getSize();
- byte[] data = new byte[size];
- zis.read (data, 0, size);
- return new ByteArrayInputStream (data);
- }
- }
- }
-
- return null;
- }
-
- public JarEntry getJarEntry (String name)
- throws java.io.IOException
- {
- JarFile jarfile = null;
-
- if (! doInput)
- throw new ProtocolException("Can't open JarEntry if doInput is false");
-
- try
- {
- jarfile = getJarFile ();
- }
- catch (java.io.IOException x)
- {
- /* ignore */
- }
-
- if (jarfile == null)
- {
- JarInputStream zis = new JarInputStream(jarFileURLConnection.getInputStream ());
-
- // This is hideous, we're doing a linear search for the thing...
- for (ZipEntry ent = zis.getNextEntry ();
- ent != null;
- ent = zis.getNextEntry ())
- {
- if (element.equals (ent.getName ()))
- {
- return new JarEntry (ent);
- }
- }
- }
-
- else
- {
- return jarfile.getJarEntry (element);
- }
-
- return null;
- }
-
- public abstract JarFile getJarFile() throws java.io.IOException;
-
-
- // Steal and borrow from protocol/file/Connection.java
-
- private Hashtable hdrHash = new Hashtable();
- private Vector hdrVec = new Vector();
- private boolean gotHeaders = false;
-
- // Override default method in URLConnection.
- public String getHeaderField(String name)
- {
- try
- {
- getHeaders();
- }
- catch (IOException x)
- {
- return null;
- }
- return (String) hdrHash.get(name.toLowerCase());
- }
-
- // Override default method in URLConnection.
- public String getHeaderField(int n)
- {
- try
- {
- getHeaders();
- }
- catch (IOException x)
- {
- return null;
- }
- if (n < hdrVec.size())
- return getField((String) hdrVec.elementAt(n));
-
- return null;
- }
-
- // Override default method in URLConnection.
- public String getHeaderFieldKey(int n)
- {
- try
- {
- getHeaders();
- }
- catch (IOException x)
- {
- return null;
- }
- if (n < hdrVec.size())
- return getKey((String) hdrVec.elementAt(n));
-
- return null;
- }
-
- private String getKey(String str)
- {
- if (str == null)
- return null;
- int index = str.indexOf(':');
- if (index >= 0)
- return str.substring(0, index);
- else
- return null;
- }
-
- private String getField(String str)
- {
- if (str == null)
- return null;
- int index = str.indexOf(':');
- if (index >= 0)
- return str.substring(index + 1).trim();
- else
- return str;
- }
-
- private void getHeaders() throws IOException
- {
- if (gotHeaders)
- return;
- gotHeaders = true;
-
- connect();
-
- // Yes, it is overkill to use the hash table and vector here since
- // we're only putting one header in the file, but in case we need
- // to add others later and for consistency, we'll implement it this way.
-
- // Add the only header we know about right now: Content-length.
- long len;
-
- if (element == null)
- len = jarFileURLConnection.getContentLength ();
- else
- len = getJarEntry (element).getSize ();
-
- String line = "Content-length: " + len;
- hdrVec.addElement(line);
-
- // The key will never be null in this scenario since we build up the
- // headers ourselves. If we ever rely on getting a header from somewhere
- // else, then we may have to check if the result of getKey() is null.
- String key = getKey(line);
- hdrHash.put(key.toLowerCase(), Long.toString(len));
- }
-
-}
diff --git a/libjava/java/net/MalformedURLException.java b/libjava/java/net/MalformedURLException.java
deleted file mode 100644
index 5ea6480b780..00000000000
--- a/libjava/java/net/MalformedURLException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// MalformedURLException.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class MalformedURLException extends java.io.IOException
-{
- public MalformedURLException()
- {
- super();
- }
-
- public MalformedURLException(String msg)
- {
- super(msg);
- }
-}
diff --git a/libjava/java/net/MulticastSocket.java b/libjava/java/net/MulticastSocket.java
deleted file mode 100644
index 9da0aac1719..00000000000
--- a/libjava/java/net/MulticastSocket.java
+++ /dev/null
@@ -1,134 +0,0 @@
-// MulticastSocket.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-import java.io.IOException;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date May 18, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class MulticastSocket extends DatagramSocket
-{
- // FIXME: the local addr bound to the multicast socket can be reused;
- // unlike unicast sockets. It binds to any available network interface.
- // See p.1159 JCL book.
-
- public MulticastSocket() throws IOException
- {
- super(0, ServerSocket.ANY_IF);
- }
-
- public MulticastSocket(int port) throws IOException
- {
- super(port, ServerSocket.ANY_IF);
- }
-
- public InetAddress getInterface() throws SocketException
- {
- // FIXME: Is it possible that an InetAddress wasn't returned from getOption?
- return (InetAddress) impl.getOption(SocketOptions.IP_MULTICAST_IF);
- }
-
- // Deprecated in JDK1.2
- public byte getTTL() throws IOException
- {
- // Use getTTL here rather than getTimeToLive in case we're using an impl
- // other than the default PlainDatagramSocketImpl and it doesn't have
- // getTimeToLive yet.
- return impl.getTTL();
- }
-
- // JDK1.2
- public int getTimeToLive() throws IOException
- {
- return impl.getTimeToLive();
- }
-
- public void setInterface(InetAddress inf) throws SocketException
- {
- impl.setOption(SocketOptions.IP_MULTICAST_IF, inf);
- }
-
- // Deprecated in JDK1.2
- public void setTTL(byte ttl) throws IOException
- {
- // Use setTTL here rather than setTimeToLive in case we're using an impl
- // other than the default PlainDatagramSocketImpl and it doesn't have
- // setTimeToLive yet.
- impl.setTTL(ttl);
- }
-
- // JDK1.2
- public void setTimeToLive(int ttl) throws IOException
- {
- if (ttl <= 0 || ttl > 255)
- throw new IllegalArgumentException("Invalid ttl: " + ttl);
-
- impl.setTimeToLive(ttl);
- }
-
- public void joinGroup(InetAddress mcastaddr) throws IOException
- {
- // FIXME: We can't currently rely on NullPointerException being
- // thrown when we invoke a method on a null object.
- if (mcastaddr == null)
- throw new NullPointerException("Null address");
- if (! mcastaddr.isMulticastAddress())
- throw new IOException("Not a Multicast address");
-
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkMulticast(mcastaddr);
-
- impl.join(mcastaddr);
- }
-
- public void leaveGroup(InetAddress mcastaddr) throws IOException
- {
- // FIXME: We can't currently rely on NullPointerException being
- // thrown when we invoke a method on a null object.
- if (mcastaddr == null)
- throw new NullPointerException("Null address");
- if (! mcastaddr.isMulticastAddress())
- throw new IOException("Not a Multicast address");
-
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkMulticast(mcastaddr);
-
- impl.leave(mcastaddr);
- }
-
- public synchronized void send(DatagramPacket p, byte ttl) throws IOException
- {
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- {
- InetAddress addr = p.getAddress();
- if (addr.isMulticastAddress())
- s.checkMulticast(addr, ttl);
- else
- s.checkConnect(addr.getHostAddress(), p.getPort());
- }
-
- int oldttl = impl.getTimeToLive();
- impl.setTimeToLive(((int) ttl) & 0xFF);
- impl.send(p);
- impl.setTimeToLive(oldttl);
- }
-}
diff --git a/libjava/java/net/NoRouteToHostException.java b/libjava/java/net/NoRouteToHostException.java
deleted file mode 100644
index cb1c5f8bad9..00000000000
--- a/libjava/java/net/NoRouteToHostException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// NoRouteToHostException.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class NoRouteToHostException extends SocketException
-{
- public NoRouteToHostException()
- {
- super();
- }
-
- public NoRouteToHostException(String msg)
- {
- super(msg);
- }
-}
diff --git a/libjava/java/net/PlainDatagramSocketImpl.java b/libjava/java/net/PlainDatagramSocketImpl.java
deleted file mode 100644
index 9a290dcd0f8..00000000000
--- a/libjava/java/net/PlainDatagramSocketImpl.java
+++ /dev/null
@@ -1,112 +0,0 @@
-// PlainDatagramSocketImpl.java - Implementation of DatagramSocketImpl.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-import java.io.IOException;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date May 3, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-class PlainDatagramSocketImpl extends DatagramSocketImpl
-{
- // These fields are mirrored for use in native code to avoid cpp conflicts
- // when the #defines in system header files are the same as the public fields.
- 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_LINGER_ = SocketOptions.SO_LINGER,
- _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
- _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
- _Jv_SO_RCVBUF_ = SocketOptions.SO_RCVBUF;
-
- int fnum = -1;
-
- // FIXME: Is this necessary? Could it help w/ DatagramSocket.getLocalAddress?
- // InetAddress address;
-
- // localAddress cache
- InetAddress localAddress;
-
- // 'timeout' is set/read by setOption/getOption.
- int timeout = 0;
-
- // FIXME: Probably should have bind (and create?) calls from DatagramSocket
- // constuctor. If so, then same change should be made to the corresponding
- // Socket (non-datagram) classes. This allows the implementation more
- // complete control over how the socket is set up and used (e.g. connect,
- // setting options, etc.).
- public PlainDatagramSocketImpl()
- {
- }
-
- protected native void bind(int lport, InetAddress laddr)
- throws SocketException;
- protected native void create() throws SocketException;
- protected native int peek(InetAddress i) throws IOException;
- protected native void setTimeToLive(int ttl) throws IOException;
- protected native int getTimeToLive() throws IOException;
- protected native void send(DatagramPacket p) throws IOException;
- 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;
-
- protected void close()
- {
- // FIXME: The close method in each of the DatagramSocket* classes does
- // not throw an IOException. The issue is that FileDescriptor.close()
- // in natFileDescriptorPosix.cc can throw one, so we have to catch
- // it here. It seems that FileDescriptor.close is properly throwing
- // the IOException on errors since many of the java.io classes depend
- // on that. This probably requires a bit more research but for now,
- // we'll catch the IOException here.
- try
- {
- fd.close();
- }
- catch (IOException e)
- {
- System.err.println("PlainDatagramSocketImpl.close: Error closing - " +
- e.getMessage());
- }
- }
-
- // Deprecated in JDK 1.2.
- protected byte getTTL() throws IOException
- {
- return (byte) getTimeToLive();
- }
-
- // Deprecated in JDK 1.2.
- protected void setTTL(byte ttl) throws IOException
- {
- setTimeToLive(((int) ttl) & 0xFF);
- }
-
- protected void join(InetAddress inetaddr) throws IOException
- {
- mcastGrp(inetaddr, true);
- }
-
- protected void leave(InetAddress inetaddr) throws IOException
- {
- mcastGrp(inetaddr, false);
- }
-}
diff --git a/libjava/java/net/PlainSocketImpl.java b/libjava/java/net/PlainSocketImpl.java
deleted file mode 100644
index df9d4387d44..00000000000
--- a/libjava/java/net/PlainSocketImpl.java
+++ /dev/null
@@ -1,97 +0,0 @@
-// PlainSocketImpl.java - Implementation of SocketImpl.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-import java.io.*;
-
-/**
- * @author Per Bothner <bothner@cygnus.com>
- * @date February 22, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-class PlainSocketImpl extends SocketImpl
-{
- // These fields are mirrored for use in native code to avoid cpp conflicts
- // when the #defines in system header files are the same as the public fields.
- 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_LINGER_ = SocketOptions.SO_LINGER,
- _Jv_SO_TIMEOUT_ = SocketOptions.SO_TIMEOUT,
- _Jv_SO_SNDBUF_ = SocketOptions.SO_SNDBUF,
- _Jv_SO_RCVBUF_ = SocketOptions.SO_RCVBUF;
-
- int fnum = -1;
-
- // 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 native Object getOption(int optID) throws SocketException;
-
- protected native void create (boolean stream) throws IOException;
-
- protected void connect (String host, int port) throws IOException
- {
- connect(InetAddress.getByName(host), port);
- }
-
- protected native void connect (InetAddress host, int port)
- throws IOException;
-
- protected native void bind (InetAddress host, int port) throws IOException;
-
- protected native void listen (int backlog) throws IOException;
-
- private native void accept (PlainSocketImpl s) throws IOException;
- protected void accept (SocketImpl s) throws IOException
- {
- accept((PlainSocketImpl) s);
- }
-
- private InputStream in;
- private OutputStream out;
-
- protected InputStream getInputStream() throws IOException
- {
- // FIXME: TODO - Implement class SocketInputStream timeouts in read();
- if (in == null)
- in = new FileInputStream (fd);
- return in;
- }
-
- protected OutputStream getOutputStream() throws IOException
- {
- if (out == null)
- out = new FileOutputStream (fd);
- return out;
- }
-
- protected int available () throws IOException
- {
- return in.available();
- }
-
- protected void close () throws IOException
- {
- fd.close();
- }
-}
diff --git a/libjava/java/net/ProtocolException.java b/libjava/java/net/ProtocolException.java
deleted file mode 100644
index 2263457d805..00000000000
--- a/libjava/java/net/ProtocolException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// ProtocolException.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class ProtocolException extends java.io.IOException
-{
- public ProtocolException()
- {
- super();
- }
-
- public ProtocolException(String msg)
- {
- super(msg);
- }
-}
diff --git a/libjava/java/net/ServerSocket.java b/libjava/java/net/ServerSocket.java
deleted file mode 100644
index bc1b072fa2d..00000000000
--- a/libjava/java/net/ServerSocket.java
+++ /dev/null
@@ -1,114 +0,0 @@
-// ServerSocket.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-/**
- * @author Per Bothner <bothner@cygnus.com>
- * @date January 6, 1999.
- */
-
-/** Written using on-line Java Platform 1.2 API Specification.
- * Status: I believe all methods are implemented.
- */
-
-package java.net;
-import java.io.*;
-
-public class ServerSocket
-{
- static SocketImplFactory factory;
- SocketImpl impl;
-
- static final byte[] zeros = {0,0,0,0};
- /* dummy InetAddress, used to bind socket to any (all) network interfaces */
- static final InetAddress ANY_IF = new InetAddress(zeros, null);
-
- public ServerSocket (int port)
- throws java.io.IOException
- {
- this(port, 50);
- }
-
- public ServerSocket (int port, int backlog)
- throws java.io.IOException
- {
- this(port, backlog, ANY_IF);
- }
-
- public ServerSocket (int port, int backlog, InetAddress bindAddr)
- throws java.io.IOException
- {
- if (factory == null)
- this.impl = new PlainSocketImpl();
- else
- this.impl = factory.createSocketImpl();
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkListen(port);
- impl.create(true);
- impl.bind(bindAddr == null ? ANY_IF : bindAddr, port);
- impl.listen(backlog);
- }
-
- public InetAddress getInetAddress()
- {
- return impl.getInetAddress();
- }
-
- public int getLocalPort()
- {
- return impl.getLocalPort();
- }
-
- public Socket accept () throws IOException
- {
- Socket s = new Socket(Socket.factory == null ? new PlainSocketImpl()
- : Socket.factory.createSocketImpl());
- implAccept (s);
- return s;
- }
-
- protected final void implAccept (Socket s) throws IOException
- {
- impl.accept(s.impl);
- }
-
- public void close () throws IOException
- {
- impl.close();
- }
-
- public synchronized void setSoTimeout (int timeout) throws SocketException
- {
- if (timeout < 0)
- throw new IllegalArgumentException("Invalid timeout: " + timeout);
-
- impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
- }
-
- public synchronized int getSoTimeout () throws SocketException
- {
- Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
- if (timeout instanceof Integer)
- return ((Integer)timeout).intValue();
- else
- return 0;
- }
-
- public String toString ()
- {
- return "ServerSocket" + impl.toString();
- }
-
- public static synchronized void setSocketFactory (SocketImplFactory fac)
- throws IOException
- {
- factory = fac;
- }
-}
diff --git a/libjava/java/net/Socket.java b/libjava/java/net/Socket.java
deleted file mode 100644
index 34ea165e51a..00000000000
--- a/libjava/java/net/Socket.java
+++ /dev/null
@@ -1,263 +0,0 @@
-// Socket.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-/**
- * @author Per Bothner <bothner@cygnus.com>
- * @date January 6, 1999.
- */
-
-/** Written using on-line Java Platform 1.2 API Specification.
- * Status: I believe all methods are implemented.
- */
-
-package java.net;
-import java.io.*;
-
-public class Socket
-{
- static SocketImplFactory factory;
- SocketImpl impl;
-
- protected Socket ()
- {
- }
-
- protected Socket (SocketImpl impl) throws SocketException
- {
- this.impl = impl;
- }
-
- public Socket (String host, int port)
- throws UnknownHostException, IOException
- {
- this(factory == null ? new PlainSocketImpl() : factory.createSocketImpl());
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkConnect(host, port);
- impl.create(true);
- // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
- // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
- // that default. JDK 1.2 doc infers not to do a bind.
- impl.connect(host, port);
- }
-
- public Socket (InetAddress address, int port)
- throws IOException
- {
- this(factory == null ? new PlainSocketImpl() : factory.createSocketImpl());
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkConnect(address.getHostName(), port);
- impl.create(true);
- // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
- // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
- // that default. JDK 1.2 doc infers not to do a bind.
- impl.connect(address, port);
- }
-
- public Socket (String host, int port,
- InetAddress localAddr, int localPort) throws IOException
- {
- this(factory == null ? new PlainSocketImpl() : factory.createSocketImpl());
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkConnect(host, port);
- impl.create(true);
- // FIXME: JCL p. 1587 says if localAddr is null, use getLocalAddress().
- impl.bind(localAddr, localPort);
- impl.connect(host, port);
- }
-
- public Socket (InetAddress address, int port,
- InetAddress localAddr, int localPort) throws IOException
- {
- this(factory == null ? new PlainSocketImpl() : factory.createSocketImpl());
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkConnect(address.getHostName(), port);
- impl.create(true);
- // FIXME: JCL p. 1587 says if localAddr is null, use getLocalAddress().
- impl.bind(localAddr, localPort);
- impl.connect(address, port);
- }
-
- /**
- * @deprecated Use DatagramSocket instead for UDP transport.
- */
- public Socket (String host, int port, boolean stream) throws IOException
- {
- impl = factory == null ? new PlainSocketImpl()
- : factory.createSocketImpl();
- impl.create(stream);
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkConnect(host, port);
- // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
- // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
- // that default. JDK 1.2 doc infers not to do a bind.
- impl.connect(host, port);
- }
-
- /**
- * @deprecated Use DatagramSocket instead for UDP transport.
- */
- public Socket (InetAddress host, int port, boolean stream) throws IOException
- {
- impl = factory == null ? new PlainSocketImpl()
- : factory.createSocketImpl();
- impl.create(stream);
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkConnect(host.getHostName(), port);
- // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
- // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
- // that default. JDK 1.2 doc infers not to do a bind.
- impl.connect(host, port);
- }
-
- public InetAddress getInetAddress ()
- {
- return impl.getInetAddress();
- }
-
- public InetAddress getLocalAddress ()
- {
- // FIXME: see note in DatagramSocket.java about checkConnect() and security
- try
- {
- return (InetAddress)impl.getOption(SocketOptions.SO_BINDADDR);
- }
- catch (SocketException x)
- {
- // (hopefully) shouldn't happen
- System.err.println(x);
- throw new java.lang.InternalError("Error in PlainSocketImpl.getOption");
- }
- }
-
- public int getPort ()
- {
- return impl.getPort();
- }
-
- public int getLocalPort ()
- {
- return impl.getLocalPort();
- }
-
- public InputStream getInputStream () throws IOException
- {
- return impl.getInputStream();
- }
-
- public OutputStream getOutputStream () throws IOException
- {
- return impl.getOutputStream();
- }
-
- public void setTcpNoDelay (boolean on) throws SocketException
- {
- impl.setOption( SocketOptions.TCP_NODELAY, new Boolean(on) );
- }
-
- public boolean getTcpNoDelay() throws SocketException
- {
- Boolean bool = (Boolean)impl.getOption( SocketOptions.TCP_NODELAY );
- return bool.booleanValue();
- }
-
- public void setSoLinger(boolean on, int linger) throws SocketException
- {
- if ( on && (linger >= 0) )
- {
- if (linger > 65535)
- linger = 65535;
- impl.setOption( SocketOptions.SO_LINGER, new Integer(linger) );
- }
- else if ( on && (linger < 0) )
- throw new IllegalArgumentException("SO_LINGER must be >= 0");
- else
- impl.setOption( SocketOptions.SO_LINGER, new Boolean(false) );
- }
-
- public int getSoLinger() throws SocketException
- {
- Object linger = impl.getOption(SocketOptions.SO_LINGER);
- if (linger instanceof Integer)
- return ((Integer)linger).intValue();
- else
- return -1;
- }
-
- public synchronized void setSoTimeout (int timeout) throws SocketException
- {
- if (timeout < 0)
- throw new IllegalArgumentException("Invalid timeout: " + timeout);
-
- impl.setOption(SocketOptions.SO_TIMEOUT, new Integer(timeout));
- }
-
- public synchronized int getSoTimeout () throws SocketException
- {
- Object timeout = impl.getOption(SocketOptions.SO_TIMEOUT);
- if (timeout instanceof Integer)
- return ((Integer)timeout).intValue();
- else
- return 0;
- }
-
- // JDK1.2
- public void setSendBufferSize (int size) throws SocketException
- {
- if (size <= 0)
- throw new IllegalArgumentException("Invalid buffer size: " + size);
-
- impl.setOption(SocketOptions.SO_SNDBUF, new Integer(size));
- }
-
- // JDK1.2
- public int getSendBufferSize () throws SocketException
- {
- Integer buf = (Integer)impl.getOption(SocketOptions.SO_SNDBUF);
- return buf.intValue();
- }
-
- // JDK1.2
- public void setReceiveBufferSize (int size) throws SocketException
- {
- if (size <= 0)
- throw new IllegalArgumentException("Invalid buffer size: " + size);
-
- impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
- }
-
- // JDK1.2
- public int getReceiveBufferSize () throws SocketException
- {
- Integer buf = (Integer)impl.getOption(SocketOptions.SO_RCVBUF);
- return buf.intValue();
- }
-
- public synchronized void close () throws IOException
- {
- impl.close();
- }
-
- public String toString ()
- {
- return "Socket" + impl.toString();
- }
-
- public static synchronized void setSocketImplFactory (SocketImplFactory fac)
- throws IOException
- {
- factory = fac;
- }
-}
diff --git a/libjava/java/net/SocketException.java b/libjava/java/net/SocketException.java
deleted file mode 100644
index 847cdc9048d..00000000000
--- a/libjava/java/net/SocketException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-// SocketException.java - Base class for networking exceptions
-
-/* Copyright (C) 1998, 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Per Bothner
- * @date January 6, 1999.
- */
-
-/** Written using on-line Java Platform 1.2 API Specification.
- * Believed complete and correct.
- */
-
-public class SocketException extends java.io.IOException
-{
- public SocketException ()
- {
- super();
- }
-
- public SocketException (String s)
- {
- super(s);
- }
-}
diff --git a/libjava/java/net/SocketImpl.java b/libjava/java/net/SocketImpl.java
deleted file mode 100644
index d902a30e40a..00000000000
--- a/libjava/java/net/SocketImpl.java
+++ /dev/null
@@ -1,76 +0,0 @@
-// SocketImpl.java - Abstract socket implementation.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-import java.io.*;
-
-/**
- * @author Per Bothner <bothner@cygnus.com>
- * @date January 6, 1999.
- */
-
-/** Written using on-line Java Platform 1.2 API Specification.
- * Believed complete and correct.
- */
-
-public abstract class SocketImpl implements SocketOptions
-{
- protected InetAddress address;
-
- protected FileDescriptor fd;
-
- protected int localport;
-
- protected int port;
-
- public SocketImpl ()
- {
- }
-
- protected abstract void create (boolean stream) throws IOException;
-
- protected abstract void connect (String host, int port) throws IOException;
-
- protected abstract void connect (InetAddress host, int port)
- throws IOException;
-
- protected abstract void bind (InetAddress host, int port) throws IOException;
-
- protected abstract void listen (int backlog) throws IOException;
-
- protected abstract void accept (SocketImpl s) throws IOException;
-
- protected abstract InputStream getInputStream() throws IOException;
-
- protected abstract OutputStream getOutputStream() throws IOException;
-
- protected abstract int available () throws IOException;
-
- protected abstract void close () throws IOException;
-
- protected FileDescriptor getFileDescriptor () { return fd; }
-
- protected InetAddress getInetAddress () { return address; }
-
- protected int getPort () { return port; }
-
- protected int getLocalPort () { return localport; }
-
- public abstract Object getOption(int optID) throws SocketException;
-
- public abstract void setOption(int optID, Object value)
- throws SocketException;
-
- public String toString ()
- {
- return "[addr=" + address.toString() + ",port=" + Integer.toString(port) +
- ",localport=" + Integer.toString(localport) + "]";
- }
-}
diff --git a/libjava/java/net/SocketImplFactory.java b/libjava/java/net/SocketImplFactory.java
deleted file mode 100644
index defce2e02cb..00000000000
--- a/libjava/java/net/SocketImplFactory.java
+++ /dev/null
@@ -1,25 +0,0 @@
-// SocketImplFactory.java - Abstract socket implementation factory.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Per Bothner <bothner@cygnus.com>
- * @date January 6, 1999.
- */
-
-/** Written using on-line Java Platform 1.2 API Specification.
- * Status: Believed complete and correct.
- */
-
-public abstract interface SocketImplFactory
-{
- public SocketImpl createSocketImpl ();
-}
diff --git a/libjava/java/net/SocketOptions.java b/libjava/java/net/SocketOptions.java
deleted file mode 100644
index d0e00d9ec08..00000000000
--- a/libjava/java/net/SocketOptions.java
+++ /dev/null
@@ -1,40 +0,0 @@
-// SocketOptions.java - Interface for get/set socket options.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date May 3, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification.
- * Status: Believed complete and correct.
- */
-
-public abstract interface SocketOptions
-{
- public static final int TCP_NODELAY = 0x1;
- public static final int SO_BINDADDR = 0xF;
- public static final int SO_REUSEADDR = 0x4;
- public static final int IP_MULTICAST_IF = 0x10;
- public static final int SO_LINGER = 0x80;
- public static final int SO_TIMEOUT = 0x1006;
-
- // JDK1.2
- public static final int SO_SNDBUF = 0x1001;
-
- // JDK1.2
- public static final int SO_RCVBUF = 0x1002;
-
- public void setOption(int optID, Object value) throws SocketException;
- public Object getOption(int optID) throws SocketException;
-}
diff --git a/libjava/java/net/URL.java b/libjava/java/net/URL.java
deleted file mode 100644
index f80a52f5878..00000000000
--- a/libjava/java/net/URL.java
+++ /dev/null
@@ -1,373 +0,0 @@
-// URL.java - A Uniform Resource Locator.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-import java.io.*;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 4, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public final class URL implements Serializable
-{
- private String protocol;
- private String host;
- private int port = -1; // Initialize for constructor using context.
- private String file;
- private String ref;
- private URLStreamHandler handler;
- private static Hashtable handlers = new Hashtable();
- private static URLStreamHandlerFactory factory;
-
- public URL(String protocol, String host, int port, String file)
- throws MalformedURLException
- {
- this(protocol, host, port, file, null);
- }
-
- public URL(String protocol, String host, String file)
- throws MalformedURLException
- {
- this(protocol, host, -1, file, null);
- }
-
- // JDK1.2
- public URL(String protocol, String host, int port, String file,
- URLStreamHandler handler) throws MalformedURLException
- {
- if (protocol == null)
- throw new MalformedURLException("null protocol");
- this.protocol = protocol;
-
- if (handler != null)
- {
- // TODO12: Need SecurityManager.checkPermission and
- // TODO12: java.net.NetPermission from JDK 1.2 to be implemented.
- // Throw an exception if an extant security mgr precludes
- // specifying a StreamHandler.
- //
- // SecurityManager s = System.getSecurityManager();
- // if (s != null)
- // s.checkPermission(NetPermission("specifyStreamHandler"));
-
- this.handler = handler;
- }
- else
- this.handler = setURLStreamHandler(protocol);
-
- if (this.handler == null)
- throw new MalformedURLException("Handler for protocol not found");
-
- this.host = host;
-
- this.port = port;
-
- int hashAt = file.indexOf('#');
- if (hashAt < 0)
- {
- this.file = file;
- this.ref = null;
- }
- else
- {
- this.file = file.substring(0, hashAt);
- this.ref = file.substring(hashAt + 1);
- }
- }
-
- public URL(String spec) throws MalformedURLException
- {
- this((URL) null, spec, (URLStreamHandler) null);
- }
-
- public URL(URL context, String spec) throws MalformedURLException
- {
- this(context, spec, (URLStreamHandler) null);
- }
-
- // JDK1.2
- public URL(URL context, String spec, URLStreamHandler handler)
- throws MalformedURLException
- {
- /* A protocol is defined by the doc as the substring before a ':'
- * as long as the ':' occurs before any '/'.
- *
- * If context is null, then spec must be an absolute URL.
- *
- * The relative URL need not specify all the components of a URL.
- * If the protocol, host name, or port number is missing, the value
- * is inherited from the context. A bare file component is appended
- * to the context's file. The optional anchor is not inherited.
- */
-
- // If this is an absolute URL, then ignore context completely.
- // An absolute URL must have chars prior to "://" but cannot have a colon
- // right after the "://". The second colon is for an optional port value
- // and implies that the host from the context is used if available.
- int colon;
- if ((colon = spec.indexOf("://", 1)) > 0 &&
- ! spec.regionMatches(colon, "://:", 0, 4))
- context = null;
-
- int slash;
- if ((colon = spec.indexOf(':')) > 0 &&
- (colon < (slash = spec.indexOf('/')) || slash < 0))
- {
- // Protocol specified in spec string.
- protocol = spec.substring(0, colon);
- if (context != null && context.protocol.equals(protocol))
- {
- // The 1.2 doc specifically says these are copied to the new URL.
- host = context.host;
- port = context.port;
- file = context.file;
- }
- }
- else if (context != null)
- {
- // Protocol NOT specified in spec string.
- // Use context fields (except ref) as a foundation for relative URLs.
- colon = -1;
- protocol = context.protocol;
- host = context.host;
- port = context.port;
- file = context.file;
- }
- else // Protocol NOT specified in spec. and no context available.
- throw new
- MalformedURLException("Absolute URL required with null context");
-
- if (handler != null)
- {
- // TODO12: Need SecurityManager.checkPermission and
- // TODO12: java.net.NetPermission from JDK 1.2 to be implemented.
- // Throw an exception if an extant security mgr precludes
- // specifying a StreamHandler.
- //
- // SecurityManager s = System.getSecurityManager();
- // if (s != null)
- // s.checkPermission(NetPermission("specifyStreamHandler"));
-
- this.handler = handler;
- }
- else
- this.handler = setURLStreamHandler(protocol);
-
- if (this.handler == null)
- throw new MalformedURLException("Handler for protocol not found");
-
- // JDK 1.2 doc for parseURL specifically states that any '#' ref
- // is to be excluded by passing the 'limit' as the indexOf the '#'
- // if one exists, otherwise pass the end of the string.
- int hashAt = spec.indexOf('#', colon + 1);
- this.handler.parseURL(this, spec, colon + 1,
- hashAt < 0 ? spec.length() : hashAt);
- if (hashAt >= 0)
- ref = spec.substring(hashAt + 1);
- }
-
- public boolean equals(Object obj)
- {
- if (obj == null || ! (obj instanceof URL))
- return false;
-
- URL uObj = (URL) obj;
-
- // This comparison is very conservative. It assumes that any
- // field can be null.
- return (port == uObj.port
- && ((protocol == null && uObj.protocol == null)
- || (protocol != null && protocol.equals(uObj.protocol)))
- && ((host == null && uObj.host == null)
- || (host != null && host.equals(uObj.host)))
- && ((file == null && uObj.file == null)
- || (file != null && file.equals(uObj.file)))
- && ((ref == null && uObj.ref == null)
- || (ref != null && ref.equals(uObj.ref))));
- }
-
- public final Object getContent() throws IOException
- {
- return openConnection().getContent();
- }
-
- public String getFile()
- {
- return file;
- }
-
- public String getHost()
- {
- return host;
- }
-
- public int getPort()
- {
- return port;
- }
-
- public String getProtocol()
- {
- return protocol;
- }
-
- public String getRef()
- {
- return ref;
- }
-
- public int hashCode()
- {
- // JCL book says this is computed using (only) the hashcodes of the
- // protocol, host and file fields. Empirical evidence indicates this
- // is probably XOR in JDK 1.1. In JDK 1.2 it seems to be a sum including
- // the port.
- //
- // JDK 1.2 online doc infers that host could be null because it
- // explicitly states that file cannot be null but is silent on host.
- // A simple example with protocol "http" (hashcode 3213448), host null,
- // file "/" (hashcode 47) produced a hashcode (3213494) which appeared
- // to be the sum of the two hashcodes plus the port. Another example
- // using "/index.html" for file bore this out; as well as "#" for file
- // (which was reduced to "" with a hashcode of zero). A "" host also
- // causes the port number and the two hashcodes to be summed.
-
- return (protocol.hashCode() + ((host == null) ? 0 : host.hashCode()) +
- port + file.hashCode());
- }
-
- public URLConnection openConnection() throws IOException
- {
- return handler.openConnection(this);
- }
-
- public final InputStream openStream() throws IOException
- {
- return openConnection().getInputStream();
- }
-
- public boolean sameFile(URL other)
- {
- // This comparison is very conservative. It assumes that any
- // field can be null.
- return (other != null
- && port == other.port
- && ((protocol == null && other.protocol == null)
- || (protocol != null && protocol.equals(other.protocol)))
- && ((host == null && other.host == null)
- || (host != null && host.equals(other.host)))
- && ((file == null && other.file == null)
- || (file != null && file.equals(other.file))));
- }
-
- protected void set(String protocol, String host, int port, String file,
- String ref)
- {
- // TBD: Theoretically, a poorly written StreamHandler could pass an
- // invalid protocol. It will cause the handler to be set to null
- // thus overriding a valid handler. Callers of this method should
- // be aware of this.
- this.handler = setURLStreamHandler(protocol);
- this.protocol = protocol;
- this.port = port;
- this.host = host;
- this.file = file;
- this.ref = ref;
- }
-
- public static synchronized void
- setURLStreamHandlerFactory(URLStreamHandlerFactory fac)
- {
- if (factory != null)
- throw new Error("URLStreamHandlerFactory already set");
-
- // Throw an exception if an extant security mgr precludes
- // setting the factory.
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkSetFactory();
- factory = fac;
- }
-
- public String toExternalForm()
- {
- // Identical to toString().
- return handler.toExternalForm(this);
- }
-
- public String toString()
- {
- // Identical to toExternalForm().
- return handler.toExternalForm(this);
- }
-
- private URLStreamHandler setURLStreamHandler(String protocol)
- {
- URLStreamHandler handler;
-
- // See if a handler has been cached for this protocol.
- if ((handler = (URLStreamHandler) handlers.get(protocol)) != null)
- return handler;
-
- // If a non-default factory has been set, use it to find the protocol.
- if (factory != null)
- handler = factory.createURLStreamHandler(protocol);
-
- // Non-default factory may have returned null or a factory wasn't set.
- // Use the default search algorithm to find a handler for this protocol.
- if (handler == null)
- {
- // Get the list of packages to check and append our default handler
- // to it, along with the JDK specified default as a last resort.
- // Except in very unusual environments the JDK specified one shouldn't
- // ever be needed (or available).
- String propVal = System.getProperty("java.protocol.handler.pkgs");
- propVal = (propVal == null) ? "" : (propVal + "|");
- propVal = propVal + "gnu.gcj.protocol|sun.net.www.protocol";
-
- StringTokenizer pkgPrefix = new StringTokenizer(propVal, "|");
- do
- {
- String facName = pkgPrefix.nextToken() + "." + protocol +
- ".Handler";
- try
- {
- handler =
- (URLStreamHandler) Class.forName(facName).newInstance();
- }
- catch (Exception e)
- {
- // Can't instantiate; handler still null, go on to next element.
- }
- } while ((handler == null ||
- ! (handler instanceof URLStreamHandler)) &&
- pkgPrefix.hasMoreTokens());
- }
-
- // Update the hashtable with the new protocol handler.
- if (handler != null)
- if (handler instanceof URLStreamHandler)
- handlers.put(protocol, handler);
- else
- handler = null;
-
- return handler;
- }
-}
diff --git a/libjava/java/net/URLClassLoader.java b/libjava/java/net/URLClassLoader.java
deleted file mode 100644
index 8e467ad6b80..00000000000
--- a/libjava/java/net/URLClassLoader.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-import java.io.*;
-import java.util.jar.*;
-import java.util.Vector;
-
-public class URLClassLoader extends ClassLoader
-{
- // The URLStreamHandlerFactory
- URLStreamHandlerFactory factory = null;
-
- // `path' contains simply the URL's we're using for the searching.
- private Vector path;
-
- // If path[n] is a zip/jar, then this holds a JarURLConnection for that thing,
- // otherwise, path[n] is null.
- private Vector info;
-
- private URLStreamHandler getHandler0 (String protocol)
- {
- if (factory != null)
- return factory.createURLStreamHandler(protocol);
- else
- return null;
- }
-
- public URLClassLoader (URL[] urls)
- {
- this (urls, null, null);
- }
-
- public URLClassLoader (URL[] urls, ClassLoader parent)
- {
- this (urls, parent, null);
- }
-
- public URLClassLoader (URL[] urls, ClassLoader parent,
- URLStreamHandlerFactory fac)
- {
- super (parent);
-
- factory = fac;
-
- if (urls == null || urls.length == 0)
- {
- path = new Vector (1);
- info = new Vector (1);
- return;
- }
-
- path = new Vector (urls.length);
- info = new Vector (urls.length);
-
- for (int i = 0; i < urls.length; i++)
- {
- URL u = urls[i];
-
- // If it is a jar url, then we'll search it as is.
- if (! u.getProtocol ().equals ("jar"))
- {
- String f = u.getFile ();
-
- // If it ends with '/' we'll take it for a directory,
- // otherwise it's a jar file. This is how JDK 1.2 defines
- // it, so we will not try to be smart here.
- if (f.charAt (f.length ()-1) != '/')
- {
- try
- {
- u = new URL ("jar", "", -1, (u.toExternalForm ())+"!/",
- getHandler0 ("jar"));
- }
- catch (MalformedURLException x)
- {
- /* ignore */
- }
- }
- }
-
- path.insertElementAt (u, i);
-
- if (u.getProtocol ().equals ("jar"))
- {
- JarURLConnection conn = null;
- try
- {
- conn = (JarURLConnection) u.openConnection ();
- }
- catch (java.io.IOException x)
- {
- /* ignore */
- }
- info.insertElementAt (conn, i);
- }
- else
- {
- info.insertElementAt (null, i);
- }
- }
- }
-
- public URL getResource (String name)
- {
- for (int i = 0; i < path.size(); i++)
- {
- URL u = (URL)path.elementAt (i);
-
- try {
- JarURLConnection conn = (JarURLConnection) info.elementAt (i);
-
- if (conn != null)
- {
- if (conn.getJarEntry (name) != null)
- return new URL(u, name, getHandler0 (u.getProtocol()));
- }
- else
- {
- URL p = new URL (u, name, getHandler0 (u.getProtocol()));
-
- InputStream is = p.openStream();
- if (is != null)
- {
- is.close();
- return p;
- }
- }
-
- // if we get an exception ... try the next path element
- } catch (IOException x) {
- continue;
- }
- }
-
- return null;
- }
-
- /** IN jdk 1.2 this method is not overridden, but we gain performance
- by doing so.
- */
-
- public InputStream getResourceAsStream (String name)
- {
- for (int i = 0; i < path.size(); i++)
- {
- URL u = (URL)path.elementAt (i);
-
- try {
- JarURLConnection conn = (JarURLConnection) info.elementAt (i);
-
- if (conn != null)
- {
- JarFile file = conn.getJarFile ();
- JarEntry ent = file.getJarEntry (name);
- if (ent != null)
- return file.getInputStream(ent);
- }
- else
- {
- InputStream is = new URL(u, name, getHandler0 (u.getProtocol())).openStream();
- if (is != null)
- return is;
- }
-
- // if we get an exception ... try the next path element
- } catch (IOException x) {
- continue;
- }
- }
-
- return null;
- }
-
- // and finally, we can implement our class loader functionality.
- protected Class findClass (String name)
- throws ClassNotFoundException
- {
- if (name == null)
- throw new ClassNotFoundException ("null");
-
- try
- {
- InputStream is = getResourceAsStream (name.replace ('.', '/') + ".class");
-
- if (is == null)
- throw new ClassNotFoundException (name);
-
- // Here we have to rely on available() to provide the length of
- // the class; which might not be exactly right in some cases...
-
- int len = is.available ();
- byte[] data = new byte[len];
-
- int left = len;
- int off = 0;
- while (left > 0)
- {
- int c = is.read (data, off, len-off);
- if (c == -1 || c == 0)
- throw new InternalError ("premature end of file");
- left -= c;
- off += c;
- }
-
- return defineClass (name, data, 0, len);
- }
- catch (java.io.IOException x)
- {
- throw new ClassNotFoundException(name);
- }
- }
-
-}
-
diff --git a/libjava/java/net/URLConnection.java b/libjava/java/net/URLConnection.java
deleted file mode 100644
index 4ddc10c53d3..00000000000
--- a/libjava/java/net/URLConnection.java
+++ /dev/null
@@ -1,454 +0,0 @@
-// URLConnection.java - Superclass of all communications links between
-// an application and a URL.
-
-/* Copyright (C) 1999, 2000 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-import java.io.*;
-import java.text.ParsePosition;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
-import gnu.gcj.io.MimeTypes;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: One guessContentTypeFrom... methods not implemented.
- * getContent method assumes content type from response; see comment there.
- */
-
-public abstract class URLConnection
-{
- protected URL url;
- protected boolean doInput = true;
- protected boolean doOutput = false;
- protected boolean allowUserInteraction;
- protected boolean useCaches;
- protected long ifModifiedSince = 0L;
- protected boolean connected = false;
- private static boolean defaultAllowUserInteraction = false;
- private static boolean defaultUseCaches = true;
- private static FileNameMap fileNameMap; // Set by the URLConnection subclass.
- private static ContentHandlerFactory factory;
- private static ContentHandler contentHandler;
- private static Hashtable handlers = new Hashtable();
- private static Locale locale;
- private static SimpleDateFormat dateFormat1, dateFormat2, dateFormat3;
- private static boolean dateformats_initialized = false;
-
- protected URLConnection(URL url)
- {
- this.url = url;
- allowUserInteraction = defaultAllowUserInteraction;
- useCaches = defaultUseCaches;
- }
-
- public abstract void connect() throws IOException;
-
- public URL getURL()
- {
- return url;
- }
-
- public int getContentLength()
- {
- return getHeaderFieldInt("content-length", -1);
- }
-
- public String getContentType()
- {
- return getHeaderField("content-type");
- }
-
- public String getContentEncoding()
- {
- return getHeaderField("content-encoding");
- }
-
- public long getExpiration()
- {
- return getHeaderFieldDate("expiration", 0L);
- }
-
- public long getDate()
- {
- return getHeaderFieldDate("date", 0L);
- }
-
- public long getLastModified()
- {
- return getHeaderFieldDate("last-modified", 0L);
- }
-
- public String getHeaderField(int n)
- {
- // Subclasses for specific protocols override this.
- return null;
- }
-
- public String getHeaderField(String name)
- {
- // Subclasses for specific protocols override this.
- return null;
- }
-
- public int getHeaderFieldInt(String name, int val)
- {
- String str = getHeaderField(name);
- try
- {
- if (str != null)
- val = Integer.parseInt(str);
- }
- catch (NumberFormatException e)
- {
- ; // Do nothing; val is the default.
- }
- return val;
- }
-
- public long getHeaderFieldDate(String name, long val)
- {
- if (! dateformats_initialized)
- initializeDateFormats();
- String str = getHeaderField(name);
- if (str != null)
- {
- Date date;
- if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null)
- val = date.getTime();
- else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null)
- val = date.getTime();
- else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null)
- val = date.getTime();
- }
- return val;
- }
-
- public String getHeaderFieldKey(int n)
- {
- // Subclasses for specific protocols override this.
- return null;
- }
-
- public Object getContent() throws IOException
- {
- // FIXME: Doc indicates that other criteria should be applied as
- // heuristics to determine the true content type, e.g. see
- // guessContentTypeFromName() and guessContentTypeFromStream methods
- // as well as FileNameMap class & fileNameMap field & get/set methods.
- String cType = getContentType();
- contentHandler = setContentHandler(cType);
- if (contentHandler == null)
- return getInputStream();
-
- return contentHandler.getContent(this);
- }
-
-// TODO12: public Permission getPermission() throws IOException
-// {
-// // Subclasses may override this.
-// return java.security.AllPermission;
-// }
-
- public InputStream getInputStream() throws IOException
- {
- // Subclasses for specific protocols override this.
- throw new UnknownServiceException("Protocol " + url.getProtocol() +
- " does not support input.");
- }
-
- public OutputStream getOutputStream() throws IOException
- {
- // Subclasses for specific protocols override this.
- throw new UnknownServiceException("Protocol " + url.getProtocol() +
- " does not support output.");
- }
-
- public String toString()
- {
- return this.getClass().getName() + ":" + url.toString();
- }
-
- public void setDoInput(boolean doinput)
- {
- if (connected)
- throw new IllegalAccessError("Already connected");
-
- doInput = doinput;
- }
-
- public boolean getDoInput()
- {
- return doInput;
- }
-
- public void setDoOutput(boolean dooutput)
- {
- if (connected)
- throw new IllegalAccessError("Already connected");
-
- doOutput = dooutput;
- if (doOutput)
- doInput = false;
- }
-
- public boolean getDoOutput()
- {
- return doOutput;
- }
-
- public void setAllowUserInteraction(boolean allowuserinteraction)
- {
- if (connected)
- throw new IllegalAccessError("Already connected");
-
- allowUserInteraction = allowuserinteraction;
- }
-
- public boolean getAllowUserInteraction()
- {
- return allowUserInteraction;
- }
-
- public static void
- setDefaultAllowUserInteraction(boolean defaultallowuserinteraction)
- {
- defaultAllowUserInteraction = defaultallowuserinteraction;
- }
-
- public static boolean getDefaultAllowUserInteraction()
- {
- return defaultAllowUserInteraction;
- }
-
- public void setUseCaches(boolean usecaches)
- {
- if (connected)
- throw new IllegalAccessError("Already connected");
-
- useCaches = usecaches;
- }
-
- public boolean getUseCaches()
- {
- return useCaches;
- }
-
- public void setIfModifiedSince(long ifmodifiedsince)
- {
- if (connected)
- throw new IllegalAccessError("Already connected");
-
- ifModifiedSince = ifmodifiedsince;
- }
-
- public long getIfModifiedSince()
- {
- return ifModifiedSince;
- }
-
- public boolean getDefaultUseCaches()
- {
- return defaultUseCaches;
- }
-
- public void setDefaultUseCaches(boolean defaultusecaches)
- {
- defaultUseCaches = defaultusecaches;
- }
-
- public void setRequestProperty(String key, String value)
- {
- // Do nothing unless overridden by subclasses that support setting
- // header fields in the request.
- }
-
- public String getRequestProperty(String key)
- {
- // Overridden by subclasses that support reading header fields from the
- // request.
- return null;
- }
-
- public static void setDefaultRequestProperty(String key, String value)
- {
- // Do nothing unless overridden by subclasses that support setting
- // default request properties.
- }
-
- public static String getDefaultRequestProperty(String key)
- {
- // Overridden by subclasses that support default request properties.
- return null;
- }
-
- public static void setContentHandlerFactory(ContentHandlerFactory fac)
- {
- if (factory != null)
- throw new Error("ContentHandlerFactory already set");
-
- // Throw an exception if an extant security mgr precludes
- // setting the factory.
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkSetFactory();
- factory = fac;
- }
-
- protected static String guessContentTypeFromName(String fname)
- {
- int dot = fname.lastIndexOf (".");
-
- if (dot != -1)
- {
- if (dot == fname.length())
- return ("application/octet-stream");
- else
- fname = fname.substring (dot + 1);
- }
-
- String type = MimeTypes.getMimeTypeFromExtension (fname);
-
- if (type == null)
- return("application/octet-stream");
-
- return(type);
- }
-
-// TODO: public static String guessContentTypeFromStream(InputStream is)
-// throws IOException
-// {
-// }
-
-// TODO12: protected void parseURL(URL u, String spec, int start, int limit)
-
- // JDK1.2
- public static FileNameMap getFileNameMap()
- {
- return fileNameMap;
- }
-
- // JDK1.2
- public static void setFileNameMap(FileNameMap map)
- {
- // Throw an exception if an extant security mgr precludes
- // setting the factory.
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkSetFactory();
-
- fileNameMap = map;
- }
-
- private ContentHandler setContentHandler(String contentType)
- {
- ContentHandler handler;
-
- // No content type so just handle it as the default.
- if (contentType == null || contentType == "")
- return null;
-
- // See if a handler has been cached for this content type.
- // For efficiency, if a content type has been searched for but not
- // found, it will be in the hash table but as the contentType String
- // instead of a ContentHandler.
- if ((handler = (ContentHandler) handlers.get(contentType)) != null)
- if (handler instanceof ContentHandler)
- return handler;
- else
- return null;
-
- // If a non-default factory has been set, use it to find the content type.
- if (factory != null)
- handler = factory.createContentHandler(contentType);
-
- // Non-default factory may have returned null or a factory wasn't set.
- // Use the default search algorithm to find a handler for this content type.
- if (handler == null)
- {
- // Get the list of packages to check and append our default handler
- // to it, along with the JDK specified default as a last resort.
- // Except in very unusual environments the JDK specified one shouldn't
- // ever be needed (or available).
- String propVal = System.getProperty("java.content.handler.pkgs");
- propVal = (propVal == null) ? "" : (propVal + "|");
- propVal = propVal + "gnu.gcj.content|sun.net.www.content";
-
- // Replace the '/' character in the content type with '.' and
- // all other non-alphabetic, non-numeric characters with '_'.
- StringTokenizer pkgPrefix = new StringTokenizer(propVal, "|");
- char[] cArray = contentType.toCharArray();
- for (int i = 0; i < cArray.length; i++)
- {
- if (cArray[i] == '/')
- cArray[i] = '.';
- else if (! ((cArray[i] >= 'A' && cArray[i] <= 'Z') ||
- (cArray[i] >= 'a' && cArray[i] <= 'z') ||
- (cArray[i] >= '0' && cArray[i] <= '9')))
- cArray[i] = '_';
- }
- String contentClass = new String(cArray);
-
- // See if a class of this content type exists in any of the packages.
- do
- {
- String facName = pkgPrefix.nextToken() + "." + contentClass;
- try
- {
- handler =
- (ContentHandler) Class.forName(facName).newInstance();
- }
- catch (Exception e)
- {
- // Can't instantiate; handler still null, go on to next element.
- }
- } while ((handler == null ||
- ! (handler instanceof ContentHandler)) &&
- pkgPrefix.hasMoreTokens());
- }
-
- // Update the hashtable with the new content handler.
- if (handler != null && handler instanceof ContentHandler)
- {
- handlers.put(contentType, handler);
- return handler;
- }
-
- // For efficiency on subsequent searches, put a dummy entry in the hash
- // table for content types that don't have a non-default ContentHandler.
- handlers.put(contentType, contentType);
- return null;
- }
-
- // We don't put these in a static initializer, because it creates problems
- // with initializer co-dependency: SimpleDateFormat's constructors eventually
- // depend on URLConnection (via the java.text.*Symbols classes).
- private synchronized void initializeDateFormats()
- {
- if (dateformats_initialized)
- return;
- locale = new Locale("En", "Us", "Unix");
- dateFormat1 = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
- locale);
- dateFormat2 = new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'",
- locale);
- dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale);
- dateformats_initialized = true;
- }
-}
diff --git a/libjava/java/net/URLDecoder.java b/libjava/java/net/URLDecoder.java
deleted file mode 100644
index 5059a962db7..00000000000
--- a/libjava/java/net/URLDecoder.java
+++ /dev/null
@@ -1,48 +0,0 @@
-// URLDecoder.java - Provides a method for decoding strings according to
-// application/x-www-form-urlencoded MIME type.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-import java.io.UnsupportedEncodingException;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date April 22, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification.
- * Status: Believed complete and correct.
- */
-
-// JDK1.2
-public class URLDecoder
-{
- // This method, per the JCL, is conservative in that it encodes
- // some "allowable" characters as % triplets.
- public static String decode(String s) throws Exception
- {
- String str = s.replace('+', ' ');
- String result = "";
- int i;
- int start = 0;
- while ((i = str.indexOf('%', start)) >= 0)
- {
- result = result + str.substring(start, i) +
- (char) Integer.parseInt(str.substring(i + 1, i + 3), 16);
- start = i + 3;
- }
-
- if (start < str.length())
- result = result + str.substring(start);
-
- return result;
- }
-}
diff --git a/libjava/java/net/URLEncoder.java b/libjava/java/net/URLEncoder.java
deleted file mode 100644
index 6590dcf8feb..00000000000
--- a/libjava/java/net/URLEncoder.java
+++ /dev/null
@@ -1,71 +0,0 @@
-// URLEncoder.java - Provides a method for encoding strings according to
-// application/x-www-form-urlencoded MIME type.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-import java.io.UnsupportedEncodingException;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date April 22, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class URLEncoder
-{
- // This method, per the JCL, is conservative in that it encodes
- // some "allowable" characters as % triplets.
- public static String encode(String s)
- {
- // Get the bytes in ISO-Latin-1 (i.e. 8859_1) per the JCL.
- // Even though it is the default in most cases, it's specified here
- // just in case System.getProperty("file.encoding") is not "8859_1".
- String result = "";
- try
- {
- byte[] buf = s.getBytes("8859_1");
- int start = 0;
- for (int i = 0; i < buf.length; i++)
- // For efficiency, check the byte in order of most likely
- // possibility so as to minimize the number of comparisons.
- // Hence, exclude all the alphanumeric & allowed special chars first.
- if ((buf[i] >= 'a' && buf[i] <= 'z') ||
- (buf[i] >= 'A' && buf[i] <= 'Z') ||
- (buf[i] >= '0' && buf[i] <= '9') ||
- buf[i] == '-' || buf[i] == '_' || buf[i] == '.' || buf[i] == '*')
- ; // This is the most likely case so exclude first for efficiency.
- else if (buf[i] == ' ')
- buf[i] = (byte) '+'; // Replace space char with plus symbol.
- else
- {
- result = result + new String(buf, start, i - start, "8859_1") +
- "%" + Integer.toHexString(((int) buf[i]) & 0xFF);
- start = i + 1;
- }
-
- // Append remainder of allowable chars from the string, if any.
- if (start < buf.length)
- result = result +
- new String(buf, start, buf.length - start, "8859_1");
- }
- catch (UnsupportedEncodingException ex)
- {
- // This should never happen as "8859_1" is the default encoding.
- return s;
- }
-
- return result;
- }
-}
diff --git a/libjava/java/net/URLStreamHandler.java b/libjava/java/net/URLStreamHandler.java
deleted file mode 100644
index 0060b4ea688..00000000000
--- a/libjava/java/net/URLStreamHandler.java
+++ /dev/null
@@ -1,156 +0,0 @@
-// URLStreamHandler.java - Superclass of all stream protocol handlers.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 4, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public abstract class URLStreamHandler
-{
- protected abstract URLConnection openConnection(URL u)
- throws java.io.IOException;
-
- protected void parseURL(URL u, String spec, int start, int limit)
- {
- String host = u.getHost();
- int port = u.getPort();
- String file = u.getFile();
-
- /* TBD: The JDK 1.2 doc specifically says that limit is the position
- * to stop parsing at and that it will be either the end of the string
- * or the position of '#'; thus the doc infers that this method does
- * not set the ref.
- */
- if (spec.regionMatches (start, "//", 0, 2))
- {
- int hostEnd;
- int colon;
-
- start += 2;
- int slash = spec.indexOf('/', start);
- if (slash >= 0)
- hostEnd = slash;
- else
- hostEnd = limit;
-
- host = spec.substring (start, hostEnd);
-
- // Look for optional port number. It is valid for the non-port
- // part of the host name to be null (e.g. a URL "http://:80").
- // TBD: JDK 1.2 in this case sets host to null rather than "";
- // this is undocumented and likely an unintended side effect in 1.2
- // so we'll be simple here and stick with "". Note that
- // "http://" or "http:///" produce a "" host in JDK 1.2.
- if ((colon = host.indexOf(':')) >= 0)
- {
- try
- {
- port = Integer.parseInt(host.substring(colon + 1));
- }
- catch (NumberFormatException e)
- {
- ; // Ignore invalid port values; port is already set to u's
- // port.
- }
- host = host.substring(0, colon);
- }
- file = null;
- start = hostEnd;
- }
- else if (host == null)
- host = "";
-
- if (start < limit && spec.charAt(start) == '/')
- {
- // This is an absolute path name; ignore any file context.
- file = spec.substring(start, limit);
- }
- else if (file == null || file.length() <= 0)
- {
- // No file context available; just spec for file.
- file = "/" + spec.substring(start, limit);
- }
- else if (start < limit)
- {
- // Context is available, but only override it if there is a new file.
- // FIXME: unsure to what extent `/` and File.separatorChar
- // can mix in URLs. Ignore File.separatorChar for now.
- file = file.substring(0, file.lastIndexOf('/'))
- + "/" + spec.substring(start, limit);
- }
-
- int index;
-
- // Replace "/./" with "/". This probably isn't very efficient in
- // the general case, but it's probably not bad most of the time.
- while ((index = file.indexOf("/./")) >= 0)
- file = file.substring(0, index) + file.substring(index + 2);
-
- // Process "/../" correctly. This probably isn't very efficient in
- // the general case, but it's probably not bad most of the time.
- while ((index = file.indexOf("/../")) >= 0)
- {
- // Strip of the previous directory - if it exists.
- int previous = file.lastIndexOf('/', index - 1);
- if (previous >= 0)
- file = file.substring(0, previous) + file.substring(index + 3);
- else
- file = file.substring(index + 3);
- }
-
- u.set(u.getProtocol(), host, port, file, u.getRef());
- }
-
- protected void setURL(URL u, String protocol, String host, int port,
- String file, String ref)
- {
- u.set(protocol, host, port, file, ref);
- }
-
- protected String toExternalForm(URL u)
- {
- String resStr, host, file, ref;
- int port;
-
- resStr = u.getProtocol() + ":";
- host = u.getHost();
- port = u.getPort();
- file = u.getFile();
- ref = u.getRef();
-
- // JDK 1.2 online doc infers that host could be null because it
- // explicitly states that file cannot be null, but is silent on host.
- //
- // Note that this produces different results from JDK 1.2 as JDK 1.2
- // ignores a non-default port if host is null or "". That is inconsistent
- // with the spec since the result of this method is spec'ed so it can be
- // used to construct a new URL that is equivalent to the original.
- if (host == null)
- host = "";
- if (port >= 0 || ! (host.length() == 0))
- resStr = resStr + "//" + host + (port < 0 ? "" : ":" + port);
-
- resStr = resStr + file;
-
- if (ref != null)
- resStr = resStr + "#" + ref;
-
- return resStr;
- }
-}
diff --git a/libjava/java/net/URLStreamHandlerFactory.java b/libjava/java/net/URLStreamHandlerFactory.java
deleted file mode 100644
index a1b85bbcd64..00000000000
--- a/libjava/java/net/URLStreamHandlerFactory.java
+++ /dev/null
@@ -1,27 +0,0 @@
-// URLStreamHandlerFactory.java - Abstract URL Stream Handler factory.
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public abstract interface URLStreamHandlerFactory
-{
- public URLStreamHandler createURLStreamHandler(String protocol);
-}
diff --git a/libjava/java/net/UnknownHostException.java b/libjava/java/net/UnknownHostException.java
deleted file mode 100644
index 12936e06761..00000000000
--- a/libjava/java/net/UnknownHostException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// UnknownHostException.java
-
-/* Copyright (C) 1998, 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Per Bothner
- * @date January 6, 1999.
- */
-
-/*
- * Written using on-line Java Platform 1.2 API Specification.
- * Status: Believed complete and correct.
- */
-
-public class UnknownHostException extends java.io.IOException
-{
- public UnknownHostException ()
- {
- super();
- }
-
- public UnknownHostException (String host)
- {
- super(host);
- }
-}
diff --git a/libjava/java/net/UnknownServiceException.java b/libjava/java/net/UnknownServiceException.java
deleted file mode 100644
index 20b00bd3676..00000000000
--- a/libjava/java/net/UnknownServiceException.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// UnknownServiceException.java
-
-/* Copyright (C) 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-package java.net;
-
-/**
- * @author Warren Levy <warrenl@cygnus.com>
- * @date March 5, 1999.
- */
-
-/**
- * Written using on-line Java Platform 1.2 API Specification, as well
- * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
- * Status: Believed complete and correct.
- */
-
-public class UnknownServiceException extends java.io.IOException
-{
- public UnknownServiceException()
- {
- super();
- }
-
- public UnknownServiceException(String msg)
- {
- super(msg);
- }
-}
diff --git a/libjava/java/net/natInetAddress.cc b/libjava/java/net/natInetAddress.cc
deleted file mode 100644
index a25e643957b..00000000000
--- a/libjava/java/net/natInetAddress.cc
+++ /dev/null
@@ -1,339 +0,0 @@
-// natInetAddress.cc
-
-/* Copyright (C) 1998, 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-
-#if GETHOSTBYNAME_R_NEEDS_REENTRANT && !defined(_REENTRANT)
-# define _REENTRANT 1
-#endif
-
-#ifdef USE_WINSOCK
-
-#include <windows.h>
-#include <winsock.h>
-
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 64
-#endif /* MAXHOSTNAMELEN */
-
-#else
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <errno.h>
-
-#include <sys/param.h>
-#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
-#endif /* USE_WINSOCK */
-
-#include <gcj/cni.h>
-#include <jvm.h>
-#include <java/net/InetAddress.h>
-#include <java/net/UnknownHostException.h>
-#include <java/lang/SecurityException.h>
-
-#if defined(HAVE_UNAME) && ! defined(HAVE_GETHOSTNAME)
-#include <sys/utsname.h>
-#endif
-
-#ifndef HAVE_GETHOSTNAME_DECL
-extern "C" int gethostname (char *name, int namelen);
-#endif
-
-#ifdef DISABLE_JAVA_NET
-
-jbyteArray
-java::net::InetAddress::aton (jstring)
-{
- return NULL;
-}
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring, java::net::InetAddress *, jboolean)
-{
- return NULL;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
- return NULL;
-}
-
-#else /* DISABLE_JAVA_NET */
-
-jbyteArray
-java::net::InetAddress::aton (jstring host)
-{
- char *hostname;
- char buf[100];
- int len = JvGetStringUTFLength(host);
- if (len < 100)
- hostname = buf;
- else
- hostname = (char*) _Jv_AllocBytesChecked (len+1);
- JvGetStringUTFRegion (host, 0, host->length(), hostname);
- buf[len] = '\0';
- char* bytes = NULL;
- int blen = 0;
-#ifdef HAVE_INET_ATON
- struct in_addr laddr;
- if (inet_aton (hostname, &laddr))
- {
- bytes = (char*) &laddr;
- blen = 4;
- }
-#elif defined(HAVE_INET_ADDR)
-#if ! HAVE_IN_ADDR_T
- typedef jint in_addr_t;
-#endif
- in_addr_t laddr = inet_addr (hostname);
- if (laddr != (in_addr_t)(-1))
- {
- bytes = (char*) &laddr;
- blen = 4;
- }
-#endif
-#ifdef HAVE_INET_PTON
- char inet6_addr[16];
- if (len == 0 && inet_pton (AF_INET6, hostname, inet6_addr) > 0)
- {
- bytes = inet6_addr;
- blen = 16;
- }
-#endif
- if (blen == 0)
- return NULL;
- jbyteArray result = JvNewByteArray (blen);
- memcpy (elements (result), bytes, blen);
- return result;
-}
-
-
-JArray<java::net::InetAddress*> *
-java::net::InetAddress::lookup (jstring host, java::net::InetAddress* iaddr,
- jboolean all)
-{
- struct hostent *hptr = NULL;
-#if defined (HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR_R)
- struct hostent hent_r;
-#if HAVE_STRUCT_HOSTENT_DATA
- struct hostent_data fixed_buffer, *buffer_r = &fixed_buffer;
-#else
-#if defined (__GLIBC__)
- // FIXME: in glibc, gethostbyname_r returns NETDB_INTERNAL to herr and
- // ERANGE to errno if the buffer size is too small, rather than what is
- // expected here. We work around this by setting a bigger buffer size and
- // hoping that it is big enough.
- char fixed_buffer[1024];
-#else
- char fixed_buffer[200];
-#endif
- char *buffer_r = fixed_buffer;
- int size_r = sizeof (fixed_buffer);
-#endif
-#endif
-
- if (host != NULL)
- {
- char *hostname;
- char buf[100];
- int len = JvGetStringUTFLength(host);
- if (len < 100)
- hostname = buf;
- else
- hostname = (char*) _Jv_AllocBytesChecked (len+1);
- JvGetStringUTFRegion (host, 0, host->length(), hostname);
- buf[len] = '\0';
-#ifdef HAVE_GETHOSTBYNAME_R
- while (true)
- {
- int ok;
-#if HAVE_STRUCT_HOSTENT_DATA
- ok = ! gethostbyname_r (hostname, &hent_r, buffer_r);
-#else
- int herr = 0;
-#ifdef GETHOSTBYNAME_R_RETURNS_INT
- ok = ! gethostbyname_r (hostname, &hent_r, buffer_r, size_r,
- &hptr, &herr);
-#else
- hptr = gethostbyname_r (hostname, &hent_r, buffer_r, size_r, &herr);
- ok = hptr != NULL;
-#endif /* GETHOSTNAME_R_RETURNS_INT */
- if (! ok && herr == ERANGE)
- {
- size_r *= 2;
- buffer_r = (char *) _Jv_AllocBytesChecked (size_r);
- }
- else
-#endif /* HAVE_STRUCT_HOSTENT_DATA */
- break;
- }
-#else
- // FIXME: this is insufficient if some other piece of code calls
- // this gethostbyname.
- JvSynchronize sync (java::net::InetAddress::localhostAddress);
- hptr = gethostbyname (hostname);
-#endif /* HAVE_GETHOSTBYNAME_R */
- }
- else
- {
- jbyteArray bytes = iaddr->address;
- char *chars = (char*) elements (bytes);
- int len = bytes->length;
- int type;
- char *val;
- if (len == 4)
- {
- val = chars;
- type = AF_INET;
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- val = (char *) &chars;
- type = AF_INET6;
- }
-#endif /* HAVE_INET6 */
- else
- JvFail ("unrecognized size");
-
-#ifdef HAVE_GETHOSTBYADDR_R
- while (true)
- {
- int ok;
-#if HAVE_STRUCT_HOSTENT_DATA
- ok = ! gethostbyaddr_r (val, len, type, &hent_r, buffer_r);
-#else
- int herr = 0;
-#ifdef GETHOSTBYADDR_R_RETURNS_INT
- ok = ! gethostbyaddr_r (val, len, type, &hent_r,
- buffer_r, size_r, &hptr, &herr);
-#else
- hptr = gethostbyaddr_r (val, len, type, &hent_r,
- buffer_r, size_r, &herr);
- ok = hptr != NULL;
-#endif /* GETHOSTBYADDR_R_RETURNS_INT */
- if (! ok && herr == ERANGE)
- {
- size_r *= 2;
- buffer_r = (char *) _Jv_AllocBytesChecked (size_r);
- }
- else
-#endif /* HAVE_STRUCT_HOSTENT_DATA */
- break;
- }
-#else /* HAVE_GETHOSTBYADDR_R */
- // FIXME: this is insufficient if some other piece of code calls
- // this gethostbyaddr.
- JvSynchronize sync (java::net::InetAddress::localhostAddress);
- hptr = gethostbyaddr (val, len, type);
-#endif /* HAVE_GETHOSTBYADDR_R */
- }
- if (hptr != NULL)
- {
- if (!all)
- host = JvNewStringUTF (hptr->h_name);
- java::lang::SecurityException *ex = checkConnect (host);
- if (ex != NULL)
- {
- if (iaddr == NULL || iaddr->address == NULL)
- JvThrow (ex);
- hptr = NULL;
- }
- }
- if (hptr == NULL)
- {
- if (iaddr != NULL && iaddr->address != NULL)
- {
- iaddr->hostname = iaddr->getHostAddress();
- return NULL;
- }
- else
- JvThrow (new java::net::UnknownHostException(host));
- }
- int count;
- if (all)
- {
- char** ptr = hptr->h_addr_list;
- count = 0;
- while (*ptr++) count++;
- }
- else
- count = 1;
- JArray<java::net::InetAddress*> *result;
- java::net::InetAddress** iaddrs;
- if (all)
- {
- result = java::net::InetAddress::allocArray (count);
- iaddrs = elements (result);
- }
- else
- {
- result = NULL;
- iaddrs = &iaddr;
- }
-
- for (int i = 0; i < count; i++)
- {
- if (iaddrs[i] == NULL)
- iaddrs[i] = new java::net::InetAddress (NULL, NULL);
- if (iaddrs[i]->hostname == NULL)
- iaddrs[i]->hostname = host;
- if (iaddrs[i]->address == NULL)
- {
- char *bytes = hptr->h_addr_list[i];
- iaddrs[i]->address = JvNewByteArray (hptr->h_length);
- memcpy (elements (iaddrs[i]->address), bytes, hptr->h_length);
- }
- }
- return result;
-}
-
-jstring
-java::net::InetAddress::getLocalHostname ()
-{
- char *chars;
-#ifdef HAVE_GETHOSTNAME
- char buffer[MAXHOSTNAMELEN];
- if (gethostname (buffer, MAXHOSTNAMELEN))
- return NULL;
- chars = buffer;
-#elif HAVE_UNAME
- struct utsname stuff;
- if (uname (&stuff) != 0)
- return NULL;
- chars = stuff.nodename;
-#else
- return NULL;
-#endif
- // It is admittedly non-optimal to convert the hostname to Unicode
- // only to convert it back in getByName, but simplicity wins. Note
- // that unless there is a SecurityManager, we only get called once
- // anyway, thanks to the InetAddress.localhost cache.
- return JvNewStringUTF (chars);
-}
-
-#endif /* DISABLE_JAVA_NET */
diff --git a/libjava/java/net/natPlainDatagramSocketImpl.cc b/libjava/java/net/natPlainDatagramSocketImpl.cc
deleted file mode 100644
index 94383f8309d..00000000000
--- a/libjava/java/net/natPlainDatagramSocketImpl.cc
+++ /dev/null
@@ -1,632 +0,0 @@
-/* Copyright (C) 1999, 2000 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-
-#ifdef USE_WINSOCK
-#include <windows.h>
-#include <winsock.h>
-#include <errno.h>
-#include <string.h>
-#ifndef ENOPROTOOPT
-#define ENOPROTOOPT 109
-#endif
-#else /* USE_WINSOCK */
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#include <sys/time.h>
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#include <errno.h>
-#include <string.h>
-#endif /* USE_WINSOCK */
-
-#if HAVE_BSTRING_H
-// Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
-#include <bstring.h>
-#endif
-
-#include <gcj/cni.h>
-#include <java/io/IOException.h>
-#include <java/io/FileDescriptor.h>
-#include <java/io/InterruptedIOException.h>
-#include <java/net/BindException.h>
-#include <java/net/SocketException.h>
-#include <java/net/PlainDatagramSocketImpl.h>
-#include <java/net/InetAddress.h>
-#include <java/net/DatagramPacket.h>
-#include <java/lang/InternalError.h>
-#include <java/lang/Object.h>
-#include <java/lang/Boolean.h>
-#include <java/lang/Integer.h>
-
-#define BooleanClass _CL_Q34java4lang7Boolean
-extern java::lang::Class BooleanClass;
-#define IntegerClass _CL_Q34java4lang7Integer
-extern java::lang::Class IntegerClass;
-
-#ifdef DISABLE_JAVA_NET
-
-void
-java::net::PlainDatagramSocketImpl::create ()
-{
- JvThrow (new SocketException (JvNewStringLatin1 ("DatagramSocketImpl.create: unimplemented")));
-}
-
-void
-java::net::PlainDatagramSocketImpl::bind (jint, java::net::InetAddress *)
-{
- JvThrow (new BindException (JvNewStringLatin1 ("DatagramSocketImpl.bind: unimplemented")));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *)
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("DatagramSocketImpl.peek: unimplemented")));
-}
-
-void
-java::net::PlainDatagramSocketImpl::send (java::net::DatagramPacket *)
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("DatagramSocketImpl.send: unimplemented")));
-}
-
-void
-java::net::PlainDatagramSocketImpl::receive (java::net::DatagramPacket *)
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("DatagramSocketImpl.receive: unimplemented")));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setTimeToLive (jint)
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("DatagramSocketImpl.setTimeToLive: unimplemented")));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::getTimeToLive ()
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("DatagramSocketImpl.getTimeToLive: unimplemented")));
-}
-
-void
-java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *,
- jboolean)
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("DatagramSocketImpl.mcastGrp: unimplemented")));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setOption (jint, java::lang::Object *)
-{
- JvThrow (new SocketException (JvNewStringLatin1 ("DatagramSocketImpl.setOption: unimplemented")));
-}
-
-java::lang::Object *
-java::net::PlainDatagramSocketImpl::getOption (jint)
-{
- JvThrow (new SocketException (JvNewStringLatin1 ("DatagramSocketImpl.getOption: unimplemented")));
-}
-
-#else /* DISABLE_JAVA_NET */
-
-#ifndef HAVE_SOCKLEN_T
-typedef int socklen_t;
-#endif
-
-union SockAddr
-{
- struct sockaddr_in address;
-#ifdef HAVE_INET6
- struct sockaddr_in6 address6;
-#endif
-};
-
-union McastReq
-{
-#if HAVE_STRUCT_IP_MREQ
- struct ip_mreq mreq;
-#endif
-#ifdef HAVE_INET6
- struct ipv6_mreq mreq6;
-#endif
-};
-
-union InAddr
-{
- struct in_addr addr;
-#ifdef HAVE_INET6
- struct in6_addr addr6;
-#endif
-};
-
-
-// FIXME: routines here and/or in natPlainSocketImpl.cc could throw
-// NoRouteToHostException; also consider UnknownHostException, ConnectException.
-
-void
-java::net::PlainDatagramSocketImpl::create ()
-{
- int sock = ::socket (AF_INET, SOCK_DGRAM, 0);
- if (sock < 0)
- {
- char* strerr = strerror (errno);
- JvThrow (new java::net::SocketException (JvNewStringUTF (strerr)));
- }
- fnum = sock;
- fd = new java::io::FileDescriptor (sock);
-}
-
-void
-java::net::PlainDatagramSocketImpl::bind (jint lport,
- java::net::InetAddress *host)
-{
- // FIXME: prob. need to do a setsockopt with SO_BROADCAST to allow multicast.
- union SockAddr u;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
- jbyteArray haddress = host->address;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
-
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
- 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);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (lport);
- }
-#endif
- else
- goto error;
- if (::bind (fnum, ptr, len) == 0)
- {
- socklen_t addrlen = sizeof(u);
- if (lport != 0)
- localPort = lport;
- else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
- localPort = ntohs (u.address.sin_port);
- else
- goto error;
- return;
- }
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::net::BindException (JvNewStringUTF (strerr)));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::peek (java::net::InetAddress *i)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- ssize_t retlen =
- ::recvfrom (fnum, (char *) NULL, 0, MSG_PEEK, (sockaddr*) &u,
- &addrlen);
- if (retlen < 0)
- goto error;
- // FIXME: Deal with Multicast addressing and if the socket is connected.
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- goto error;
- i->address = raddr;
- return rport;
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
-}
-
-void
-java::net::PlainDatagramSocketImpl::send (java::net::DatagramPacket *p)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- jint rport = p->getPort();
- union SockAddr u;
- jbyteArray haddress = p->getAddress()->address;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- jbyte *dbytes = elements (p->getData());
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
- memcpy (&u.address.sin_addr, bytes, len);
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (rport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (rport);
- }
-#endif
- else
- goto error;
- if (::sendto (fnum, (char *) dbytes, p->getLength(), 0, ptr, len) >= 0)
- return;
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
-}
-
-void
-java::net::PlainDatagramSocketImpl::receive (java::net::DatagramPacket *p)
-{
- // FIXME: Deal with Multicast and if the socket is connected.
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- jbyte *dbytes = elements (p->getData());
- ssize_t retlen = 0;
-
- // Do timeouts via select since SO_RCVTIMEO is not always available.
- if (timeout > 0)
- {
- 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 = select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
- goto error;
- else if (retval == 0)
- JvThrow (new java::io::InterruptedIOException ());
- }
-
- retlen =
- ::recvfrom (fnum, (char *) dbytes, p->getLength(), 0, (sockaddr*) &u,
- &addrlen);
- if (retlen < 0)
- goto error;
- // FIXME: Deal with Multicast addressing and if the socket is connected.
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- goto error;
- p->setAddress (new InetAddress (raddr, NULL));
- p->setPort (rport);
- p->setLength ((jint) retlen);
- return;
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setTimeToLive (jint ttl)
-{
- // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
- char val = (char) ttl;
- socklen_t val_len = sizeof(val);
- if (::setsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, val_len) == 0)
- return;
-
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
-}
-
-jint
-java::net::PlainDatagramSocketImpl::getTimeToLive ()
-{
- // Assumes IPPROTO_IP rather than IPPROTO_IPV6 since socket created is IPv4.
- char val;
- socklen_t val_len = sizeof(val);
- if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_TTL, &val, &val_len) == 0)
- return ((int) val) & 0xFF;
-
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
-}
-
-void
-java::net::PlainDatagramSocketImpl::mcastGrp (java::net::InetAddress *inetaddr,
- jboolean join)
-{
- union McastReq u;
- jbyteArray haddress = inetaddr->address;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- int level, opname;
- const char *ptr;
- if (0)
- ;
-#if HAVE_STRUCT_IP_MREQ
- else if (len == 4)
- {
- level = IPPROTO_IP;
- opname = join ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP;
- memcpy (&u.mreq.imr_multiaddr, bytes, len);
- // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
- // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
- u.mreq.imr_interface.s_addr = htonl (INADDR_ANY);
- len = sizeof (struct ip_mreq);
- ptr = (const char *) &u.mreq;
- }
-#endif
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- level = IPPROTO_IPV6;
- opname = join ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP;
- memcpy (&u.mreq6.ipv6mr_multiaddr, bytes, len);
- // FIXME: If a non-default interface is set, use it; see Stevens p. 501.
- // Maybe not, see note in last paragraph at bottom of Stevens p. 497.
- u.mreq6.ipv6mr_interface = 0;
- len = sizeof (struct ipv6_mreq);
- ptr = (const char *) &u.mreq6;
- }
-#endif
- else
- goto error;
- if (::setsockopt (fnum, level, opname, ptr, len) == 0)
- return;
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
-}
-
-void
-java::net::PlainDatagramSocketImpl::setOption (jint optID,
- java::lang::Object *value)
-{
- int val;
- socklen_t val_len = sizeof (val);
-
- if (_Jv_IsInstanceOf (value, &BooleanClass))
- {
- java::lang::Boolean *boolobj =
- static_cast<java::lang::Boolean *> (value);
- val = boolobj->booleanValue() ? 1 : 0;
- }
- else if (_Jv_IsInstanceOf (value, &IntegerClass))
- {
- java::lang::Integer *intobj =
- static_cast<java::lang::Integer *> (value);
- val = (int) intobj->intValue();
- }
- // Else assume value to be an InetAddress for use with IP_MULTICAST_IF.
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("TCP_NODELAY not valid for UDP")));
- return;
- case _Jv_SO_LINGER_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("SO_LINGER not valid for UDP")));
- return;
- case _Jv_SO_SNDBUF_ :
- case _Jv_SO_RCVBUF_ :
-#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
- goto error;
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported")));
-#endif
- return;
- case _Jv_SO_REUSEADDR_ :
-#if defined(SO_REUSEADDR)
- if (::setsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
- val_len) != 0)
- goto error;
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("SO_REUSEADDR not supported")));
-#endif
- return;
- case _Jv_SO_BINDADDR_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("SO_BINDADDR: read only option")));
- return;
- case _Jv_IP_MULTICAST_IF_ :
- union InAddr u;
- jbyteArray haddress;
- jbyte *bytes;
- int len;
- int level, opname;
- const char *ptr;
-
- haddress = ((java::net::InetAddress *) value)->address;
- bytes = elements (haddress);
- len = haddress->length;
- if (len == 4)
- {
- level = IPPROTO_IP;
- opname = IP_MULTICAST_IF;
- memcpy (&u.addr, bytes, len);
- len = sizeof (struct in_addr);
- ptr = (const char *) &u.addr;
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- level = IPPROTO_IPV6;
- opname = IPV6_MULTICAST_IF;
- memcpy (&u.addr6, bytes, len);
- len = sizeof (struct in6_addr);
- ptr = (const char *) &u.addr6;
- }
-#endif
- else
- goto error;
- if (::setsockopt (fnum, level, opname, ptr, len) != 0)
- goto error;
- return;
- case _Jv_SO_TIMEOUT_ :
- timeout = val;
- return;
- default :
- errno = ENOPROTOOPT;
- }
-
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::net::SocketException (JvNewStringUTF (strerr)));
-}
-
-java::lang::Object *
-java::net::PlainDatagramSocketImpl::getOption (jint optID)
-{
- int val;
- socklen_t val_len = sizeof(val);
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("TCP_NODELAY not valid for UDP")));
- break;
-
- case _Jv_SO_LINGER_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("SO_LINGER not valid for UDP")));
- break;
- case _Jv_SO_RCVBUF_ :
- case _Jv_SO_SNDBUF_ :
-#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
- goto error;
- else
- return new java::lang::Integer (val);
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported")));
-#endif
- break;
- case _Jv_SO_BINDADDR_:
- // 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);
- }
-#endif
- else
- goto error;
- localAddress = new java::net::InetAddress (laddr, NULL);
- }
- return localAddress;
- break;
- case _Jv_SO_REUSEADDR_ :
-#if defined(SO_REUSEADDR)
- if (::getsockopt (fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &val,
- &val_len) != 0)
- goto error;
- return new java::lang::Boolean (val != 0);
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("SO_REUSEADDR not supported")));
-#endif
- break;
- case _Jv_IP_MULTICAST_IF_ :
-#ifdef HAVE_INET_NTOA
- struct in_addr inaddr;
- socklen_t inaddr_len;
- char *bytes;
-
- inaddr_len = sizeof(inaddr);
- if (::getsockopt (fnum, IPPROTO_IP, IP_MULTICAST_IF, (char *) &inaddr,
- &inaddr_len) != 0)
- goto error;
-
- bytes = inet_ntoa (inaddr);
-
- return java::net::InetAddress::getByName (JvNewStringLatin1 (bytes));
-#else
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF: not available - no inet_ntoa()")));
-#endif
- break;
- case _Jv_SO_TIMEOUT_ :
- return new java::lang::Integer (timeout);
- break;
- default :
- errno = ENOPROTOOPT;
- }
-
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::net::SocketException (JvNewStringUTF (strerr)));
-}
-
-#endif /* DISABLE_JAVA_NET */
diff --git a/libjava/java/net/natPlainSocketImpl.cc b/libjava/java/net/natPlainSocketImpl.cc
deleted file mode 100644
index 52187461f49..00000000000
--- a/libjava/java/net/natPlainSocketImpl.cc
+++ /dev/null
@@ -1,477 +0,0 @@
-/* Copyright (C) 1998, 1999 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-
-
-#ifndef DISABLE_JAVA_NET
-#ifdef USE_WINSOCK
-#include <windows.h>
-#include <winsock.h>
-#include <errno.h>
-#include <string.h>
-#ifndef ENOPROTOOPT
-#define ENOPROTOOPT 109
-#endif
-#else /* USE_WINSOCK */
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <errno.h>
-#include <string.h>
-#endif /* USE_WINSOCK */
-#endif /* DISABLE_JAVA_NET */
-
-#if HAVE_BSTRING_H
-// Needed for bzero, implicitly used by FD_ZERO on IRIX 5.2
-#include <bstring.h>
-#endif
-
-#include <gcj/cni.h>
-#include <gcj/javaprims.h>
-#include <java/io/IOException.h>
-#include <java/io/FileDescriptor.h>
-#include <java/io/InterruptedIOException.h>
-#include <java/net/BindException.h>
-#include <java/net/ConnectException.h>
-#include <java/net/PlainSocketImpl.h>
-#include <java/net/InetAddress.h>
-#include <java/net/SocketException.h>
-#include <java/lang/InternalError.h>
-#include <java/lang/Object.h>
-#include <java/lang/Boolean.h>
-#include <java/lang/Class.h>
-#include <java/lang/Integer.h>
-
-#define BooleanClass _CL_Q34java4lang7Boolean
-extern java::lang::Class BooleanClass;
-
-#ifdef DISABLE_JAVA_NET
-
-void
-java::net::PlainSocketImpl::create (jboolean)
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("SocketImpl.create: unimplemented")));
-}
-
-void
-java::net::PlainSocketImpl::bind (java::net::InetAddress *, jint)
-{
- JvThrow (new BindException (JvNewStringLatin1 ("SocketImpl.bind: unimplemented")));
-}
-
-void
-java::net::PlainSocketImpl::connect (java::net::InetAddress *, jint)
-{
- JvThrow (new ConnectException (JvNewStringLatin1 ("SocketImpl.connect: unimplemented")));
-}
-
-void
-java::net::PlainSocketImpl::listen (jint)
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("SocketImpl.listen: unimplemented")));
-}
-
-void
-java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *)
-{
- JvThrow (new java::io::IOException (JvNewStringLatin1 ("SocketImpl.accept: unimplemented")));
-}
-
-void
-java::net::PlainSocketImpl::setOption (jint, java::lang::Object *)
-{
- JvThrow (new SocketException (JvNewStringLatin1 ("SocketImpl.setOption: unimplemented")));
-}
-
-java::lang::Object *
-java::net::PlainSocketImpl::getOption (jint)
-{
- JvThrow (new SocketException (JvNewStringLatin1 ("SocketImpl.getOption: unimplemented")));
-}
-
-#else /* DISABLE_JAVA_NET */
-
-#ifndef HAVE_SOCKLEN_T
-typedef int socklen_t;
-#endif
-
-union SockAddr
-{
- struct sockaddr_in address;
-#ifdef HAVE_INET6
- struct sockaddr_in6 address6;
-#endif
-};
-
-void
-java::net::PlainSocketImpl::create (jboolean stream)
-{
- int sock = ::socket (AF_INET, stream ? SOCK_STREAM : SOCK_DGRAM, 0);
- if (sock < 0)
- {
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
- }
- fnum = sock;
- fd = new java::io::FileDescriptor (sock);
-}
-
-void
-java::net::PlainSocketImpl::bind (java::net::InetAddress *host, jint lport)
-{
- union SockAddr u;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- jbyteArray haddress = host->address;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- int i = 1;
-
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
- 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);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (lport);
- }
-#endif
- else
- goto error;
-
- // Enable SO_REUSEADDR, so that servers can reuse ports left in TIME_WAIT.
- ::setsockopt(fnum, SOL_SOCKET, SO_REUSEADDR, (char *) &i, sizeof(i));
-
- if (::bind (fnum, ptr, len) == 0)
- {
- address = host;
- socklen_t addrlen = sizeof(u);
- if (lport != 0)
- localport = lport;
- else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
- localport = ntohs (u.address.sin_port);
- else
- goto error;
- return;
- }
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::net::BindException (JvNewStringUTF (strerr)));
-}
-
-void
-java::net::PlainSocketImpl::connect (java::net::InetAddress *host, jint rport)
-{
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- jbyteArray haddress = host->address;
- jbyte *bytes = elements (haddress);
- int len = haddress->length;
- struct sockaddr *ptr = (struct sockaddr *) &u.address;
- if (len == 4)
- {
- u.address.sin_family = AF_INET;
- memcpy (&u.address.sin_addr, bytes, len);
- len = sizeof (struct sockaddr_in);
- u.address.sin_port = htons (rport);
- }
-#ifdef HAVE_INET6
- else if (len == 16)
- {
- u.address6.sin6_family = AF_INET6;
- memcpy (&u.address6.sin6_addr, bytes, len);
- len = sizeof (struct sockaddr_in6);
- u.address6.sin6_port = htons (rport);
- }
-#endif
- else
- goto error;
- if (::connect (fnum, ptr, len) != 0)
- goto error;
- address = host;
- port = rport;
- // A bind may not have been done on this socket; if so, set localport now.
- if (localport == 0)
- if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
- localport = ntohs (u.address.sin_port);
- else
- goto error;
- return;
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::net::ConnectException (JvNewStringUTF (strerr)));
-}
-
-void
-java::net::PlainSocketImpl::listen (jint backlog)
-{
- if (::listen (fnum, backlog) != 0)
- {
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
- }
-}
-
-void
-java::net::PlainSocketImpl::accept (java::net::PlainSocketImpl *s)
-{
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- int new_socket = 0;
-
- // Do timeouts via select since SO_RCVTIMEO is not always available.
- if (timeout > 0)
- {
- 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 = select (fnum + 1, &rset, NULL, NULL, &tv)) < 0)
- goto error;
- else if (retval == 0)
- JvThrow (new java::io::InterruptedIOException (
- JvNewStringUTF("Accept timed out")));
- }
-
- new_socket = ::accept (fnum, (sockaddr*) &u, &addrlen);
- if (new_socket < 0)
- goto error;
- jbyteArray raddr;
- jint rport;
- if (u.address.sin_family == AF_INET)
- {
- raddr = JvNewByteArray (4);
- memcpy (elements (raddr), &u.address.sin_addr, 4);
- rport = ntohs (u.address.sin_port);
- }
-#ifdef HAVE_INET6
- else if (u.address.sin_family == AF_INET6)
- {
- raddr = JvNewByteArray (16);
- memcpy (elements (raddr), &u.address6.sin6_addr, 16);
- rport = ntohs (u.address6.sin6_port);
- }
-#endif
- else
- goto error;
- s->fnum = new_socket;
- s->localport = localport;
- s->address = new InetAddress (raddr, NULL);
- s->port = rport;
- s->fd = new java::io::FileDescriptor (new_socket);
- return;
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::io::IOException (JvNewStringUTF (strerr)));
-}
-
-void
-java::net::PlainSocketImpl::setOption (jint optID, java::lang::Object *value)
-{
- int val;
- socklen_t val_len = sizeof (val);
-
- if (_Jv_IsInstanceOf (value, &BooleanClass))
- {
- java::lang::Boolean *boolobj =
- static_cast<java::lang::Boolean *> (value);
- if (boolobj->booleanValue())
- val = 1;
- else
- {
- if (optID == _Jv_SO_LINGER_)
- val = -1;
- else
- val = 0;
- }
- }
- else // assume value is an Integer
- {
- java::lang::Integer *intobj =
- static_cast<java::lang::Integer *> (value);
- val = (int) intobj->intValue();
- }
-
- switch (optID)
- {
- case _Jv_TCP_NODELAY_ :
-#ifdef TCP_NODELAY
- if (::setsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
- val_len) != 0)
- goto error;
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("TCP_NODELAY not supported")));
-#endif /* TCP_NODELAY */
- return;
- case _Jv_SO_LINGER_ :
-#ifdef SO_LINGER
- struct linger l_val;
- l_val.l_onoff = (val != -1);
- l_val.l_linger = val;
- if (::setsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
- sizeof(l_val)) != 0)
- goto error;
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("SO_LINGER not supported")));
-#endif /* SO_LINGER */
- return;
- case _Jv_SO_SNDBUF_ :
- case _Jv_SO_RCVBUF_ :
-#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::setsockopt (fnum, SOL_SOCKET, opt, (char *) &val, val_len) != 0)
- goto error;
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported")));
-#endif
- return;
- case _Jv_SO_BINDADDR_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("SO_BINDADDR: read only option")));
- return;
- case _Jv_IP_MULTICAST_IF_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP")));
- return;
- case _Jv_SO_REUSEADDR_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("SO_REUSEADDR: not valid for TCP")));
- return;
- case _Jv_SO_TIMEOUT_ :
- timeout = val;
- return;
- default :
- errno = ENOPROTOOPT;
- }
-
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::net::SocketException (JvNewStringUTF (strerr)));
-}
-
-java::lang::Object *
-java::net::PlainSocketImpl::getOption (jint optID)
-{
- int val;
- socklen_t val_len = sizeof(val);
- union SockAddr u;
- socklen_t addrlen = sizeof(u);
- struct linger l_val;
- socklen_t l_val_len = sizeof(l_val);
-
- switch (optID)
- {
-#ifdef TCP_NODELAY
- case _Jv_TCP_NODELAY_ :
- if (::getsockopt (fnum, IPPROTO_TCP, TCP_NODELAY, (char *) &val,
- &val_len) != 0)
- goto error;
- else
- return new java::lang::Boolean (val != 0);
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("TCP_NODELAY not supported")));
-#endif
- break;
-
- case _Jv_SO_LINGER_ :
-#ifdef SO_LINGER
- if (::getsockopt (fnum, SOL_SOCKET, SO_LINGER, (char *) &l_val,
- &l_val_len) != 0)
- goto error;
- if (l_val.l_onoff)
- return new java::lang::Integer (l_val.l_linger);
- else
- return new java::lang::Boolean ((__java_boolean)false);
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("SO_LINGER not supported")));
-#endif
- break;
- case _Jv_SO_RCVBUF_ :
- case _Jv_SO_SNDBUF_ :
-#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
- int opt;
- optID == _Jv_SO_SNDBUF_ ? opt = SO_SNDBUF : opt = SO_RCVBUF;
- if (::getsockopt (fnum, SOL_SOCKET, opt, (char *) &val, &val_len) != 0)
- goto error;
- else
- return new java::lang::Integer (val);
-#else
- JvThrow (new java::lang::InternalError (
- JvNewStringUTF ("SO_RCVBUF/SO_SNDBUF not supported")));
-#endif
- break;
- case _Jv_SO_BINDADDR_:
- // 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);
- }
-#endif
- else
- goto error;
- localAddress = new java::net::InetAddress (laddr, NULL);
- }
- return localAddress;
- break;
- case _Jv_IP_MULTICAST_IF_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("IP_MULTICAST_IF: not valid for TCP")));
- break;
- case _Jv_SO_REUSEADDR_ :
- JvThrow (new java::net::SocketException (
- JvNewStringUTF ("SO_REUSEADDR: not valid for TCP")));
- break;
- case _Jv_SO_TIMEOUT_ :
- return new java::lang::Integer (timeout);
- break;
- default :
- errno = ENOPROTOOPT;
- }
-
- error:
- char* strerr = strerror (errno);
- JvThrow (new java::net::SocketException (JvNewStringUTF (strerr)));
-}
-
-#endif /* DISABLE_JAVA_NET */