harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [111/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketImpl.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketImpl.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketImpl.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketImpl.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,492 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+import java.io.OutputStream;
+
+/**
+ * The abstract superclass of all classes that implement streaming sockets.
+ * 
+ * Streaming sockets are wrapped by two classes, ServerSocket and Socket at the
+ * server and client end of a connection respectively. At the server there are
+ * two types of sockets engaged in communication, the <code>ServerSocket</code>
+ * on a well known port (hereafter refered to as the listener) used to establish
+ * a connection and the resulting <code>Socket</code> (hereafter refered to as
+ * host).
+ * 
+ * Some of the <code>SocketImpl</code> instance variable values must be
+ * interpreted in the context of the wrapper. See the getter methods for these
+ * details.
+ */
+public abstract class SocketImpl implements SocketOptions {
+
+	protected InetAddress address;
+
+	protected int port;
+
+	protected FileDescriptor fd;
+
+	protected int localport;
+
+	int receiveTimeout;
+
+	boolean streaming = true;
+
+	boolean shutdownInput = false;
+
+	// Fill in the JNI id caches
+	private static native void oneTimeInitialization(boolean jcl_supports_ipv6);
+
+	static {
+		oneTimeInitialization(true);
+	}
+
+	/**
+	 * Construct a connection-oriented SocketImpl.
+	 * 
+	 * @see SocketImplFactory
+	 */
+	public SocketImpl() {
+		initializeSocket();
+	}
+
+	/**
+	 * Accepts a connection on the provided socket.
+	 * 
+	 * @param newSocket
+	 *            the socket to accept connections on
+	 * @exception SocketException
+	 *                if an error occurs while accepting
+	 */
+	protected abstract void accept(SocketImpl newSocket) throws IOException;
+
+	/**
+	 * Answer the number of bytes that may be read from this socket without
+	 * blocking. This call does not block.
+	 * 
+	 * @return int the number of bytes that may be read without blocking
+	 * @exception SocketException
+	 *                if an error occurs while peeking
+	 */
+	protected abstract int available() throws IOException;
+
+	/**
+	 * Binds this socket to the specified local host/port.
+	 * 
+	 * @param address
+	 *            the local machine address to bind the socket to
+	 * @param port
+	 *            the port on the local machine to bind the socket to
+	 * @exception IOException
+	 *                if an error occurs while binding
+	 */
+	protected abstract void bind(InetAddress address, int port)
+			throws IOException;
+
+	/**
+	 * Close the socket. Usage thereafter is invalid.
+	 * 
+	 * @exception IOException
+	 *                if an error occurs while closing
+	 */
+	protected abstract void close() throws IOException;
+
+	/**
+	 * Connects this socket to the specified remote host/port.
+	 * 
+	 * @param host
+	 *            the remote host to connect to
+	 * @param port
+	 *            the remote port to connect to
+	 * @exception IOException
+	 *                if an error occurs while connecting
+	 */
+	protected abstract void connect(String host, int port) throws IOException;
+
+	/**
+	 * Connects this socket to the specified remote host address/port.
+	 * 
+	 * @param address
+	 *            the remote host address to connect to
+	 * @param port
+	 *            the remote port to connect to
+	 * @exception IOException
+	 *                if an error occurs while connecting
+	 */
+	protected abstract void connect(InetAddress address, int port)
+			throws IOException;
+
+	/**
+	 * Creates a new unconnected socket. If streaming is true, create a stream
+	 * socket, else a datagram socket.
+	 * 
+	 * @param isStreaming
+	 *            true, if the socket is type streaming
+	 * @exception SocketException
+	 *                if an error occurs while creating the socket
+	 */
+	protected abstract void create(boolean isStreaming) throws IOException;
+
+	/**
+	 * Answer the socket's file descriptor.
+	 * 
+	 * @return FileDescriptor the socket FileDescriptor
+	 */
+	protected FileDescriptor getFileDescriptor() {
+		return fd;
+	}
+
+	/**
+	 * Answer the socket's address. Refering to the class comment: Listener: The
+	 * local machines IP address to which this socket is bound. Host: The client
+	 * machine, to which this socket is connected. Client: The host machine, to
+	 * which this socket is connected.
+	 * 
+	 * @return InetAddress the socket address
+	 */
+	protected InetAddress getInetAddress() {
+		return address;
+	}
+
+	/**
+	 * Answer the socket input stream.
+	 * 
+	 * @return InputStream an InputStream on the socket
+	 * @exception IOException
+	 *                thrown if an error occurs while accessing the stream
+	 */
+	protected abstract InputStream getInputStream() throws IOException;
+
+	/**
+	 * Answer the socket's localport. The field is initialized to -1 and upon
+	 * demand will go to the IP stack to get the bound value. See the class
+	 * comment for the context of the local port.
+	 * 
+	 * @return int the socket localport
+	 */
+
+	protected int getLocalPort() {
+		return localport;
+	}
+
+	/**
+	 * Answer the nominated socket option.
+	 * 
+	 * @param optID
+	 *            the socket option to retrieve
+	 * @return Object the option value
+	 * @exception SocketException
+	 *                thrown if an error occurs while accessing the option
+	 */
+	public abstract Object getOption(int optID) throws SocketException;
+
+	/**
+	 * Answer the socket output stream.
+	 * 
+	 * @return OutputStream an OutputStream on the socket
+	 * @exception IOException
+	 *                thrown if an error occurs while accessing the stream
+	 */
+	protected abstract OutputStream getOutputStream() throws IOException;
+
+	/**
+	 * Answer the socket's remote port. This value is not meaningful when the
+	 * socketImpl is wrapped by a ServerSocket.
+	 * 
+	 * @return int the remote port the socket is connected to
+	 */
+	protected int getPort() {
+		return port;
+	}
+
+	/**
+	 * Initialize the socket. By default, read & accept operations are blocking.
+	 * The port fields are created with -1 values, to flag them as unset.
+	 */
+	void initializeSocket() {
+		fd = new FileDescriptor();
+		receiveTimeout = 0;
+	}
+
+	/**
+	 * Listen for connection requests on this stream socket. Incoming connection
+	 * requests are queued, up to the limit nominated by backlog. Additional
+	 * requests are rejected. listen() may only be invoked on stream sockets.
+	 * 
+	 * @param backlog
+	 *            the max number of outstanding connection requests
+	 * @exception IOException
+	 *                thrown if an error occurs while listening
+	 */
+
+	protected abstract void listen(int backlog) throws IOException;
+
+	/**
+	 * Answer the result of attempting to accept a connection request to this
+	 * stream socket in the IP stack.
+	 * 
+	 * @param fdServer
+	 *            the server socket FileDescriptor
+	 * @param newSocket
+	 *            the host socket a connection will be accepted on
+	 * @param fdnewSocket
+	 *            the FileDescriptor for the host socket
+	 * @param timeout
+	 *            the timeout that the server should listen for
+	 * @exception SocketException
+	 *                if an error occurs while accepting connections
+	 */
+	static native void acceptStreamSocketImpl(FileDescriptor fdServer,
+			SocketImpl newSocket, FileDescriptor fdnewSocket, int timeout)
+			throws IOException;
+
+	/**
+	 * Answer the number of bytes available to read on the socket without
+	 * blocking.
+	 * 
+	 * @param aFD
+	 *            the socket FileDescriptor
+	 * @exception SocketException
+	 *                if an error occurs while peeking
+	 */
+	static native int availableStreamImpl(FileDescriptor aFD)
+			throws SocketException;
+
+	/**
+	 * Answer the result of attempting to create a stream socket in the IP
+	 * stack.
+	 * 
+	 * @param aFD
+	 *            the socket FileDescriptor
+	 * @exception SocketException
+	 *                if an error occurs while creating the socket
+	 */
+	static native void createStreamSocketImpl(FileDescriptor aFD,
+			boolean preferIPv4Stack) throws SocketException;
+
+	/**
+	 * Allocate a datagram socket in the IP stack. The socket is associated with
+	 * the <code>aFD</code>.
+	 * 
+	 * @param aFD
+	 *            the FileDescriptor to associate with the socket
+	 * 
+	 * @exception SocketException
+	 *                upon an allocation error
+	 */
+
+	static native void createDatagramSocketImpl(FileDescriptor aFD,
+			boolean preferIPv4Stack) throws SocketException;
+
+	/**
+	 * Answer the result of attempting to listen on a stream socket in the IP
+	 * stack.
+	 * 
+	 * @param aFD
+	 *            the socket FileDescriptor
+	 * @param backlog
+	 *            the number of connection requests that may be queued before
+	 *            requests are rejected
+	 * @exception SocketException
+	 *                if an error occurs while listening
+	 */
+	static native void listenStreamSocketImpl(FileDescriptor aFD, int backlog)
+			throws SocketException;
+
+	/**
+	 * Recieve at most <code>count</code> bytes into the buffer
+	 * <code>data</code> at the <code>offset</code> on the socket.
+	 * 
+	 * @param aFD
+	 *            the socket FileDescriptor
+	 * @param data
+	 *            the receive buffer
+	 * @param offset
+	 *            the offset into the buffer
+	 * @param count
+	 *            the max number of bytes to receive
+	 * @param timeout
+	 *            the max time the read operation should block waiting for data
+	 * @return int the actual number of bytes read
+	 * @exception SocketException
+	 *                if an error occurs while reading
+	 */
+	static native int receiveStreamImpl(FileDescriptor aFD, byte[] data,
+			int offset, int count, int timeout) throws IOException;
+
+	/**
+	 * Send <code>count</code> bytes from the buffer <code>data</code> at
+	 * the <code>offset</code>, on the socket.
+	 * 
+	 * @param data
+	 *            the send buffer
+	 * @param offset
+	 *            the offset into the buffer
+	 * @param count
+	 *            the number of bytes to receive
+	 * @return int the actual number of bytes sent
+	 * @exception SocketException
+	 *                if an error occurs while writing
+	 */
+	static native int sendStreamImpl(FileDescriptor fd, byte[] data,
+			int offset, int count) throws IOException;
+
+	/**
+	 * In the IP stack, read at most <code>count</code> bytes off the socket
+	 * into the <code>buffer</code>, at the <code>offset</code>. If the
+	 * timeout is zero, block indefinitely waiting for data, otherwise wait the
+	 * specified period (in milliseconds).
+	 * 
+	 * @param buffer
+	 *            the buffer to read into
+	 * @param offset
+	 *            the offset into the buffer
+	 * @param count
+	 *            the max number of bytes to read
+	 * @return int the actual number of bytes read
+	 * @exception IOException
+	 *                thrown if an error occurs while reading
+	 */
+
+	int read(byte[] buffer, int offset, int count) throws IOException {
+		if (shutdownInput)
+			return -1;
+		try {
+			int read = receiveStreamImpl(fd, buffer, offset, count,
+					receiveTimeout);
+			if (read == -1)
+				shutdownInput = true;
+			return read;
+		} catch (InterruptedIOException e) {
+			throw new SocketTimeoutException(e.getMessage());
+		}
+	}
+
+	/**
+	 * Set the nominated socket option.
+	 * 
+	 * @param optID
+	 *            the socket option to set
+	 * @param val
+	 *            the option value
+	 * @exception SocketException
+	 *                thrown if an error occurs while setting the option
+	 */
+
+	public abstract void setOption(int optID, Object val)
+			throws SocketException;
+
+	/**
+	 * Answers a string containing a concise, human-readable description of the
+	 * socket.
+	 * 
+	 * @return String the description
+	 */
+	public String toString() {
+		return new StringBuffer(100).append("Socket[addr=").append(
+				getInetAddress()).append(",port=").append(port).append(
+				",localport=").append(getLocalPort()).append("]").toString();
+	}
+
+	/**
+	 * In the IP stack, write at most <code>count</code> bytes on the socket
+	 * from the <code>buffer</code>, from the <code>offset</code>.
+	 * 
+	 * @param buffer
+	 *            the buffer to read into
+	 * @param offset
+	 *            the offset into the buffer
+	 * @param count
+	 *            the number of bytes to write
+	 * @return int the actual number of bytes written
+	 * @exception IOException
+	 *                thrown if an error occurs while writing
+	 */
+
+	int write(byte[] buffer, int offset, int count) throws IOException {
+		if (!streaming) {
+			PlainSocketImpl2.sendDatagramImpl2(fd, buffer, offset, count, port,
+					address);
+		}
+		return sendStreamImpl(fd, buffer, offset, count);
+	}
+
+	/**
+	 * Shutdown the input portion of the socket.
+	 */
+	protected void shutdownInput() throws IOException {
+		shutdownInput = true;
+		shutdownInputImpl(fd);
+	}
+
+	private native void shutdownInputImpl(FileDescriptor descriptor) throws IOException;
+
+	/**
+	 * Shutdown the output portion of the socket.
+	 */
+	protected void shutdownOutput() throws IOException {
+		shutdownOutputImpl(fd);
+	}
+
+	private native void shutdownOutputImpl(FileDescriptor descriptor)
+			throws IOException;
+
+	/**
+	 * Connect the socket to the host/port specified by the SocketAddress with a
+	 * specified timeout.
+	 * 
+	 * @param remoteAddr
+	 *            the remote machine address and port to connect to
+	 * @param timeout
+	 *            the millisecond timeout value, the connect will block
+	 *            indefinitely for a zero value.
+	 * 
+	 * @exception IOException
+	 *                if a problem occurs during the connect
+	 */
+	protected abstract void connect(SocketAddress remoteAddr, int timeout)
+			throws IOException;
+
+	/**
+	 * Answer if the socket supports urgent data. Subclasses should override
+	 * this method.
+	 * 
+	 * @return false, subclasses must override
+	 */
+	protected boolean supportsUrgentData() {
+		return false;
+	}
+
+	/**
+	 * Send the single byte of urgent data on the socket.
+	 * 
+	 * @param value
+	 *            the byte of urgent data
+	 * 
+	 * @exception IOException
+	 *                when an error occurs sending urgent data
+	 */
+	protected abstract void sendUrgentData(int value) throws IOException;
+
+	static native boolean supportsUrgentDataImpl(FileDescriptor fd);
+
+	static native boolean sendUrgentDataImpl(FileDescriptor fd, byte value);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketImplFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketImplFactory.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketImplFactory.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketImplFactory.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,31 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+/**
+ * This interface defines a factory for socket implementations. It is used by
+ * the classes <code>Socket</code> and <code>ServerSocket</code> to create
+ * socket implementations.
+ */
+public interface SocketImplFactory {
+	/**
+	 * Creates a new <code>SocketImpl</code> instance.
+	 * 
+	 * @return SocketImpl
+	 */
+	SocketImpl createSocketImpl();
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketInputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketInputStream.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketInputStream.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketInputStream.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,154 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import com.ibm.oti.util.Msg;
+
+/**
+ * The SocketInputStream supports the streamed reading of bytes from a socket.
+ * Multiple streams may be opened on a socket, so care should be taken to manage
+ * opened streams and coordinate read operations between threads.
+ */
+class SocketInputStream extends InputStream {
+
+	SocketImpl socket;
+
+	/**
+	 * Constructs a SocketInputStream for the <code>socket</code>. Read
+	 * operations are forwarded to the <code>socket</code>.
+	 * 
+	 * @param socket
+	 *            the socket to be read
+	 * @see Socket
+	 */
+	public SocketInputStream(SocketImpl socket) {
+		super();
+		this.socket = socket;
+	}
+
+	/**
+	 * Answer the number of bytes that may be read without blocking. Zero
+	 * indicates a read operation would block. This call itself does not block,
+	 * but may throw an IOException.
+	 * 
+	 * @return int the number of bytes that may be read without blocking
+	 * @exception IOException
+	 *                thrown if an error occurs during the test
+	 */
+	public int available() throws IOException {
+		return socket.available();
+	}
+
+	/**
+	 * Close the stream and the underlying socket.
+	 * 
+	 * @exception IOException
+	 *                thrown if an error occurs during the close
+	 */
+	public void close() throws IOException {
+		socket.close();
+		super.close();
+	}
+
+	/**
+	 * Read a single byte from the socket, answering the value as an
+	 * <code>int</code>. This call may block indefinitely, depending upon
+	 * whether data is available and whether the read timeout option has been
+	 * set on the socket. A value of -1 indicates 'end-of-file'.
+	 * 
+	 * @return int the value read
+	 * @exception IOException
+	 *                thrown if an error occurs during the read
+	 */
+	public int read() throws IOException {
+		byte[] buffer = new byte[1];
+		int result = socket.read(buffer, 0, 1);
+		return (-1 == result) ? result : buffer[0] & 0xFF;
+	}
+
+	/**
+	 * Read a buffer.length number of bytes from the socket, into the
+	 * <code>buffer</code>. This call may block indefinitely, depending upon
+	 * whether data is available and whether the read timeout option has been
+	 * set on the socket. The number of bytes actually read is returned; a value
+	 * of -1 indicates 'end-of-file'.
+	 * 
+	 * @param buffer
+	 *            the buffer to read into
+	 * @return int the number of bytes actually read
+	 * @exception IOException
+	 *                thrown if an error occurs during the read
+	 */
+	public int read(byte[] buffer) throws IOException {
+		return read(buffer, 0, buffer.length);
+	}
+
+	/**
+	 * Read a <code>count</code> number of bytes from the socket, into the
+	 * <code>buffer</code> at an <code>offset</code>. This call may block
+	 * indefinitely, depending upon whether data is available and whether the
+	 * read timeout option has been set on the socket. The number of bytes
+	 * actually read is returned; a value of -1 indicates 'end-of-file'.
+	 * 
+	 * @param buffer
+	 *            the buffer to read into
+	 * @param offset
+	 *            the offset into the buffer to start filling
+	 * @param count
+	 *            the maximum number of bytes to read
+	 * @return int the number of bytes actually read
+	 * @exception IOException,
+	 *                ArrayIndexOutOfBoundsException thrown if the argument
+	 *                bounds are incorrect or an error occurs during the read
+	 */
+	public int read(byte[] buffer, int offset, int count) throws IOException {
+		if (null == buffer)
+			throw new IOException(Msg.getString("K0047"));
+		
+		if (0 == count)
+			return 0;
+
+		if (0 > offset || offset >= buffer.length)
+			throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e"));
+		if (0 > count || offset + count > buffer.length)
+			throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f"));
+
+		return socket.read(buffer, offset, count);
+	}
+
+	/**
+	 * Skips <code>n</code> number of bytes in this InputStream. Subsequent
+	 * <code>read()</code>'s will not return these bytes unless
+	 * <code>reset()</code> is used. This method may perform multiple reads to
+	 * read <code>n</code> bytes. This implementation reads <code>n</code>
+	 * bytes into a temporary buffer.
+	 * 
+	 * @param n
+	 *            the number of bytes to skip.
+	 * @return the number of bytes actually skipped.
+	 * 
+	 * @exception java.io.IOException
+	 *                If the stream is already closed or another IOException
+	 *                occurs.
+	 */
+	public long skip(long n) throws IOException {
+		return (0 == n) ? 0 : super.skip(n);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketOptions.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketOptions.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketOptions.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketOptions.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,82 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+/**
+ * Defines the protocol to get & set Socket options.
+ */
+public interface SocketOptions {
+
+	public static int SO_LINGER = 128;
+
+	public static int SO_TIMEOUT = 4102;
+
+	public static int TCP_NODELAY = 1;
+
+	// For 5 and 6 see MulticastSocket
+
+	// For 7 see PlainDatagramSocketImpl
+	
+	public static int IP_MULTICAST_IF = 16;
+
+	public static int SO_BINDADDR = 15;
+
+	public static int SO_REUSEADDR = 4;
+
+	// 10 not currently used
+	
+	public static int SO_SNDBUF = 4097;
+
+	public static int SO_RCVBUF = 4098;
+
+	// For 13, see DatagramSocket
+	
+	public static int SO_KEEPALIVE = 8;
+
+	public static final int IP_TOS = 3;
+
+	public static final int IP_MULTICAST_LOOP = 18;
+
+	public static final int SO_BROADCAST = 32;
+
+	public static final int SO_OOBINLINE = 4099;
+
+	public static final int IP_MULTICAST_IF2 = 31;
+
+	/**
+	 * Answer the declared socket option.
+	 * 
+	 * @return Object the option value
+	 * @param optID
+	 *            the option identifier
+	 * @exception SocketException
+	 *                thrown if an error occurs getting the option
+	 */
+	public Object getOption(int optID) throws SocketException;
+
+	/**
+	 * Set the declared socket option to the value.
+	 * 
+	 * @param optID
+	 *            the option identifier
+	 * @param val
+	 *            the option value to be set
+	 * @exception SocketException
+	 *                thrown if an error occurs setting the option
+	 */
+	public void setOption(int optID, Object val) throws SocketException;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketOutputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketOutputStream.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketOutputStream.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketOutputStream.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,112 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+/**
+ * The SocketOutputStream supports the streamed writing of bytes to the socket.
+ * Multiple streams may be opened on a socket, so care should be taken to manage
+ * opened streams and coordinate write operations between threads.
+ */
+import java.io.IOException;
+import java.io.OutputStream;
+
+class SocketOutputStream extends OutputStream {
+
+	SocketImpl socket;
+
+	/**
+	 * Constructs a SocketOutputStream for the <code>socket</code>. Write
+	 * operations are forwarded to the <code>socket</code>.
+	 * 
+	 * @param socket
+	 *            the socket to be written
+	 * @see Socket
+	 */
+
+	public SocketOutputStream(SocketImpl socket) {
+		super();
+		this.socket = socket;
+	}
+
+	/**
+	 * Close the stream and the underlying socket.
+	 * 
+	 * @exception IOException
+	 *                thrown if an error occurs during the close
+	 */
+
+	public void close() throws IOException {
+		socket.close();
+		super.close();
+	}
+
+	/**
+	 * Write the <code>buffer</code> to the socket.
+	 * 
+	 * @param buffer
+	 *            the buffer to write
+	 * @exception IOException
+	 *                thrown if an error occurs during the write
+	 */
+	public void write(byte[] buffer) throws IOException {
+		socket.write(buffer, 0, buffer.length);
+	}
+
+	/**
+	 * Write the <code>count</code> number of bytes from the
+	 * <code>buffer</code> to the socket, starting at <code>offset</code>.
+	 * 
+	 * @param buffer
+	 *            the buffer to write
+	 * @param offset
+	 *            the offset in buffer to start writing
+	 * @param count
+	 *            the number of bytes to write
+	 * @exception IOException,
+	 *                IndexOutOfBoundsException thrown if an error occurs during
+	 *                the write
+	 */
+	public void write(byte[] buffer, int offset, int count) throws IOException {
+		// avoid int overflow
+		if (buffer != null) {
+			if (0 <= offset && offset <= buffer.length && 0 <= count
+					&& count <= buffer.length - offset) {
+				socket.write(buffer, offset, count);
+			} else
+				throw new ArrayIndexOutOfBoundsException(com.ibm.oti.util.Msg
+						.getString("K002f"));
+		} else
+			throw new NullPointerException(com.ibm.oti.util.Msg
+					.getString("K0047"));
+	}
+
+	/**
+	 * Write a single byte, the lowest-order byte from an <code>int</code> to
+	 * the socket.
+	 * 
+	 * @param oneByte
+	 *            the value to write
+	 * @exception IOException
+	 *                thrown if an error occurs during the write
+	 */
+	public void write(int oneByte) throws IOException {
+		byte[] buffer = new byte[1];
+		buffer[0] = (byte) (oneByte & 0xFF);
+
+		socket.write(buffer, 0, 1);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketPermission.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketPermission.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketPermission.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketPermission.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,433 @@
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.security.Permission;
+import java.security.PermissionCollection;
+
+import com.ibm.oti.util.Inet6Util;
+import com.ibm.oti.util.Msg;
+
+/**
+ * SocketPermissions represent permission to access resources via sockets. The
+ * name of the permission should be either the (possibly wildcarded (eg.
+ * *.company.com)) DNS style name of the of the host for which access is being
+ * requested, or its IP address in standard nn.nn.nn.nn ("dot") notation. The
+ * action list can be made up of any of the following:
+ * <dl>
+ * <dt>connect</dt>
+ * <dd>requests permission to connect to the host</dd>
+ * <dt>listen</dt>
+ * <dd>requests permission to listen for connections from the host</dd>
+ * <dt>accept</dt>
+ * <dd>requests permission to accept connections from the host</dd>
+ * <dt>resolve</dt>
+ * <dd>requests permission to resolve the host name</dd>
+ * </dl>
+ * Note that "resolve" is implied when any (or none) of the others are present.
+ * <p>
+ * Access to a particular port can be requested by appending a colon and a
+ * single digit to the name (eg. "*.company.com:7000"). A range of port numbers
+ * can also be specified, by appending a pattern of the form <low>-<high> where
+ * <low> and <high> are valid port numbers. If either <low> or <high> is omitted
+ * it is equivalent to entering the lowest or highest possible value
+ * respectively. For example:
+ * 
+ * <pre>
+ * SocketPermission(&quot;www.company.com:7000-&quot;, &quot;connect&quot;, &quot;accept&quot;)
+ * </pre>
+ * 
+ * represents permission to connect to and accept connections from
+ * www.company.com on ports in the range 7000 to 65535.
+ * 
+ */
+public final class SocketPermission extends Permission implements Serializable {
+
+	static final long serialVersionUID = -7204263841984476862L;
+
+	// Bit masks for each of the possible actions
+	static final int SP_CONNECT = 1;
+
+	static final int SP_LISTEN = 2;
+
+	static final int SP_ACCEPT = 4;
+
+	static final int SP_RESOLVE = 8;
+
+	// list of actions permitted for socket permission in order, indexed by mask
+	// value
+	private static final String[] actionNames = { "", "connect", "listen", "",
+			"accept", "", "", "", "resolve" };
+
+	// If a wildcard is present store the information
+	private transient boolean isPartialWild = false;
+
+	private transient boolean isWild = false;
+
+	// The highest port number
+	private static final int HIGHEST_PORT = 65535;
+
+	// The lowest port number
+	private static final int LOWEST_PORT = 0;
+
+	transient String hostName; // Host name as returned by InetAddress
+
+	transient String ipString; // IP address as returned by InetAddress
+
+	transient boolean resolved = false; // IP address has been resolved
+
+	// the port range;
+	transient int portMin = LOWEST_PORT;
+
+	transient int portMax = HIGHEST_PORT;
+
+	private String actions; // List of all actions allowed by this permission
+
+	transient int actionsMask = SP_RESOLVE;
+
+	/**
+	 * Constructs an instance of this class. The host name can be a DNS name, an
+	 * individual hostname, an ip address or the empty string which implies
+	 * localhost. The port or port range is optional.
+	 * <p>
+	 * The action list is a comma-seperated list which can consist of "connect",
+	 * "listen", "accept", and "resolve". They are case-insensitive and can be
+	 * put together in any order. "resolve" is always implied.
+	 * 
+	 * @param host
+	 *            java.lang.String the host name
+	 * @param action
+	 *            java.lang.String the action string
+	 */
+	public SocketPermission(String host, String action) {
+		super(host.equals("") ? "localhost" : host);
+		hostName = getHostString(host);
+		if (action == null)
+			throw new NullPointerException();
+		if (action.equals(""))
+			throw new IllegalArgumentException();
+
+		setActions(action);
+		actions = toCanonicalActionString(action);
+		parsePort(host); // Use host since we are only checking for port
+		// presence
+	}
+
+	/**
+	 * Compares the argument to the receiver, and answers true if they represent
+	 * the equal objects using a class specific comparison.
+	 * <p>
+	 * 
+	 * @param o
+	 *            the object to compare with this object
+	 * @return <code>true</code> if the object is the same as this object
+	 *         <code>false</code> if it is different from this object
+	 * @see #hashCode
+	 */
+	public boolean equals(Object o) {
+		if (this == o)
+			return true;
+		if (this.getClass() != o.getClass())
+			return false;
+		SocketPermission sp = (SocketPermission) o;
+		if (!hostName.equals(sp.hostName)) {
+			if (getIPString() == null || !ipString.equals(sp.getIPString()))
+				return false;
+		}
+		if (this.portMin != sp.portMin)
+			return false;
+		if (this.portMax != sp.portMax)
+			return false;
+		return this.actionsMask == sp.actionsMask;
+	}
+
+	/**
+	 * Answers an integer hash code for the receiver. Any two objects which
+	 * answer <code>true</code> when passed to <code>.equals</code> must
+	 * answer the same value for this method.
+	 * 
+	 * @return int the receiver's hash.
+	 * 
+	 * @see #equals
+	 */
+	public int hashCode() {
+		return hostName.hashCode() ^ actionsMask ^ portMin ^ portMax;
+	}
+
+	/**
+	 * Answers the canonical action list of this SocketPermission in the order:
+	 * connect, listen, accept, resolve.
+	 * 
+	 * @return java.lang.String the canonical action list
+	 */
+	public String getActions() {
+		return actions;
+	}
+
+	/**
+	 * Stores the actions for this permission as a bit field
+	 * 
+	 * @param actions
+	 *            java.lang.String the action list
+	 */
+	private void setActions(String actions) throws IllegalArgumentException {
+		if (actions.equals(""))
+			return;
+		boolean parsing = true;
+		String action;
+		StringBuffer sb = new StringBuffer();
+		int pos = 0, length = actions.length();
+		while (parsing) {
+			char c;
+			sb.setLength(0);
+			while (pos < length && (c = actions.charAt(pos++)) != ',')
+				sb.append(c);
+			if (pos == length)
+				parsing = false;
+			action = sb.toString().trim().toLowerCase();
+			if (action.equals(actionNames[SP_CONNECT]))
+				actionsMask |= SP_CONNECT;
+			else if (action.equals(actionNames[SP_LISTEN]))
+				actionsMask |= SP_LISTEN;
+			else if (action.equals(actionNames[SP_ACCEPT]))
+				actionsMask |= SP_ACCEPT;
+			else if (action.equals(actionNames[SP_RESOLVE])) {
+			} else
+				throw new IllegalArgumentException(Msg.getString("K0048",
+						action));
+		}
+	}
+
+	/**
+	 * Check the permission to see if the actions requested by the argument
+	 * permission are permissable. All argument permission actions, host and
+	 * port must be implied by this permission in order to return true. This
+	 * permission may imply additional actions etc. not present in the argument
+	 * permission.
+	 * 
+	 * @return boolean true if this permission implies <code>p</code>, and
+	 *         false otherwise
+	 * @param p
+	 *            java.security.Permission the other socket permission
+	 */
+	public boolean implies(Permission p) {
+		SocketPermission sp;
+		try {
+			sp = (SocketPermission) p;
+		} catch (ClassCastException e) {
+			return false;
+		}
+
+		// tests if the action list of p is the subset of the one of the
+		// receiver
+		if ((actionsMask & sp.actionsMask) != sp.actionsMask)
+			return false;
+
+		// only check the port range if the action string of the current object
+		// is not "resolve"
+		if (!p.getActions().equals("resolve"))
+			if ((sp.portMin < this.portMin) || (sp.portMax > this.portMax))
+				return false;
+
+		// Verify the host is valid
+		return checkHost(sp);
+	}
+
+	/**
+	 * Answers a PermissionCollection for storing SocketPermission objects.
+	 * 
+	 * @return java.security.PermissionCollection a permission collection
+	 */
+	public PermissionCollection newPermissionCollection() {
+		return new SocketPermissionCollection();
+	}
+
+	/**
+	 * Parses the port string into the lower and higher bound of the port range.
+	 * 
+	 */
+	private void parsePort(String hostString) throws IllegalArgumentException {
+		int negidx = -1;
+		int len = -1;
+		int lastIdx = hostString.lastIndexOf(':');
+		int idx = hostString.indexOf(':');
+		int endOfIPv6Addr = hostString.lastIndexOf(']');
+		if ((endOfIPv6Addr == -1) && (idx != lastIdx)) {
+			// there are no square braces, but there are more than one ':' which
+			// implies an IPv6 address with no port, or an illegal argument
+			// check for valid IPv6 address
+			if (Inet6Util.isValidIP6Address(hostString)) {
+				return;
+			}
+			// throw an invalid argument exception
+			throw new IllegalArgumentException(Msg.getString("K004a"));
+		}
+		// if there is a colon and it occurs after the ']' then there is a port
+		// to be parsed
+		if ((lastIdx > -1) && (lastIdx > endOfIPv6Addr)) {
+			try {
+				len = hostString.length();
+				// look for a '-' after the colon
+				negidx = hostString.indexOf('-', lastIdx);
+				if (negidx == lastIdx + 1) {
+					portMax = Integer.parseInt(hostString.substring(
+							lastIdx + 2, len));
+				} else {
+					// A port range was provided
+					if (negidx != -1 && (negidx != len - 1)) {
+						portMin = Integer.parseInt(hostString.substring(
+								lastIdx + 1, negidx));
+						portMax = Integer.parseInt(hostString.substring(
+								negidx + 1, len));
+					} else {
+						if (negidx == -1) {
+							portMin = Integer.parseInt(hostString.substring(
+									lastIdx + 1, len));
+							portMax = portMin;
+						} else {
+							portMin = Integer.parseInt(hostString.substring(
+									lastIdx + 1, negidx));
+						}
+					}
+				}
+				if (portMax < portMin)
+					throw new IllegalArgumentException(Msg.getString("K0049"));
+
+			} catch (NumberFormatException e) {
+				throw new IllegalArgumentException(Msg.getString("K004a"));
+			}
+		}
+	}
+
+	/**
+	 * Creates a canonical action list.
+	 * 
+	 * @param action
+	 *            java.lang.String
+	 * 
+	 * @return java.lang.String
+	 */
+	private String toCanonicalActionString(String action) {
+		if (action == null || action.equals("") || actionsMask == SP_RESOLVE)
+			return actionNames[SP_RESOLVE]; // If none specified return the
+		// implied action resolve
+		StringBuffer sb = new StringBuffer();
+		if ((actionsMask & SP_CONNECT) == SP_CONNECT) {
+			sb.append(',');
+			sb.append(actionNames[SP_CONNECT]);
+		}
+		if ((actionsMask & SP_LISTEN) == SP_LISTEN) {
+			sb.append(',');
+			sb.append(actionNames[SP_LISTEN]);
+		}
+		if ((actionsMask & SP_ACCEPT) == SP_ACCEPT) {
+			sb.append(',');
+			sb.append(actionNames[SP_ACCEPT]);
+		}
+		sb.append(',');
+		sb.append(actionNames[SP_RESOLVE]);// Resolve is always implied
+		// Don't copy the first ','.
+		return actions = sb.substring(1, sb.length());
+	}
+
+	private String getIPString() {
+		if (!resolved) {
+			try {
+				ipString = InetAddress.getHostNameInternal(hostName);
+			} catch (UnknownHostException e) {
+			}
+			resolved = true;
+		}
+		return ipString;
+	}
+
+	private String getHostString(String host) throws IllegalArgumentException {
+		int idx = -1;
+		idx = host.indexOf(':');
+		isPartialWild = (host.length() > 0 && host.charAt(0) == '*');
+		if (isPartialWild) {
+			resolved = true;
+			isWild = (host.length() == 1);
+			if (isWild) {
+				return host;
+			}
+			if (idx > -1) {
+				host = host.substring(0, idx);
+			}
+			return host.toLowerCase();
+		}
+
+		int lastIdx = host.lastIndexOf(':');
+		if ((idx > -1) && (idx == lastIdx)) {
+			host = host.substring(0, idx);
+		} else {
+			// likely host is or contains an IPv6 address
+			if (lastIdx != -1) {
+				if (Inet6Util.isValidIP6Address(host)) {
+					return host.toLowerCase();
+				} else if (Inet6Util.isValidIP6Address(host.substring(0,
+						lastIdx))) {
+					host = host.substring(0, lastIdx);
+				} else {
+					throw new IllegalArgumentException(Msg.getString("K004a"));
+				}
+			}
+		}
+		return host.toLowerCase();
+	}
+
+	/*
+	 * Determines whether or not this permission could refer to the same host as
+	 * sp
+	 */
+	boolean checkHost(SocketPermission sp) {
+		if (isPartialWild) {
+			if (isWild)
+				return true; // Match on any host
+			int length = hostName.length() - 1;
+			return sp.hostName.regionMatches(sp.hostName.length() - length,
+					hostName, 1, length);
+		}
+		// The ipString may not be the same, some hosts resolve to
+		// multiple ips
+		return (getIPString() != null && ipString.equals(sp.getIPString()))
+				|| hostName.equals(sp.hostName);
+	}
+
+	private void writeObject(ObjectOutputStream stream) throws IOException {
+		stream.defaultWriteObject();
+	}
+
+	private void readObject(ObjectInputStream stream) throws IOException,
+			ClassNotFoundException {
+		stream.defaultReadObject();
+		// Initialize locals
+		isPartialWild = false;
+		isWild = false;
+		portMin = LOWEST_PORT;
+		portMax = HIGHEST_PORT;
+		actionsMask = SP_RESOLVE;
+		hostName = getHostString(getName());
+		parsePort(getName());
+		setActions(actions);
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketPermissionCollection.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketPermissionCollection.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketPermissionCollection.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketPermissionCollection.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,85 @@
+/* Copyright 1998, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.security.Permission;
+import java.security.PermissionCollection;
+import java.util.Vector;
+
+/**
+ * SocketPermissionCollection is a class which holds a collection of
+ * SocketPermission objects and can answer a boolean indicating whether or not a
+ * specific permissions is implied by a SocketPermissionCollection.
+ */
+final class SocketPermissionCollection extends PermissionCollection {
+	
+	static final long serialVersionUID = 2787186408602843674L;
+
+	public Vector permissions = new Vector();
+
+	// Constructs a new instance of this class.
+	public SocketPermissionCollection() {
+		super();
+	}
+
+	// Adds the argument to the collection.
+	public void add(Permission permission) {
+		if (isReadOnly())
+			throw new IllegalStateException();
+		if (!(permission instanceof SocketPermission))
+			throw new IllegalArgumentException(permission.toString());
+		permissions.addElement(permission);
+	}
+
+	// Answers an enumeration of the permissions
+	public java.util.Enumeration elements() {
+		return permissions.elements();
+	}
+
+	/** Answers if this permission collection implies <code>permission</code>.
+	 * Basically it tests
+	 * if <code>permission</code> is the subset of this collection.
+	 * */
+	public boolean implies(Permission permission) {
+		if (!(permission instanceof SocketPermission))
+			return false;
+		SocketPermission sp, argPerm = (SocketPermission) permission;
+		int pmask = argPerm.actionsMask;
+		int allMask = 0;
+		int i = 0, count = permissions.size();
+		while ((i < count) && ((allMask & pmask) != pmask)) {
+			sp = (SocketPermission) permissions.elementAt(i);
+			if (sp.checkHost(argPerm)) {
+				if ((sp.actionsMask & SocketPermission.SP_RESOLVE) == SocketPermission.SP_RESOLVE)
+					allMask |= SocketPermission.SP_RESOLVE;
+				// Only set flags if the port range and host can be implied
+				if ((argPerm.portMin >= sp.portMin)
+						&& (argPerm.portMax <= sp.portMax)) {
+					if ((sp.actionsMask & SocketPermission.SP_CONNECT) == SocketPermission.SP_CONNECT)
+						allMask |= SocketPermission.SP_CONNECT;
+					if ((sp.actionsMask & SocketPermission.SP_ACCEPT) == SocketPermission.SP_ACCEPT)
+						allMask |= SocketPermission.SP_ACCEPT;
+					if ((sp.actionsMask & SocketPermission.SP_LISTEN) == SocketPermission.SP_LISTEN)
+						allMask |= SocketPermission.SP_LISTEN;
+				}
+			}
+			++i;
+		}
+
+		return (allMask & pmask) == pmask;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketTimeoutException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketTimeoutException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketTimeoutException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/SocketTimeoutException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,40 @@
+/* Copyright 2004, 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.InterruptedIOException;
+
+public class SocketTimeoutException extends InterruptedIOException {
+
+	/**
+	 * Constructs a new instance of this class with its walkback filled in.
+	 */
+	public SocketTimeoutException() {
+		super();
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public SocketTimeoutException(String detailMessage) {
+		super(detailMessage);
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Socks4Message.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Socks4Message.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Socks4Message.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/luni/src/java/net/Socks4Message.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,251 @@
+/* Copyright 2000, 2003 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.net;
+
+
+import java.io.UnsupportedEncodingException;
+
+class Socks4Message {
+	protected byte[] buffer;
+
+	final static private int SOCKS_VERSION = 4;
+
+	final static public int COMMAND_CONNECT = 1;
+
+	final static public int COMMAND_BIND = 2;
+
+	final static public int RETURN_SUCCESS = 90;
+
+	final static public int RETURN_FAILURE = 91;
+
+	final static public int RETURN_CANNOT_CONNECT_TO_IDENTD = 92;
+
+	final static public int RETURN_DIFFERENT_USER_IDS = 93;
+
+	final static protected int INDEX_VERSION = 0;
+
+	final static private int INDEX_COMMAND = 1;
+
+	final static private int INDEX_PORT = 2;
+
+	final static private int INDEX_IP = 4;
+
+	final static private int INDEX_USER_ID = 8;
+
+	final static private int BUFFER_LENGTH = 256;
+
+	final static public int REPLY_LENGTH = 8;
+
+	final static private int MAX_USER_ID_LENGTH = BUFFER_LENGTH - INDEX_USER_ID;
+
+	public Socks4Message() {
+		super();
+		buffer = new byte[BUFFER_LENGTH];
+		setVersionNumber(SOCKS_VERSION);
+	}
+
+	/**
+	 * Get the request's command or result.
+	 */
+	public int getCommandOrResult() {
+		return buffer[INDEX_COMMAND];
+	}
+
+	/**
+	 * Set the request's command or result.
+	 */
+	public void setCommandOrResult(int command) {
+		buffer[INDEX_COMMAND] = (byte) command;
+	}
+
+	/**
+	 * Answer the request's port number.
+	 */
+	public int getPort() {
+		return getInt16(INDEX_PORT);
+	}
+
+	/**
+	 * Set the request's port number.
+	 */
+	public void setPort(int port) {
+		setInt16(INDEX_PORT, port);
+	}
+
+	/*
+	 * Answer the IP address of the request as an integer.
+	 */
+	public int getIP() {
+		return getInt32(INDEX_IP);
+	}
+
+	/**
+	 * Set the IP address. This expects an array of four bytes in host order.
+	 */
+	public void setIP(byte[] ip) {
+		buffer[INDEX_IP] = ip[0];
+		buffer[INDEX_IP + 1] = ip[1];
+		buffer[INDEX_IP + 2] = ip[2];
+		buffer[INDEX_IP + 3] = ip[3];
+	}
+
+	/**
+	 * Answer the user id for authentication.
+	 */
+	public String getUserId() {
+		return getString(INDEX_USER_ID, MAX_USER_ID_LENGTH);
+	}
+
+	/**
+	 * Set the user id for authentication.
+	 */
+	public void setUserId(String id) {
+		setString(INDEX_USER_ID, MAX_USER_ID_LENGTH, id);
+	}
+
+	/**
+	 */
+	public String toString() {
+		StringBuffer buf = new StringBuffer("");
+		buf.append("Version: ");
+		buf.append(Integer.toHexString(getVersionNumber()));
+		buf.append(" Command: ");
+		buf.append(Integer.toHexString(getCommandOrResult()));
+		buf.append(" Port: ");
+		buf.append(getPort());
+		buf.append(" IP: ");
+		buf.append(Integer.toHexString(getIP()));
+		buf.append(" User ID: ");
+		buf.append(getUserId());
+		return buf.toString();
+	}
+
+	/**
+	 * Answer the total number of bytes used for the request. This method
+	 * searches for the end of the user id, then searches for the end of the
+	 * password and returns the final index as the requests length.
+	 */
+	public int getLength() {
+		int index = 0;
+
+		// Look for the end of the user id.
+		for (index = INDEX_USER_ID; buffer[index] != 0; index++) {
+			/*
+			 * Finds the end of the user id by searching for the null
+			 * termination of the user id string.
+			 */
+		}
+
+		// Increment the index to include the NULL character in the length;
+		index++;
+		return index;
+	}
+
+	/**
+	 * Answer an error string corresponding to the given error value.
+	 */
+	public String getErrorString(int error) {
+		switch (error) {
+		case RETURN_FAILURE:
+			return com.ibm.oti.util.Msg.getString("K00cd");
+		case RETURN_CANNOT_CONNECT_TO_IDENTD:
+			return com.ibm.oti.util.Msg.getString("K00ce");
+		case RETURN_DIFFERENT_USER_IDS:
+			return com.ibm.oti.util.Msg.getString("K00cf");
+		default:
+			return com.ibm.oti.util.Msg.getString("K00d0");
+		}
+	}
+
+	/**
+	 * Answer the message's byte buffer.
+	 */
+	public byte[] getBytes() {
+		return buffer;
+	}
+
+	/**
+	 * Get a 16 bit integer from the buffer at the offset given.
+	 */
+	private int getInt16(int offset) {
+		return (((buffer[offset] & 0xFF) << 8) + (buffer[offset + 1] & 0xFF));
+	}
+
+	/**
+	 * Get a 32 bit integer from the buffer at the offset given.
+	 */
+	private int getInt32(int offset) {
+		return ((buffer[offset + 3] & 0xFF)
+				+ ((buffer[offset + 2] & 0xFF) << 8)
+				+ ((buffer[offset + 1] & 0xFF) << 16) + ((buffer[offset + 0] & 0xFF) << 24));
+	}
+
+	/**
+	 * Get a String from the buffer at the offset given. The method reads until
+	 * it encounters a null value or reaches the maxLength given.
+	 */
+	private String getString(int offset, int maxLength) {
+		int index = offset;
+		int lastIndex = index + maxLength;
+		String result;
+
+		while (index < lastIndex && (buffer[index] != 0))
+			index++;
+		try {
+			result = new String(buffer, offset, index - offset, "ISO8859_1");
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e.toString());
+		}
+		return result;
+	}
+
+	/**
+	 * Answer the SOCKS version number. Should always be 4.
+	 */
+	private int getVersionNumber() {
+		return buffer[INDEX_VERSION];
+	}
+
+	/**
+	 * Put a 16 bit integer into the buffer at the offset given.
+	 */
+	private void setInt16(int offset, int value) {
+		buffer[offset] = (byte) (value >>> 8 & 0xFF);
+		buffer[offset + 1] = (byte) (value & 0xFF);
+	}
+
+	/**
+	 * Put a string into the buffer at the offset given.
+	 */
+	private void setString(int offset, int maxLength, String theString) {
+		byte[] stringBytes;
+		try {
+			stringBytes = theString.getBytes("ISO8859_1");
+		} catch (UnsupportedEncodingException e) {
+			throw new RuntimeException(e.toString());
+		}
+		int length = Math.min(stringBytes.length, maxLength);
+		System.arraycopy(stringBytes, 0, buffer, offset, length);
+		buffer[offset + length] = 0;
+	}
+
+	/**
+	 * Set the SOCKS version number. This should always be 4.
+	 */
+	private void setVersionNumber(int number) {
+		buffer[INDEX_VERSION] = (byte) number;
+	}
+}



Mime
View raw message