diff options
author | jfrijters <jfrijters> | 2007-08-23 13:29:12 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2007-08-23 13:29:12 +0400 |
commit | 8e00b2f20a0730f097b45101347e891b31479edb (patch) | |
tree | 28b77fc67f50b20a3ca8e7d41c7cf882291814c0 /openjdk/sun/nio/ch | |
parent | 3a0429a1984f35029bc8c619b51856ec2a33f80e (diff) |
Fixed writeImpl() to return IOStatus.UNAVAILABLE if the socket is in non-blocking mode and the write failed because of this.
Diffstat (limited to 'openjdk/sun/nio/ch')
-rw-r--r-- | openjdk/sun/nio/ch/Net.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/openjdk/sun/nio/ch/Net.java b/openjdk/sun/nio/ch/Net.java index ba907756..33e87ef7 100644 --- a/openjdk/sun/nio/ch/Net.java +++ b/openjdk/sun/nio/ch/Net.java @@ -272,19 +272,19 @@ class Net { // package-private if (false) throw new cli.System.Net.Sockets.SocketException(); if (false) throw new cli.System.ObjectDisposedException(""); int read = fd.getSocket().Receive(buf, offset, length, SocketFlags.wrap(SocketFlags.None)); - return read == 0 ? -1 : read; + return read == 0 ? IOStatus.EOF : read; } catch (cli.System.Net.Sockets.SocketException x) { if (x.get_ErrorCode() == PlainSocketImpl.WSAESHUTDOWN) { // the socket was shutdown, so we have to return EOF - return -1; + return IOStatus.EOF; } else if (x.get_ErrorCode() == PlainSocketImpl.WSAEWOULDBLOCK) { // nothing to read and would block - return 0; + return IOStatus.UNAVAILABLE; } throw PlainSocketImpl.convertSocketExceptionToIOException(x); } @@ -368,6 +368,10 @@ class Net { // package-private } catch (cli.System.Net.Sockets.SocketException x) { + if (x.get_ErrorCode() == PlainSocketImpl.WSAEWOULDBLOCK) + { + return IOStatus.UNAVAILABLE; + } throw PlainSocketImpl.convertSocketExceptionToIOException(x); } catch (cli.System.ObjectDisposedException x1) @@ -382,7 +386,10 @@ class Net { // package-private { byte[] buf = src.array(); int len = writeImpl(fd, buf, src.arrayOffset() + src.position(), src.remaining()); - src.position(src.position() + len); + if (len > 0) + { + src.position(src.position() + len); + } return len; } else @@ -391,7 +398,10 @@ class Net { // package-private byte[] buf = new byte[src.remaining()]; src.get(buf); int len = writeImpl(fd, buf, 0, buf.length); - src.position(pos + len); + if (len > 0) + { + src.position(pos + len); + } return len; } } @@ -405,6 +415,10 @@ class Net { // package-private if (size > 0) { int written = write(fd, srcs[i]); + if (written < 0) + { + break; + } totalWritten += written; if (written < size) { |