summaryrefslogtreecommitdiff
path: root/libjava/gnu
diff options
context:
space:
mode:
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2004-03-17 08:09:32 +0000
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>2004-03-17 08:09:32 +0000
commit3819c3e3f73f37e13ff32f72c3af0aef7c441aea (patch)
tree3b0ac7b3f6371284917ba6f89fd7ad76c90b72ea /libjava/gnu
parent4aad261ff9ad67dd9eead7ebb9eefcb7afb0c095 (diff)
downloadgcc-3819c3e3f73f37e13ff32f72c3af0aef7c441aea.tar.gz
2004-03-17 Michael Koch <konqueror@gmx.de>
* gnu/java/net/natPlainSocketImplPosix.cc (write): Just call write(jbyteArray, offset, len). (read): Just call read(jbyteArray, offset, len). git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@79578 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gnu')
-rw-r--r--libjava/gnu/java/net/natPlainSocketImplPosix.cc106
1 files changed, 27 insertions, 79 deletions
diff --git a/libjava/gnu/java/net/natPlainSocketImplPosix.cc b/libjava/gnu/java/net/natPlainSocketImplPosix.cc
index c02d5a0f047..1dbc90d6010 100644
--- a/libjava/gnu/java/net/natPlainSocketImplPosix.cc
+++ b/libjava/gnu/java/net/natPlainSocketImplPosix.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 Free Software Foundation
+/* Copyright (C) 2003, 2004 Free Software Foundation
This file is part of libgcj.
@@ -309,32 +309,15 @@ gnu::java::net::PlainSocketImpl::close()
timeout = 0;
}
+static void
+write_helper (jint native_fd, jbyte *bytes, jint len);
+
// Write a byte to the socket.
void
gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jint b)
{
- jbyte d =(jbyte) b;
- int r = 0;
-
- while (r != 1)
- {
- r = _Jv_write (this$0->native_fd, &d, 1);
- if (r == -1)
- {
- if (::java::lang::Thread::interrupted())
- {
- ::java::io::InterruptedIOException *iioe
- = new ::java::io::InterruptedIOException
- (JvNewStringLatin1 (strerror (errno)));
- iioe->bytesTransferred = 0;
- throw iioe;
- }
- // Some errors should not cause exceptions.
- if (errno != ENOTCONN && errno != ECONNRESET && errno != EBADF)
- throw new ::java::io::IOException (JvNewStringUTF (strerror (errno)));
- break;
- }
- }
+ jbyte data = (jbyte) b;
+ write_helper (this$0->native_fd, &data, 1);
}
// Write some bytes to the socket.
@@ -346,12 +329,17 @@ gnu::java::net::PlainSocketImpl$SocketOutputStream::write(jbyteArray b, jint off
if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
throw new ::java::lang::ArrayIndexOutOfBoundsException;
- jbyte *bytes = elements (b) + offset;
+ write_helper (this$0->native_fd, elements (b) + offset * sizeof (jbyte), len);
+}
+
+static void
+write_helper(jint native_fd, jbyte *bytes, jint len)
+{
int written = 0;
while (len > 0)
{
- int r = _Jv_write (this$0->native_fd, bytes, len);
+ int r = _Jv_write (native_fd, bytes, len);
if (r == -1)
{
@@ -382,61 +370,19 @@ gnu::java::net::PlainSocketImpl::sendUrgentData (jint)
"PlainSocketImpl: sending of urgent data not supported by this socket"));
}
+static jint
+read_helper (jint native_fd, jint timeout, jbyte *bytes, jint count);
+
// Read a single byte from the socket.
jint
gnu::java::net::PlainSocketImpl$SocketInputStream::read(void)
{
- jbyte b;
- jint timeout = this$0->timeout;
- jint native_fd = this$0->native_fd;
+ jbyte data;
- // Do timeouts via select.
- if (timeout > 0 && native_fd >= 0 && native_fd < FD_SETSIZE)
- {
- // Create the file descriptor set.
- fd_set read_fds;
- FD_ZERO (&read_fds);
- FD_SET (native_fd,&read_fds);
- // Create the timeout struct based on our internal timeout value.
- struct timeval timeout_value;
- timeout_value.tv_sec = timeout / 1000;
- timeout_value.tv_usec = (timeout % 1000) * 1000;
- // Select on the fds.
- int sel_retval =
- _Jv_select (native_fd + 1, &read_fds, NULL, NULL, &timeout_value);
- // If select returns 0 we've waited without getting data...
- // that means we've timed out.
- if (sel_retval == 0)
- throw new ::java::net::SocketTimeoutException
- (JvNewStringUTF ("Read timed out") );
- // If select returns ok we know we either got signalled or read some data...
- // either way we need to try to read.
- }
-
- int r = _Jv_read (native_fd, &b, 1);
-
- if (r == 0)
- return -1;
-
- if (::java::lang::Thread::interrupted())
- {
- ::java::io::InterruptedIOException *iioe =
- new ::java::io::InterruptedIOException
- (JvNewStringUTF("Read interrupted"));
- iioe->bytesTransferred = r == -1 ? 0 : r;
- throw iioe;
- }
- else if (r == -1)
- {
- // Some errors cause us to return end of stream...
- if (errno == ENOTCONN)
- return -1;
+ if (read_helper (this$0->native_fd, this$0->timeout, &data, 1) == 1)
+ return data;
- // Other errors need to be signalled.
- throw new ::java::io::IOException (JvNewStringUTF (strerror (errno)));
- }
-
- return b & 0xFF;
+ return -1;
}
// Read count bytes into the buffer, starting at offset.
@@ -444,10 +390,7 @@ jint
gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer, jint offset,
jint count)
{
- jint native_fd = this$0->native_fd;
- jint timeout = this$0->timeout;
-
- if (! buffer)
+ if (! buffer)
throw new ::java::lang::NullPointerException;
jsize bsize = JvGetArrayLength (buffer);
@@ -455,8 +398,13 @@ gnu::java::net::PlainSocketImpl$SocketInputStream::read(jbyteArray buffer, jint
if (offset < 0 || count < 0 || offset + count > bsize)
throw new ::java::lang::ArrayIndexOutOfBoundsException;
- jbyte *bytes = elements (buffer) + offset;
+ return read_helper (this$0->native_fd, this$0->timeout,
+ elements (buffer) + offset * sizeof (jbyte), count);
+}
+static jint
+read_helper (jint native_fd, jint timeout, jbyte *bytes, jint count)
+{
// Do timeouts via select.
if (timeout > 0 && native_fd >= 0 && native_fd < FD_SETSIZE)
{