History log of /libcore/luni/src/main/java/java/nio/SocketChannelImpl.java
Revision Date Author Comments
0aff1dd0b4be1b8d8cb45b59079ca883a1b3205a 17-Jun-2014 Elliott Hughes <enh@google.com> Remove.

(cherry-pick of 63744c884dd4b4f4307f2b021fb894af164972af.)

Change-Id: Ibf79a402e1bad98a262e380fcee3d35c127ae6d5
63744c884dd4b4f4307f2b021fb894af164972af 17-Jun-2014 Elliott Hughes <enh@google.com> Remove.

Change-Id: Ibf79a402e1bad98a262e380fcee3d35c127ae6d5
5d930cadc8f62aee5f18e7921296fe66a54f18ab 24-Apr-2014 Elliott Hughes <enh@google.com> Groundwork towards making the Libcore.os functionality public.

Change-Id: Ie700aa16d91fba53fc5eb2555829cb74d84b12ad
f0d40d662d9dfdb04215c718961765837d2cf00c 11-Apr-2014 Neil Fuller <nfuller@google.com> libcore changes to support asynchronous close interruption

Previously AsynchronousSocketCloseMonitor was used to handle
socket interruption on close. To support the same for
FileChannel it has been renamed to AsynchronousCloseMonitor.
The Java class was already called this.

FileInputStream, FileOutputStream, RandomAccessFile will
now throw IOException if a connection is closed by another
thread during read. Thread.interrupt() continues to have no effect
on streams.

FileChannel will now throw AsynchronousCloseException during
reads and writes if the file is closed, per the documentation.

FileChannel will now throw ClosedByInterruptException during
reads and writes if the thread reading/writing is interrupted.

Note: FileChannel.lock() will probably still not not throw
AsynchronousCloseException, though it probably should.

This change also has impact on external/conscrypt and
frameworks/base.

Change-Id: I37de3e7d1a005a73821221e6156d10b95c595d7a
Bug: 13927110
8621348d05b28d7626e76fcea3ea6f45099a9157 07-Mar-2014 Neil Fuller <nfuller@google.com> Add APIs for better interoperability with Java 1.7

Must be committed at the same time as the change in framework
to update the public API footprint.

See commit 38ce4c0f83d4ac35c4c63fecf7c8775f9b16f6da in framework/base.

Change-Id: I71a88b09feef8bc2b50b3aeafc3be5863eea3063
df29508a7aa622f265aaebdc472eb7d679185ebb 30-Jan-2014 Neil Fuller <nfuller@google.com> Implementation of MulticastChannel.

Note: ProtocolFamily / StandardProtocolFamily /
DatagramChannel.open(ProtocolFamily) have not been
implemented.

There is a related change to libnativehelper that
must be merged at the same time to avoid
build breakage. See
https://android-review.googlesource.com/#/c/81371/

Bug: 12464155
Change-Id: I07fc049b429a2d373e9bd7b07149632f5cd69f9d
ff81b740a338ba964e0ba1c40d925fb2ceb37bf2 20-Jan-2014 Neil Fuller <nfuller@google.com> Adding additional methods to NetworkChannel.

Adding NetworkChannel.supportedOptions(), NetworkChannel.getOption(),
NetworkChannel.setOption(). A lot of the changes are in documentation
and tests.

Bug: 12464155
Change-Id: Ifa56843a8823b6b9cbd262409adc2450b401c654
47ae0b5a1d96c8030e0963ccc5b44c3ee66aaec3 20-Jan-2014 Neil Fuller <nfuller@google.com> Implementing bind() and getLocalAddress() for NIO2.

This change introduces NetworkChannel, but only bind() and
getLocalAddress() methods. To avoid breaking existing Android
applications that extend ServerSocketChannel, DatagramChannel and
SocketChannel the methods have been added with concrete
implementations that throw exceptions rather than leaving them
abstract.

In channel tests, usages of channel.socket().bind() and
channel.socket().getLocalSocketAddress() have been changed to
channel.bind() and channel.getLocalAddress(), since the behavior is
close enough and the tests should be written against the channel APIs
as much as possible. Tests have been added for new methods.

Removed further overriding in
DatagramChannelImpl.DatagramSocketAdapter and
SocketChannelImpl.SocketAdapter which revealed some bugs and lack of
clarity in the docs for the socket methods:

Improved the documentation for DatagramSocket.getLocalAddress(),
DatagramSocket.getLocalSocketAddress(),
ServerSocket.getInetAddress(), ServerSocket.getLocalPort(),
ServerSocket.getLocalSocketAddress(), Socket.getLocalAddress(),
Socket.getLocalPort(), Socket.getLocalSocketAddress(). These methods
treat special cases differently.

Fixed a bug in DatagramSocket.getLocalSocketAddress() where it would
incorrect throw an exception if the socket has been closed, which
contradicts the (updated) documentation and the RI. It now returns
null. Added tests.

Fixed a bug in Socket.close(): a closed socket would still report as
being connected. Added tests.

Fixed a bug in Socket.startupSocket() - the socket was recording it
was being bound, but was not updating the cached local address. This
method is called during ServerSocketChannel.accept() and would cause
the socket to report its local address as being the wildcard address,
when it is not. Added a test.

Change-Id: Ibec8527e1c72597e268d23e6c1f03eb16e46cdc4
Bug: 12464155
933fbbf606268eec9fc430632b8bca7002a833b3 14-Jan-2014 Neil Fuller <nfuller@google.com> Refactoring in preparation for NIO2 changes.

Making the various Socket/Channel classes more consistent with each
other for synchronizing state between the Channel, Socket and the OS.
This is in preparation for NetworkChannel.bind().
Synchronizing state revealed a test that relied upon a Socket from a
channel not reporting isConnected() properly after a connect(). Tests
have been updated.

Reading the local address back from the OS revealed that Android is
using IPv6 and reports the string equivalent of IPv4's 0.0.0.0 as
"::". Updated a test that was relying on the string form.

Calling connect() twice on a DatagramSocket appears inconsistent with
itself and Channel and other Sockets. A pure DatagramSocket switches
over to the new remote address. I have changed the Channel-backed
DatagramSocket to throw an IllegalStateException exception, and have
created a bug to discuss making the calls more consistent.

Socket has been modified to avoid using the address field to store
the local address after a bind(). This field is documented as holding
the remote address, not the local.

Changed implementation of SocketChannelImpl.socket().getInputStream()
and SocketChannelImpl.socket().getOutputStream() to use the one that
is implemented by Socket and not a custom NIO-based implementation.
The use of NIO provided two parallel implementations for the same
thing. This change alters behavior when attempting to read zero bytes
and when a Channel is in non-blocking mode: now it throws
IllegalBlockingModeException rather than
ArrayIndexOutOfBoundsException. The tests have been updated.

Various tidying up changes to introduce @Override, remove
unnecessarily initialized local variables, fields, semi-colons,
javadocs and imports. Added close() calls for objects during tests
that were cluttering the logs.

Modified IoBridge.connect() to be void. Adjusted SocketChannelImpl
accordingly and tidied up impossible cases. Modified
SocketChannel.connect() so that it always returns false in
non-blocking mode. This looks like an existing bug:
it would previously have returned true, even though the connection
was potentially still pending. Tests have been added.

Also tidied up SocketChannelImpl.finishConnect() - it was potentially
resetting the isBound state.

Change-Id: Ic7943615b4b763f77e74397e0e91a62edc7d7017
bug: 12464155
38f3983aed5a093c17d1f68c1517bbc72c2862ea 15-Oct-2013 Elliott Hughes <enh@google.com> Use @throws rather than the deprecated and unusual @exception.

Change-Id: I69d94fae14a6153ef227352e1e159697db8d618d
325ff8c68ed5e530e9e1d487b9e2e6d8f8e2bd37 25-Jun-2013 Elliott Hughes <enh@google.com> Clean up the #read javadoc.

By being more consistent in parameter naming, we can inherit more javadoc.

Also fix a couple of javadoc warnings in KnownFailure and DataInputStream.

Change-Id: I778f40469404fb50c51cdb1068970974f923180c
c43083ece7c4479fbe38001983a0d28893d0812a 22-Jun-2013 Elliott Hughes <enh@google.com> Fix the SocketChannel accept locking behavior.

Fixes a harmony-tests/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ServerSocketChannelTest
test that had been failing since we turned it back on.

Change-Id: I76cbc5edc1ab9edc4d2818bd23649f4b906d662c
c6ad01d286af243fd300dd105eb2e4437e0b6b16 21-Jun-2013 Elliott Hughes <enh@google.com> Fix non-blocking SocketChannel connects.

There are many reasons why the initial connect(2) may have resulted
in a ConnectException, only one of which (EINPROGRESS) means we haven't
yet failed.

Bug: https://code.google.com/p/android/issues/detail?id=56684
Change-Id: I2115998bce9043f076418fb0d1c22a26e04ee2e1
b2e6be1cc1d375ca2fc28ee1fdfc10c0adc2554d 29-Sep-2012 Elliott Hughes <enh@google.com> Rewrite NIO Pipe to use socketpair(2).

Our Pipe originally used socket(2) to create AF_INET/AF_INET6
sockets. This was clearly a bad idea.

I rewrote it to use socketpair(2) and AF_UNIX, but this was
before the big "expose POSIX" rewrite, so it required a bunch
of hacks in the native code, so I went with pipe(2) instead.

The trouble with pipe(2) is that we end up using FileChannel
to implement the Pipe.SinkChannel and Pipe.SourceChannel, but
the kernel won't wake a read(2) on a pipe if another thread
calls close(2) on it, so we started failing interrupt tests.

This (final?) rewrite is hopefully the best of all worlds:
we don't have any INTERNET permission needs, the code is as
simple as the pipe(2) code, and interruption works.

Bug: 7084342
Bug: 2735373
Bug: http://code.google.com/p/android/issues/detail?id=9431

(cherry picked from commit 3218082325b6b8713a8ac15731482e3da86a7df9)

Change-Id: Ib92cdf8c818f6bba1f00e191f1b624ce9e693754
3218082325b6b8713a8ac15731482e3da86a7df9 29-Sep-2012 Elliott Hughes <enh@google.com> Rewrite NIO Pipe to use socketpair(2).

Our Pipe originally used socket(2) to create AF_INET/AF_INET6
sockets. This was clearly a bad idea.

I rewrote it to use socketpair(2) and AF_UNIX, but this was
before the big "expose POSIX" rewrite, so it required a bunch
of hacks in the native code, so I went with pipe(2) instead.

The trouble with pipe(2) is that we end up using FileChannel
to implement the Pipe.SinkChannel and Pipe.SourceChannel, but
the kernel won't wake a read(2) on a pipe if another thread
calls close(2) on it, so we started failing interrupt tests.

This (final?) rewrite is hopefully the best of all worlds:
we don't have any INTERNET permission needs, the code is as
simple as the pipe(2) code, and interruption works.

Bug: 7084342
Bug: 2735373
Bug: http://code.google.com/p/android/issues/detail?id=9431
Change-Id: If3f052c9d3f5aa1c099f5a069ace9a8d6ce3ca3a
d43b9ef11a1095967a3396b246639b563e1a4128 12-Sep-2012 Kenny Root <kroot@google.com> Add consistent reasons for NullPointerException

Semi-automated replacement of empty and non-conforming
NullPointerException reason messages.

(cherry-pick of 86acc043d3334651ee26c65467d78d6cefedd397.)

Change-Id: I6d893979f5c20a50e841e32af9fd7b2d8bc9d54d
86acc043d3334651ee26c65467d78d6cefedd397 12-Sep-2012 Kenny Root <kroot@google.com> Add consistent reasons for NullPointerException

Semi-automated replacement of empty and non-conforming
NullPointerException reason messages.

Change-Id: Iedeb4b21949e973c4042ce5982dda315f2e785e1
126ab1b546c71137a97cef68cc89267e7f7be634 28-Aug-2012 Elliott Hughes <enh@google.com> Improve nio IllegalArgumentException detail messages.

Bug: 7005326
Change-Id: Ibab8b776865dbed5da062cc683f834a79f068b32
be0b5bd592bed1edaed2447e7ab1764b93eceaab 13-Sep-2011 Jesse Wilson <jessewilson@google.com> Make socket channel address available after bind().

This regression was found by a harmony test:
org.apache.harmony.nio.tests.java.nio.channels.SocketChannelTest#testSocket_bind

Change-Id: Idb1089fb96b17673cf78903d935cb729722fda33
3267a46b52d848e1e9e20c226512688f0c50d4c3 25-Aug-2011 Jeff Sharkey <jsharkey@android.com> Return real FileDescriptor in Socket wrappers.

In classes that wrap another Socket, return the real FileDescriptor
from the wrapped Socket.

Bug: 5189186
Change-Id: I157feb6991def9110eaf0ea82365b6f5b95b9372
e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7 10-Jun-2011 Elliott Hughes <enh@google.com> Expose pread and pwrite.

And fix FileChannel to use them.

Bug: 4183719
Bug: 3107501
Change-Id: I51114a16522b93bf959b5953bec658e6889054c6
9b510df35b57946d843ffc34cf23fdcfc84c5220 28-May-2011 Elliott Hughes <enh@google.com> Make ErrnoException a checked exception.

Bug: 4486011
Change-Id: I1877ce593d441653f75ab14884aa2d85f52652ad
a28bc96d63595a77fa918da8ccdda50e9eaae95e 21-May-2011 Elliott Hughes <enh@google.com> Fix read/write bugs in DatagramChannel and SocketChannel.

Also improve some exception detail messages for ease of debugging.

These bugs were found by external/apache-harmony tests.

Change-Id: I37a58c1d1f1c2150eb9171967f47ef9644e8ae15
0b736ebc4efef64f2db1999aea90297ad8196146 20-May-2011 Elliott Hughes <enh@google.com> Move the stuff to bridge between io/net/nio semantics and POSIX semantics.

IoUtils should be more generally useful.

Change-Id: I5665f2a94d226ada3077a30045549a53cc741cf0
23ec09188303a874b3b391f96ae0a29af002bff9 19-May-2011 Elliott Hughes <enh@google.com> Implement recvfrom(2).

This one's a little bit hairy because of multiple return values.

Bug: 3107501
Change-Id: I3bd35647d94bb6bc2192d6f31a39ecca07a3926e
90d96a4f168b7e56cff54dc94dca2f3cde60ebcd 17-May-2011 Elliott Hughes <enh@google.com> Add sendto(2) and reimplement all network writes in terms of it.

Note that this doesn't fix http://b/4182806.

Bug: 3107501
Change-Id: I9b56eae226389a63a12b4c0499d40d5a54a462e2
e27d02044ec399884bfd4343d513bf270b9b9b11 16-May-2011 Elliott Hughes <enh@google.com> Remove OSNetworkSystem.close.

For now I'm keeping AsynchronousCloseMonitor as a special case in native code.
We can see about doing something more general-purpose in a later pass.

Bug: 3107501
Change-Id: Ib79b9fc0bebfafc2d14896d957bd8591ae8e6e97
2bad9bff258de6275bd3847e5e9f3169b0a93c61 12-May-2011 Elliott Hughes <enh@google.com> Reimplement OSNetworkSystem.isConnected in Java.

We can do this in Java now we've exposed poll(2).

Change-Id: I9f2700d09134198c1cd2681e3814fb482e8e271c
49ff8b8582bca20a1adbda1d957220526332a8ca 06-May-2011 Elliott Hughes <enh@google.com> More networking cleanup.

Move a bit more work into Java.

Change-Id: I656ec6e3c792ce9baed32662d65c45d75af1d371
a3b57e9cb41fb00ac607cd330fa73270b564b66c 06-May-2011 Elliott Hughes <enh@google.com> Fix non-blocking DatagramChannel.receive and ServerSocketChannel.accept.

The former problem was the reported bug, but the latter was another instance of
the same mistake, and much harder to fix.

The interesting change here is that we now create the SocketImpl (and thus the
underlying OS socket) for a ServerSocket much sooner than we used to: if the
constructor doesn't throw, you've got yourself a usable socket.

Bug: http://code.google.com/p/android/issues/detail?id=16579
Change-Id: Iac8b707e74cd1367ee0fdc22fc3969677cfa566c
d6ecf9222ec65a08e99f15fcc4ec024f0fffd13a 04-May-2011 Elliott Hughes <enh@google.com> Fix non-blocking connects.

The key change here is reintroducing the boolean return value, which we need
as long as the native code treats EINPROGRESS as a special case which doesn't
throw.

The rest is just drive-by incremental cleanup of the code.

Change-Id: I761b052adbb14e912c3853a35327f8a589cd4023
220c0af1763283b75617226efe3919c3e3b044c8 30-Apr-2011 Elliott Hughes <enh@google.com> Rewrite blocking connects in terms of the non-blocking primitives.

This simplifies OSNetworkSystem, getting us closer to replacing the
connect(2)-related bits with our new POSIX interface. It also lets
us remove cruft on the Java side that was resetting the socket's
blocking/non-blocking state (which should never have been touched),
which in turn fixes bug 4193212.

Detail messages for socket timeouts get better too, now we're throwing
on the Java side.

The only thing that's worse is that we used to get away with throwing
a checked exception from native code, which simplified our "throws"
clauses. Now we actually have to jump through a few hoops to make javac
happy. (Especially awkward because SocketTimeoutException isn't a
SocketException.) Stupid checked exceptions.

Bug: 4193212
Bug: 3107501
Change-Id: I00695d22094e6d785458dfbb7050fbaecf2db89f
0a9d1ee45a9884a9616624d747172e18734e8fe0 31-Mar-2011 Elliott Hughes <enh@google.com> Add getsockname(2) and getsockopt(2).

Bug: 3107501
Change-Id: Ibb0d5a576ecb46e51dbda6051776145eec9e7fe1
d320e321d5567a4ac94b6e5874eda4b1f1189e13 30-Mar-2011 Elliott Hughes <enh@google.com> Move and rename an implementation detail.

Change-Id: I563c2fd6689dd7249049671c3c01c6434d9b5fa5
454a95f6a28855aa3c88d168b15a45bf315efc99 30-Mar-2011 Elliott Hughes <enh@google.com> Add socket(2) and start adding setsockopt(2).

I've added just enough setsockopt to keep the hack from our old socket
creation code. More later (but not necessarily right away).

Bug: 3107501
Change-Id: Id57bdd3c760bc58ed79d675b268c55493cbc24c8
8de7cf6bff36093dda9e25a1ab3718720cb54906 07-Mar-2011 Elliott Hughes <enh@google.com> Move the various concrete SocketImpl classes into java.net.

Also do some trivial tidying of dead code.

Bug: http://code.google.com/p/android/issues/detail?id=15304
Change-Id: If7186dda6bf31e2c2ef00ac6f386cbc9a78847fd
9229d47c1288e25ead3a2dc27fac8a4a2ee932a3 07-Mar-2011 Elliott Hughes <enh@google.com> Kill many of the stl_style_names in Java.

Change-Id: I4473a6efc74a49dd3b480a48d4c697fc773e08f8
62e34a21db1cbef5d2cec186ee4f15c5ec39d187 24-Feb-2011 Elliott Hughes <enh@google.com> Fix more FindBugs warnings: dead store in SocketChannelImpl.

Change-Id: I2aa05b830dd7cac561efadf019eb48c2c933c095
fb0ec0e650bf8be35acb0d47da0311a7c446aa33 14-Jan-2011 Elliott Hughes <enh@google.com> Remove useless android-changed comments.

I've changed useful ones to regular comments or TODOs, as appropriate.

I've left ones in code like java.util.concurrent where we really are
tracking an upstream source, making the change markers useful.

I've left a handful of others where I intend to actually investigate
the implied TODOs before deciding how to resolve them.

Change-Id: Iaf71059b818596351cf8ee5a3cf3c85586051fa6
ad41624e761bcf1af9c8008eb45187fc13983717 07-Jan-2011 Elliott Hughes <enh@google.com> Retire SecurityManager.

This change removes all the code that was calling getSecurityManager, and
removes all use of AccessController.doPrivileged. It also changes the
implementation of AccessController so it doesn't actually do anything; it's
only there for source-level compatibility.

Bug: 2585285
Change-Id: I1f0295a4f12bce0316d8073011d8593fee116f71
a1603838fe9e865575c87982e32c6343740e464c 11-Dec-2010 Elliott Hughes <enh@google.com> Lots more bounds-checking/exception-throwing consistency.

Overflow-safe checks all round, plus better detail messages. This isn't
quite everything, but it's a large chunk of the work. Most notably, this
is all of io and nio.

There are numerous changes of exception priority here, and the harmony
tests noticed a subset of them in the nio code. I've modified our checked-out
copy of the tests to accept any of the throwable exceptions.

Change-Id: Id185f1228fb9a1d5fc9494e78375b5623fb0fe14
b46dab348e2007bc08abaf7ecae34d89a2474e50 09-Dec-2010 Elliott Hughes <enh@google.com> Rewrite all backwards comparisons.

Strictly, all the ones I could find. This is everything with 0 or null on the
left-hand side.

Note that this touches several incorrect bounds checks, which I haven't fixed:
I'm going to come back and finish that independent cleanup separately.

Change-Id: Ibdb054b53df9aace47c7d2a00ff19122190053e8
5e23b687ef8b3c696d54d1880b454942875665b7 22-Sep-2010 Elliott Hughes <enh@google.com> Remove custom marker classes for locks.

Just use Object instead.

Bug: 3024308
Change-Id: I83a01020646d95e014743b76e27ca7134c155298
ae704b984c10a63883cc366e823d53902d6ac7a9 21-Sep-2010 Elliott Hughes <enh@google.com> Minor tidy-up.

The nio implementation is still a bit of a mess because Java doesn't have any
kind of "module" concept, nor "friend". But this makes it a little less untidy,
and makes the deliberate access control subversions a little more explicit, and
makes various things less accessible than they were.

Change-Id: I514b1e24000b91f86b768ed408fedae115dc3080