Пример #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);
 }