Index: gnu/java/net/PlainDatagramSocketImpl.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/net/PlainDatagramSocketImpl.java,v retrieving revision 1.5 diff -u -b -B -r1.5 PlainDatagramSocketImpl.java --- gnu/java/net/PlainDatagramSocketImpl.java 28 Nov 2003 23:43:18 -0000 1.5 +++ gnu/java/net/PlainDatagramSocketImpl.java 19 Mar 2004 08:32:44 -0000 @@ -1,5 +1,5 @@ /* PlainDatagramSocketImpl.java -- Default DatagramSocket implementation - Copyright (C) 1998, 1999, 2001, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2001, 2003, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -60,8 +60,8 @@ * It makes native calls to C routines that implement BSD style * SOCK_DGRAM sockets in the AF_INET family. * - * @author Aaron M. Renn
- * @author Warren Levy + * @author Aaron M. Renn (address@hidden) + * @author Warren Levy (address@hidden) */ public final class PlainDatagramSocketImpl extends DatagramSocketImpl { @@ -157,10 +157,10 @@ { Object obj = getOption(IP_TTL); - if (!(obj instanceof Integer)) + if (! (obj instanceof Integer)) throw new IOException("Internal Error"); - return(((Integer)obj).intValue()); + return ((Integer) obj).intValue(); } /** Index: gnu/java/net/PlainSocketImpl.java =================================================================== RCS file: /cvsroot/classpath/classpath/gnu/java/net/PlainSocketImpl.java,v retrieving revision 1.7 diff -u -b -B -r1.7 PlainSocketImpl.java --- gnu/java/net/PlainSocketImpl.java 3 Mar 2004 22:27:25 -0000 1.7 +++ gnu/java/net/PlainSocketImpl.java 19 Mar 2004 08:32:44 -0000 @@ -195,8 +195,7 @@ * * @param stream true for a stream socket, false for a datagram socket */ - protected native synchronized void create(boolean stream) - throws IOException; + protected native synchronized void create(boolean stream) throws IOException; /** * Connects to the remote hostname and port specified as arguments. @@ -206,9 +205,9 @@ * * @exception IOException If an error occurs */ - protected synchronized void connect (String host, int port) throws IOException + protected synchronized void connect(String host, int port) throws IOException { - connect (InetAddress.getByName (host), port); + connect(InetAddress.getByName(host), port); } /** @@ -219,22 +218,27 @@ * * @exception IOException If an error occurs */ - protected native void connect(InetAddress addr, int port) - throws IOException; + protected native void connect(InetAddress addr, int port) throws IOException; - protected synchronized void connect(SocketAddress address, int timeout) - throws IOException + /** + * Connects to the remote socket address with a specified timeout. + * + * @param timeout The timeout to use for this connect, 0 means infinite. + * + * @exception IOException If an error occurs + */ + protected synchronized void connect(SocketAddress address, int timeout) throws IOException { InetSocketAddress sockAddr = (InetSocketAddress) address; InetAddress addr = sockAddr.getAddress(); if (addr == null) - throw new IllegalArgumentException ("address is unresolved: " + sockAddr); + throw new IllegalArgumentException("address is unresolved: " + sockAddr); int port = sockAddr.getPort(); if (timeout < 0) - throw new IllegalArgumentException ("negative timeout"); + throw new IllegalArgumentException("negative timeout"); Object oldTimeoutObj = null; @@ -304,7 +308,7 @@ * * @exception IOException If an error occurs */ - protected native void close () throws IOException; + protected native void close() throws IOException; public void sendUrgentData(int data) { @@ -344,7 +348,7 @@ protected synchronized InputStream getInputStream() throws IOException { if (in == null) - in = new SocketInputStream (this); + in = new SocketInputStream(); return in; } @@ -360,7 +364,7 @@ protected synchronized OutputStream getOutputStream() throws IOException { if (out == null) - out = new SocketOutputStream (this); + out = new SocketOutputStream(); return out; } @@ -368,59 +372,18 @@ /** * This class contains an implementation ofInputStream
for
* sockets. It in an internal only class used by PlainSocketImpl
.
+ *
+ * @author Nic Ferrier
*/
final class SocketInputStream
extends InputStream
{
/**
- * The PlainSocketImpl object this stream is associated with
- */
- private PlainSocketImpl impl;
-
- /**
- * Builds an instance of this class from a PlainSocketImpl object
- */
- protected SocketInputStream (PlainSocketImpl impl)
- {
- this.impl = impl;
- }
-
- /**
* Returns the number of bytes available to be read before blocking
*/
public int available() throws IOException
{
- return impl.available();
- }
-
- /**
- * Determines if "mark" functionality is supported on this stream. For
- * sockets, this is always false. Note that the superclass default is
- * false, but it is overridden out of safety concerns and/or paranoia.
- */
- public boolean markSupported()
- {
- return false;
- }
-
- /**
- * Do nothing mark method since we don't support this functionality. Again,
- * overriding out of paranoia.
- *
- * @param readlimit In theory, the number of bytes we can read before the mark becomes invalid
- */
- public void mark (int readlimit)
- {
- }
-
- /**
- * Since we don't support mark, this method always throws an exception
- *
- * @exception IOException Everytime since we don't support this functionality
- */
- public void reset() throws IOException
- {
- throw new IOException ("Socket InputStreams do not support mark/reset");
+ return PlainSocketImpl.this.available();
}
/**
@@ -430,7 +393,7 @@
*/
public void close() throws IOException
{
- impl.close();
+ PlainSocketImpl.this.close();
}
/**
@@ -443,25 +406,29 @@
public int read() throws IOException
{
byte buf[] = new byte [1];
- int bytes_read = read (buf, 0, buf.length);
+ int bytes_read = read(buf, 0, 1);
- if (bytes_read != -1)
- return buf[0] & 0xFF;
- else
+ if (bytes_read == -1)
return -1;
+
+ return buf[0] & 0xFF;
}
/**
* Reads up to len bytes of data into the caller supplied buffer starting
* at offset bytes from the start of the buffer
*
+ * @param buf The buffer
+ * @param offset Offset into the buffer to start reading from
+ * @param len The number of bytes to read
+ *
* @return The number of bytes actually read or -1 if end of stream
*
* @exception IOException If an error occurs.
*/
public int read (byte[] buf, int offset, int len) throws IOException
{
- int bytes_read = impl.read (buf, offset, len);
+ int bytes_read = PlainSocketImpl.this.read (buf, offset, len);
if (bytes_read == 0)
return -1;
@@ -475,24 +442,13 @@
* OutputStream
subclass returned by its
* getOutputStream method
. It expects only to be used in that
* context.
+ *
+ * @author Nic Ferrier
*/
final class SocketOutputStream
extends OutputStream
{
/**
- * The PlainSocketImpl object this stream is associated with
- */
- private PlainSocketImpl impl;
-
- /**
- * Build an instance of this class from a PlainSocketImpl object
- */
- protected SocketOutputStream (PlainSocketImpl impl)
- {
- this.impl = impl;
- }
-
- /**
* This method closes the stream and the underlying socket connection. This
* action also effectively closes any other InputStream or OutputStream
* object associated with the connection.
@@ -501,17 +457,7 @@
*/
public void close() throws IOException
{
- impl.close();
- }
-
- /**
- * Hmmm, we don't seem to have a flush() method in Socket impl, so just
- * return for now, but this might need to be looked at later.
- *
- * @exception IOException Can't happen
- */
- public void flush() throws IOException
- {
+ PlainSocketImpl.this.close();
}
/**
@@ -521,13 +467,10 @@
*
* @exception IOException If an error occurs
*/
- public void write (int b) throws IOException
+ public void write(int b) throws IOException
{
- byte buf[] = new byte [1];
- Integer i = new Integer (b);
-
- buf [0] = i.byteValue();
- write (buf, 0, buf.length);
+ byte buf[] = { (byte) b };
+ write(buf, 0, 1);
}
/**
@@ -537,10 +480,12 @@
* @param buf The buffer
* @param offset Offset into the buffer to start writing from
* @param len The number of bytes to write
+ *
+ * @exception IOException If an error occurs.
*/
public void write (byte[] buf, int offset, int len) throws IOException
{
- impl.write (buf, offset, len);
+ PlainSocketImpl.this.write (buf, offset, len);
}
}
}