Commit 9b7fe786 by Bryce McKinlay Committed by Bryce McKinlay

PlainSocketImpl.java (read): Remove declaration.

	* gnu/java/net/PlainSocketImpl.java (read): Remove declaration.
	(write): Likewise.
	(SocketInputStream, SocketOutputStream): Declare `read' and `write'
	native. Remove implementations which called back into
	PlainSocketImpl.
	Remove unneccessary overridden methods.
	* gnu/java/net/natPlainSocketImplNoNet.cc (read): Move
	implementation
	to inner class PlainSocketImpl.SocketInputStream.
	(write): Likewise.
	* gnu/java/net/natPlainSocketImplPosix.cc: As above.
	* gnu/java/net/natPlainSocketImplWin32.cc: As above.
	* gnu/java/net/SocketInputStream.java: Remove unused file.
	* gnu/java/net/SocketOutputStream.java: Likewise.
	* Makefile.am: Build CNI headers for PlainSocketImpl.SocketInputStream
	and SocketOutputStream.
	* Makefile.in: Rebuilt.

From-SVN: r71724
parent b9f2972f
2003-09-24 Bryce McKinlay <bryce@mckinlay.net.nz>
* gnu/java/net/PlainSocketImpl.java (read): Remove declaration.
(write): Likewise.
(SocketInputStream): Declare `read' and `write' methods native.
Remove implementations which called back into PlainSocketImpl.
Remove unneccessary overridden methods.
* gnu/java/net/natPlainSocketImplNoNet.cc (read): Move implementation
to inner class PlainSocketImpl.SocketInputStream.
(write): Likewise.
* gnu/java/net/natPlainSocketImplPosix.cc: As above.
* gnu/java/net/natPlainSocketImplWin32.cc: As above.
* gnu/java/net/SocketInputStream.java: Remove unused file.
* gnu/java/net/SocketOutputStream.java: Likewise.
* Makefile.am: Build CNI headers for PlainSocketImpl.SocketInputStream
and SocketOutputStream.
* Makefile.in: Rebuilt.
2003-09-23 Nathanael Nerode <neroden@gcc.gnu.org>
* java/lang/System.java: Add GCJ LOCAL note about encoding aliases.
......
......@@ -464,7 +464,9 @@ ordinary_nat_headers = $(ordinary_java_source_files:.java=.h) \
inner_nat_headers = java/io/ObjectOutputStream$$PutField.h \
java/io/ObjectInputStream$$GetField.h \
java/lang/reflect/Proxy$$ProxyData.h \
java/lang/reflect/Proxy$$ProxyType.h
java/lang/reflect/Proxy$$ProxyType.h \
gnu/java/net/PlainSocketImpl$$SocketInputStream.h \
gnu/java/net/PlainSocketImpl$$SocketOutputStream.h
nat_headers = $(ordinary_nat_headers) $(inner_nat_headers)
......@@ -549,6 +551,14 @@ java/io/ObjectOutputStream$$PutField.h: java/io/ObjectOutputStream.class
$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
'java/io/ObjectOutputStream$$PutField'
gnu/java/net/PlainSocketImpl$$SocketInputStream.h: gnu/java/net/PlainSocketImpl.class
$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
'gnu/java/net/PlainSocketImpl$$SocketInputStream'
gnu/java/net/PlainSocketImpl$$SocketOutputStream.h: gnu/java/net/PlainSocketImpl.class
$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
'gnu/java/net/PlainSocketImpl$$SocketOutputStream'
## Headers we maintain by hand and which we want to install.
extra_headers = java/lang/Object.h java/lang/Class.h
......
......@@ -444,8 +444,9 @@ ordinary_nat_headers = $(ordinary_java_source_files:.java=.h) \
inner_nat_headers = java/io/ObjectOutputStream$$PutField.h \
java/io/ObjectInputStream$$GetField.h \
java/lang/reflect/Proxy$$ProxyData.h \
java/lang/reflect/Proxy$$ProxyType.h
java/lang/reflect/Proxy$$ProxyType.h \
gnu/java/net/PlainSocketImpl$$SocketInputStream.h \
gnu/java/net/PlainSocketImpl$$SocketOutputStream.h
nat_headers = $(ordinary_nat_headers) $(inner_nat_headers)
......@@ -5047,6 +5048,14 @@ java/io/ObjectOutputStream$$PutField.h: java/io/ObjectOutputStream.class
$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
'java/io/ObjectOutputStream$$PutField'
gnu/java/net/PlainSocketImpl$$SocketInputStream.h: gnu/java/net/PlainSocketImpl.class
$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
'gnu/java/net/PlainSocketImpl$$SocketInputStream'
gnu/java/net/PlainSocketImpl$$SocketOutputStream.h: gnu/java/net/PlainSocketImpl.class
$(GCJH) -classpath '' -bootclasspath $(top_builddir) \
'gnu/java/net/PlainSocketImpl$$SocketOutputStream'
$(extra_headers) $(srcdir)/java/lang/Object.h $(srcdir)/java/lang/Class.h:
@:
......
......@@ -271,32 +271,6 @@ public final class PlainSocketImpl extends SocketImpl
protected native void sendUrgentData(int data)
throws IOException;
native int read() throws IOException;
/**
* Internal method used by SocketInputStream for reading data from
* the connection. Reads up to len bytes of data into the buffer
* buf starting at offset bytes into the buffer.
*
* @return The actual number of bytes read or -1 if end of stream.
*
* @exception IOException If an error occurs
*/
native int read(byte[] buffer, int offset, int count)
throws IOException;
native void write(int c) throws IOException;
/**
* Internal method used by SocketOuputStream for writing data to
* the connection. Writes up to len bytes of data from the buffer
* buf starting at offset bytes into the buffer.
*
* @exception IOException If an error occurs
*/
native void write(byte[] buffer, int offset, int count)
throws IOException;
/**
* Returns an InputStream object for reading from this socket. This will
* be an instance of SocketInputStream.
......@@ -334,13 +308,14 @@ public final class PlainSocketImpl extends SocketImpl
*
* @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
*/
class SocketInputStream
final class SocketInputStream
extends InputStream
{
SocketInputStream()
{
}
public native int read() throws IOException;
public native int read(byte[] buffer, int offset, int length)
throws IOException;
public final void close() throws IOException
{
PlainSocketImpl.this.close();
......@@ -350,52 +325,23 @@ public final class PlainSocketImpl extends SocketImpl
{
return PlainSocketImpl.this.available();
}
public final int read() throws IOException
{
return PlainSocketImpl.this.read();
}
public final int read(byte[] buffer, int offset, int length)
throws IOException
{
return PlainSocketImpl.this.read(buffer, offset, length);
}
public final int read(byte[] buffer)
throws IOException
{
return PlainSocketImpl.this.read(buffer, 0, buffer.length);
}
}
/** A stream which writes to the socket implementation.
*
* @author Nic Ferrier <nferrier@tapsellferrier.co.uk>
*/
class SocketOutputStream
final class SocketOutputStream
extends OutputStream
{
public final void close() throws IOException
{
PlainSocketImpl.this.close();
}
public native void write(int c) throws IOException;
public final void write(int c) throws IOException
{
PlainSocketImpl.this.write(c);
}
public native void write(byte[] buffer, int offset, int length)
throws IOException;
public final void write(byte[] buffer, int offset, int length)
throws IOException
public void close() throws IOException
{
PlainSocketImpl.this.write(buffer, offset, length);
}
public final void write(byte[] buffer)
throws IOException
{
PlainSocketImpl.this.write(buffer, 0, buffer.length);
PlainSocketImpl.this.close();
}
}
}
/* SocketInputStream.java -- An InputStream for Sockets
Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.net;
import java.io.InputStream;
import java.io.IOException;
/**
* This class contains an implementation of <code>InputStream</code> for
* sockets. It in an internal only class used by <code>PlainSocketImpl</code>.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
class SocketInputStream extends InputStream
{
/*************************************************************************/
/*
* Instance Variables
*/
/**
* The PlainSocketImpl object this stream is associated with
*/
private PlainSocketImpl impl;
/*************************************************************************/
/*
* Constructors
*/
/**
* Builds an instance of this class from a PlainSocketImpl object
*/
protected
SocketInputStream(PlainSocketImpl impl)
{
this.impl = impl;
}
/*************************************************************************/
/*
* Instance Methods
*/
/**
* 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");
}
/*************************************************************************/
/**
* This method not only closes the stream, it closes the underlying socket
* (and thus any connection) and invalidates any other Input/Output streams
* for the underlying impl object
*/
public void
close() throws IOException
{
impl.close();
}
/*************************************************************************/
/**
* Reads the next byte of data and returns it as an int.
*
* @return The byte read (as an int) or -1 if end of stream);
*
* @exception IOException If an error occurs.
*/
public int
read() throws IOException
{
byte buf[] = new byte[1];
int bytes_read = read(buf, 0, buf.length);
if (bytes_read != -1)
return(buf[0] & 0xFF);
else
return(-1);
}
/*************************************************************************/
/**
* Reads up to buf.length bytes of data into the caller supplied buffer.
*
* @return The actual number of bytes read or -1 if end of stream
*
* @exception IOException If an error occurs.
*/
public int
read(byte[] buf) throws IOException
{
return(read(buf, 0, buf.length));
}
/*************************************************************************/
/**
* Reads up to len bytes of data into the caller supplied buffer starting
* at offset bytes from the start of the buffer
*
* @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);
if (bytes_read == 0)
return(-1);
return(bytes_read);
}
} // class SocketInputStream
/* SocketOutputStream.java -- OutputStream for PlainSocketImpl
Copyright (C) 1998,2000 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.java.net;
import java.io.OutputStream;
import java.io.IOException;
/**
* This class is used internally by <code>PlainSocketImpl</code> to be the
* <code>OutputStream</code> subclass returned by its
* <code>getOutputStream method</code>. It expects only to be used in that
* context.
*
* @author Aaron M. Renn (arenn@urbanophile.com)
*/
class SocketOutputStream extends OutputStream
{
/*************************************************************************/
/*
* Instance Variables
*/
/**
* The PlainSocketImpl object this stream is associated with
*/
private PlainSocketImpl impl;
/*************************************************************************/
/*
* Constructors
*/
/**
* Build an instance of this class from a PlainSocketImpl object
*/
protected
SocketOutputStream(PlainSocketImpl impl)
{
this.impl = impl;
}
/*************************************************************************/
/*
* Instance Methods
*/
/**
* 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.
*
* @exception IOException If an error occurs
*/
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
{
return;
}
/*************************************************************************/
/**
* Writes a byte (passed in as an int) to the given output stream
*
* @param b The byte to write
*
* @exception IOException If an error occurs
*/
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);
}
/*************************************************************************/
/**
* Write an array of bytes to the output stream
*
* @param buf The array of bytes to write
*
* @exception IOException If an error occurs
*/
public void
write(byte[] buf) throws IOException
{
write(buf, 0, buf.length);
}
/*************************************************************************/
/**
* Writes len number of bytes from the array buf to the stream starting
* at offset bytes into the buffer.
*
* @param buf The buffer
* @param offset Offset into the buffer to start writing from
* @param len The number of bytes to write
*/
public void
write(byte[] buf, int offset, int len) throws IOException
{
impl.write(buf, offset, len);
}
} // class SocketOutputStream
......@@ -10,6 +10,8 @@ details. */
#include <platform.h>
#include <gnu/java/net/PlainSocketImpl.h>
#include <gnu/java/net/PlainSocketImpl$SocketInputStream.h>
#include <gnu/java/net/PlainSocketImpl$SocketOutputStream.h>
#include <java/io/IOException.h>
#include <java/net/BindException.h>
#include <java/net/ConnectException.h>
......@@ -65,28 +67,30 @@ gnu::java::net::PlainSocketImpl::getOption (jint)
}
jint
gnu::java::net::PlainSocketImpl::read(void)
gnu::java::net::PlainSocketImpl$SocketInputStream::read(void)
{
throw new ::java::net::SocketException (
JvNewStringLatin1 ("SocketImpl.read: unimplemented"));
}
jint
gnu::java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer,
jint offset, jint count)
{
throw new ::java::net::SocketException (
JvNewStringLatin1 ("SocketImpl.read: unimplemented"));
}
void
gnu::java::net::PlainSocketImpl::write(jint b)
gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jint b)
{
throw new ::java::net::SocketException (
JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
}
void
gnu::java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jbyteArray b,
jint offset, jint len)
{
throw new ::java::net::SocketException (
JvNewStringLatin1 ("SocketImpl.write: unimplemented"));
......
......@@ -32,6 +32,8 @@ details. */
#include <gcj/cni.h>
#include <gcj/javaprims.h>
#include <gnu/java/net/PlainSocketImpl.h>
#include <gnu/java/net/PlainSocketImpl$SocketInputStream.h>
#include <gnu/java/net/PlainSocketImpl$SocketOutputStream.h>
#include <java/io/IOException.h>
#include <java/io/InterruptedIOException.h>
#include <java/net/BindException.h>
......@@ -310,14 +312,14 @@ gnu::java::net::PlainSocketImpl::close()
// Write a byte to the socket.
void
gnu::java::net::PlainSocketImpl::write(jint b)
gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jint b)
{
jbyte d =(jbyte) b;
int r = 0;
while (r != 1)
{
r = _Jv_write (fnum, &d, 1);
r = _Jv_write (this$0->fnum, &d, 1);
if (r == -1)
{
if (::java::lang::Thread::interrupted())
......@@ -338,7 +340,7 @@ gnu::java::net::PlainSocketImpl::write(jint b)
// Write some bytes to the socket.
void
gnu::java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jbyteArray b, jint offset, jint len)
{
if (! b)
throw new ::java::lang::NullPointerException;
......@@ -350,7 +352,7 @@ gnu::java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
while (len > 0)
{
int r = _Jv_write (fnum, bytes, len);
int r = _Jv_write (this$0->fnum, bytes, len);
if (r == -1)
{
......@@ -383,9 +385,11 @@ gnu::java::net::PlainSocketImpl::sendUrgentData (jint)
// Read a single byte from the socket.
jint
gnu::java::net::PlainSocketImpl::read(void)
gnu::java::net::PlainSocketImpl$SocketInputStream::read(void)
{
jbyte b;
jint timeout = this$0->timeout;
jint fnum = this$0->fnum;
// Do timeouts via select.
if (timeout > 0 && fnum >= 0 && fnum < FD_SETSIZE)
......@@ -438,8 +442,12 @@ gnu::java::net::PlainSocketImpl::read(void)
// Read count bytes into the buffer, starting at offset.
jint
gnu::java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer, jint offset,
jint count)
{
jint fnum = this$0->fnum;
jint timeout = this$0->timeout;
if (! buffer)
throw new ::java::lang::NullPointerException;
......
......@@ -346,14 +346,14 @@ gnu::java::net::PlainSocketImpl::close()
// Write a byte to the socket.
void
gnu::java::net::PlainSocketImpl::write(jint b)
gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jint b)
{
jbyte d =(jbyte) b;
int r = 0;
while (r != 1)
{
r = ::send (fnum, (char*) &d, 1, 0);
r = ::send (this$0->fnum, (char*) &d, 1, 0);
if (r == -1)
{
DWORD dwErr = WSAGetLastError();
......@@ -376,7 +376,8 @@ gnu::java::net::PlainSocketImpl::write(jint b)
// Write some bytes to the socket.
void
gnu::java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jbyteArray b,
jint offset, jint len)
{
if (! b)
throw new ::java::lang::NullPointerException;
......@@ -387,7 +388,7 @@ gnu::java::net::PlainSocketImpl::write(jbyteArray b, jint offset, jint len)
int written = 0;
while (len > 0)
{
int r = ::send (fnum, (char*) bytes, len, 0);
int r = ::send (this$0->fnum, (char*) bytes, len, 0);
if (r == -1)
{
......@@ -479,16 +480,17 @@ error:
// Read a single byte from the socket.
jint
gnu::java::net::PlainSocketImpl::read(void)
gnu::java::net::PlainSocketImpl$SocketInputStream::read(void)
{
jbyte b;
doRead(fnum, &b, 1, timeout);
doRead(this$0->fnum, &b, 1, this$0->timeout);
return b & 0xFF;
}
// Read count bytes into the buffer, starting at offset.
jint
gnu::java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count)
gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer,
jint offset, jint count)
{
if (! buffer)
throw new ::java::lang::NullPointerException;
......@@ -501,7 +503,7 @@ gnu::java::net::PlainSocketImpl::read(jbyteArray buffer, jint offset, jint count
jbyte *bytes = elements (buffer) + offset;
// Read the socket.
return doRead(fnum, bytes, count, timeout);
return doRead(this$0->fnum, bytes, count, this$0->timeout);
}
// How many bytes are available?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment