History log of /libcore/luni/src/main/java/libcore/io/BlockGuardOs.java
Revision Date Author Comments
f6cf9efb212e572dcd2e902ca461af6323793dbf 26-Aug-2014 Elliott Hughes <enh@google.com> Keep qtaguid quiet by not trying to untag non-sockets.

Bug: 17203955
Change-Id: I0999fc0ff295986b92e31568d96e321b9e7ffb2c
d636777d624428dfc51d1181f47602f389eb4cce 15-Aug-2014 Elliott Hughes <enh@google.com> Avoid triggering StrictMode when closing a socket.

Originally, we called getsockoptLinger unconditionally, using ENOTSOCK
to recognize the non-socket case, but the cost of throwing an exception
is so high (both on dalvik and art) that we worked around that by doing
an fstat first. This was mostly fine, but fstat calls onReadFromDisk,
which isn't true for the socket case (which causes upset for threads
that are allowed to touch the network but not allowed to touch disk,
which Chrome uses, even though it's not immediately obvious to me why
that makes any sense).

Bug: 4972558
Bug: 12133112
Change-Id: Ic0b89d1f181e436b4f43c1c04c1f706883ab84c0
04428d61d7000e17ab21d08a1d672c34eb68f6e2 10-May-2014 Elliott Hughes <enh@google.com> Add android.system.Os.link for link(2).

Bug: 14683762
Change-Id: Ieeba1d2d0c5e9c05e85c6ffbaeb5a7febc69238c
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
11f07d30d2e344b48f132ec6ed105d85423052c2 04-Feb-2014 Elliott Hughes <enh@google.com> Add posix_fallocate to Libcore.os.

(The Java API takes longs for the off_t arguments, and uses posix_fallocate64
behind the scenes.)

Bug: 5287571
Change-Id: I48566d8720c6b41ab42a402eeb322d054d2029ea
0b6b3e10459fc3a3f4dd280dab8d4a145f7bf2f0 01-Feb-2014 Elliott Hughes <enh@google.com> Move the hidden File.readlink into Libcore.os.

Change-Id: Ia983909e62d3806027dff870f0148dd07c31bf01
2e767cfb798ceb59cef27a097edd55ba1d99f7f9 11-Dec-2013 Narayan Kamath <narayan@google.com> Remove blockguard check for getaddrinfo.

Change-Id: Ia45aa76e42b06d7ed405d7a2f6851658fec0bff0
b46217c4c5ff99126eb31a4d2c6ad020fcb89a08 11-Dec-2013 Narayan Kamath <narayan@google.com> Remove blockguard check for getaddrinfo.

Change-Id: Ia45aa76e42b06d7ed405d7a2f6851658fec0bff0
edaa74db58376b7528434707304d081591df2fb5 27-Sep-2013 Jeff Sharkey <jsharkey@android.com> Catch more system calls that result in disk I/O.

Change-Id: If3d941154c658bd87ed968ae4d40cfb6806242ce
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
26010ab930a2cee3bf10b9612cf070183c21228b 24-Jul-2012 Elliott Hughes <enh@google.com> Declare that various Posix methods can throw SocketException.

Bug: 5177516
Change-Id: Icf2f06c7df6686dd1f54a930bc3fa50b1ce4e1d4
4ff585466887785d48c02d14a15dcde64934442b 22-Nov-2011 JP Abgrall <jpa@google.com> libcore: BlockGuard: untag socket on close

java.net.Socket creates the socket on connect(). But in case of failure
during the connect() it closes the socket.
During the create, BlockGuard's socket() is the one tagging the socket.
But in case of failure, nobody untags that socket.
So now we untag scokets on close() in BlockGuard

Bug: 5274621
Change-Id: I282665a05e2dc184df77c84ceab49fb55b7695af
e8e19f6476b30ccf9f69925c10ce62efdba4e62a 21-Oct-2011 Elliott Hughes <enh@google.com> Cope with fstat(2) failures during close.

Whatever the root cause of the fstat(2) failure, we should still attempt the
requested close(2) --- even if it's just going to fail in the same way the
fstat(2) did.

Bug: 5407056
Change-Id: Ie988d1b1ebdb6b378fb537b2f56245fab568ee7c
9c8130231a0e1c2a5ded68e99f782427bb5326fa 11-Aug-2011 Elliott Hughes <enh@google.com> Use Libcore.os.fstat to recognize socket FileDescriptors in BlockGuard.

Exception throwing is pretty slow, and BlockGuard's isLingerSocket
causes us to throw whenever we close a non-socket fd. Avoid that
by adding a cheap test for socket fds and only calling isLingerSocket
on socket fds.

Bug: 4972558
Change-Id: Ib18d6c0c091cb366f953d7467e83fad570bb3457
5112325117859c7c6cd042c17f519f967c551b20 29-Jun-2011 Jesse Wilson <jessewilson@google.com> Move socket tagging to frameworks/base.

Change-Id: I6f6f840d5d5eee6ca2170fc127fd525155dd40b8
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
553d98af897f7202de5e5a776287de0b5ca8fe39 19-May-2011 Elliott Hughes <enh@google.com> Expose accept(2).

The implementation of PlainSocketImpl.accept is made ugly by the fact that the
SocketImpl we mutate may share its FileDescriptor with a SocketChannel, so we
need to mutate the FileDescriptor itself, and can't simply swap in a new one.
I've raised http://b/4452981 to see if we can integrate the nio and io socket
classes more closely, to avoid this kind of mess.

Bug: 3107501
Change-Id: I4964b64c25e936a44d1e4c22504ca29bba247ab6
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
1e8d508f2d97e19f2fc8a709330ea97e1e9f203a 04-May-2011 Jeff Sharkey <jsharkey@android.com> Add Socket tagging for granular data accounting.

Changes BlockGuard to maintain a set of "tags" for the current thread,
which it communicates to kernel before each Socket use. Also changes
HttpConnectionPool to tag/untag sockets as they are recycled.

Change-Id: I33e614f1f570466bdffbf07cc5c718f18b8f3773
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
70c820401677ca251ad09ac64cc23c760764e75d 12-May-2011 Elliott Hughes <enh@google.com> Expose poll(2) and reimplement java.nio.channels.Selector.

This also adds UnsafeArrayList<T>, which is like ArrayList but lets you access
the underlying array (as opposed to ArrayList.toArray which creates a copy).

Bug: 3107501
Change-Id: I8dc570a9fd7951b1435047017ea7aa19f8f8fc53
996bf79565ac88402920bd826d6f85952c83be20 10-May-2011 Elliott Hughes <enh@google.com> Expose connect(2).

The new NET_FAILURE_RETRY in Posix.cpp is intended to replace the legacy one
in NetFd.h, but during the transition we need both. The new one also takes care
of the asynchronous Socket.close semantics, and changes the behavior when the
FileDescriptor is invalid on entry: that is now reported as EBADF; it's only
reported as "Socket closed" when we've been round the loop at least once,
giving us reason to believe the socket was ever open. Having had to debug this
distinction, I think the new semantics are less confusing.

Bug: 3107501
Change-Id: I243dc4fa2eddde7ba40e9b66ec8fc555bc4e80f9
bbac92e691de7d570928ddfba639067978e55b06 29-Mar-2011 Elliott Hughes <enh@google.com> Add readv(2)/writev(2).

The old implementation would cheat if it was given non-direct buffers, copying
them into newly-allocated direct buffers. (The network Channel implementations
are worse: they copy all the data into a single buffer, and then read/write
that. I'll get to them eventually.)

Bug: 3107501
Change-Id: I1655bacb042e7ebcde7e5bc5cf2c71e7ce5e30af
78c7cc547101002b9f9043cf3845970719d1bda8 26-Mar-2011 Elliott Hughes <enh@google.com> Add write(2).

Note that this is a functional change, because the old code was wrong: it
assumed that short writes don't happen. I thought we'd (I'd) cleaned this
up just recently, but it looks like I must have only gone through the network
code. Embarrassing.

This also cleans up the previous read change a bit, factoring out a bit more
duplication, and taking advantage of the fact that we now get decent
exceptions thrown from invalid FileDescriptors (meaning we can remove explicit
checks).

Bug: 3107501
Change-Id: I8bd5324836c9d151dceaef5b84ec523a67391b64
26c7025a7a919044771fb89031161bd26fe03032 26-Mar-2011 Elliott Hughes <enh@google.com> Add read(2).

For both byte[]s and ByteBuffers.

Bug: 3107501
Change-Id: I93b781069ade4507371c8fe8c5fda0163fbb2dbb
0ac77ac8e915bff1a863e371f9b363033f9cf759 23-Mar-2011 Elliott Hughes <enh@google.com> Add open(2).

Bug: 3107501
Change-Id: I404030b4c678862465d04f723a6a324663e0af25
f5333fd2094bdac4d6506177b1964b79afa64d77 18-Mar-2011 Elliott Hughes <enh@google.com> Add ftruncate(2).

The claim that "the port library" modifies the file offset appears to only ever
have been true of Harmony's Win32 implementation. Certainly, this is not the
behavior of ftruncate(2), so we can lose the cruft.

Bug: 3107501
Change-Id: I35092fd986296b78c4847c7215765f9997339f37
52724d3ebd4ccaaa4b9f5576e329d4272cde8ea9 17-Mar-2011 Elliott Hughes <enh@google.com> Add fsync(2) and fdatasync(2).

Interesting parts to this change:
* first BlockGuard support (and general delegation support).
* first rethrowing of ErrnoException as IOException.
* switching FileChannelImpl from int to FileDescriptor.

The special case in FileDescriptor.sync has been removed. Testing with the RI
showed that it doesn't treat syncing a FileDescriptor that corresponds to a
socket as a special case --- it throws SyncFailedException just like normal.

Bug: 3107501
Change-Id: I99faf120bd802aec0397a79772ed38c5e1542fed