コード例 #1
0
 @Override
 public FileDescriptor open(String path, int flags, int mode) throws ErrnoException {
   BlockGuard.getThreadPolicy().onReadFromDisk();
   if ((mode & O_ACCMODE) != O_RDONLY) {
     BlockGuard.getThreadPolicy().onWriteToDisk();
   }
   return os.open(path, flags, mode);
 }
コード例 #2
0
 @Override
 public int sendto(
     FileDescriptor fd, ByteBuffer buffer, int flags, InetAddress inetAddress, int port)
     throws ErrnoException, SocketException {
   BlockGuard.getThreadPolicy().onNetwork();
   return os.sendto(fd, buffer, flags, inetAddress, port);
 }
コード例 #3
0
 @Override
 public int poll(StructPollfd[] fds, int timeoutMs) throws ErrnoException {
   // Greater than 0 is a timeout in milliseconds and -1 means "block forever",
   // but 0 means "poll and return immediately", which shouldn't be subject to BlockGuard.
   if (timeoutMs != 0) {
     BlockGuard.getThreadPolicy().onNetwork();
   }
   return os.poll(fds, timeoutMs);
 }
コード例 #4
0
 @Override
 public int recvfrom(
     FileDescriptor fd,
     byte[] bytes,
     int byteOffset,
     int byteCount,
     int flags,
     InetSocketAddress srcAddress)
     throws ErrnoException, SocketException {
   BlockGuard.getThreadPolicy().onNetwork();
   return os.recvfrom(fd, bytes, byteOffset, byteCount, flags, srcAddress);
 }
コード例 #5
0
 @Override
 public int sendto(
     FileDescriptor fd,
     byte[] bytes,
     int byteOffset,
     int byteCount,
     int flags,
     InetAddress inetAddress,
     int port)
     throws ErrnoException, SocketException {
   // We permit datagrams without hostname lookups.
   if (inetAddress != null) {
     BlockGuard.getThreadPolicy().onNetwork();
   }
   return os.sendto(fd, bytes, byteOffset, byteCount, flags, inetAddress, port);
 }
コード例 #6
0
 @Override
 public void close(FileDescriptor fd) throws ErrnoException {
   try {
     if (S_ISSOCK(Libcore.os.fstat(fd).st_mode)) {
       if (isLingerSocket(fd)) {
         // If the fd is a socket with SO_LINGER set, we might block indefinitely.
         // We allow non-linger sockets so that apps can close their network
         // connections in methods like onDestroy which will run on the UI thread.
         BlockGuard.getThreadPolicy().onNetwork();
       }
       untagSocket(fd);
     }
   } catch (ErrnoException ignored) {
     // We're called via Socket.close (which doesn't ask for us to be called), so we
     // must not throw here, because Socket.close must not throw if asked to close an
     // already-closed socket. Also, the passed-in FileDescriptor isn't necessarily
     // a socket at all.
   }
   os.close(fd);
 }
コード例 #7
0
 @Override
 public void fsync(FileDescriptor fd) throws ErrnoException {
   BlockGuard.getThreadPolicy().onWriteToDisk();
   os.fsync(fd);
 }
コード例 #8
0
 @Override
 public void connect(FileDescriptor fd, InetAddress address, int port)
     throws ErrnoException, SocketException {
   BlockGuard.getThreadPolicy().onNetwork();
   os.connect(fd, address, port);
 }
コード例 #9
0
 @Override
 public FileDescriptor accept(FileDescriptor fd, InetSocketAddress peerAddress)
     throws ErrnoException, SocketException {
   BlockGuard.getThreadPolicy().onNetwork();
   return tagSocket(os.accept(fd, peerAddress));
 }
コード例 #10
0
 @Override
 public int writev(FileDescriptor fd, Object[] buffers, int[] offsets, int[] byteCounts)
     throws ErrnoException {
   BlockGuard.getThreadPolicy().onWriteToDisk();
   return os.writev(fd, buffers, offsets, byteCounts);
 }
コード例 #11
0
 @Override
 public int write(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)
     throws ErrnoException {
   BlockGuard.getThreadPolicy().onWriteToDisk();
   return os.write(fd, bytes, byteOffset, byteCount);
 }
コード例 #12
0
 @Override
 public int write(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException {
   BlockGuard.getThreadPolicy().onWriteToDisk();
   return os.write(fd, buffer);
 }
コード例 #13
0
 @Override
 public int recvfrom(FileDescriptor fd, ByteBuffer buffer, int flags, InetSocketAddress srcAddress)
     throws ErrnoException, SocketException {
   BlockGuard.getThreadPolicy().onNetwork();
   return os.recvfrom(fd, buffer, flags, srcAddress);
 }
コード例 #14
0
 @Override
 public int read(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount)
     throws ErrnoException {
   BlockGuard.getThreadPolicy().onReadFromDisk();
   return os.read(fd, bytes, byteOffset, byteCount);
 }
コード例 #15
0
 @Override
 public int read(FileDescriptor fd, ByteBuffer buffer) throws ErrnoException {
   BlockGuard.getThreadPolicy().onReadFromDisk();
   return os.read(fd, buffer);
 }
コード例 #16
0
 @Override
 public void ftruncate(FileDescriptor fd, long length) throws ErrnoException {
   BlockGuard.getThreadPolicy().onWriteToDisk();
   os.ftruncate(fd, length);
 }