< prev index next >

src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java

Print this page




 173         // sizeof buffer for when polling inotify
 174         private static final int BUFFER_SIZE = 8192;
 175 
 176         private final UnixFileSystem fs;
 177         private final LinuxWatchService watcher;
 178 
 179         // inotify file descriptor
 180         private final int ifd;
 181         // socketpair used to shutdown polling thread
 182         private final int socketpair[];
 183         // maps watch descriptor to Key
 184         private final Map<Integer,LinuxWatchKey> wdToKey;
 185         // address of read buffer
 186         private final long address;
 187 
 188         Poller(UnixFileSystem fs, LinuxWatchService watcher, int ifd, int[] sp) {
 189             this.fs = fs;
 190             this.watcher = watcher;
 191             this.ifd = ifd;
 192             this.socketpair = sp;
 193             this.wdToKey = new HashMap<Integer,LinuxWatchKey>();
 194             this.address = unsafe.allocateMemory(BUFFER_SIZE);
 195         }
 196 
 197         @Override
 198         void wakeup() throws IOException {
 199             // write to socketpair to wakeup polling thread
 200             try {
 201                 write(socketpair[1], address, 1);
 202             } catch (UnixException x) {
 203                 throw new IOException(x.errorString());
 204             }
 205         }
 206 
 207         @Override
 208         Object implRegister(Path obj,
 209                             Set<? extends WatchEvent.Kind<?>> events,
 210                             WatchEvent.Modifier... modifiers)
 211         {
 212             UnixPath dir = (UnixPath)obj;
 213 


 440 
 441     // offsets of inotify_event
 442     private static native int[] eventOffsets();
 443 
 444     private static native int inotifyInit() throws UnixException;
 445 
 446     private static native int inotifyAddWatch(int fd, long pathAddress, int mask)
 447         throws UnixException;
 448 
 449     private static native void inotifyRmWatch(int fd, int wd)
 450         throws UnixException;
 451 
 452     private static native void configureBlocking(int fd, boolean blocking)
 453         throws UnixException;
 454 
 455     private static native void socketpair(int[] sv) throws UnixException;
 456 
 457     private static native int poll(int fd1, int fd2) throws UnixException;
 458 
 459     static {
 460         AccessController.doPrivileged(new PrivilegedAction<Void>() {
 461             public Void run() {
 462                 System.loadLibrary("nio");
 463                 return null;
 464         }});
 465     }
 466 }


 173         // sizeof buffer for when polling inotify
 174         private static final int BUFFER_SIZE = 8192;
 175 
 176         private final UnixFileSystem fs;
 177         private final LinuxWatchService watcher;
 178 
 179         // inotify file descriptor
 180         private final int ifd;
 181         // socketpair used to shutdown polling thread
 182         private final int socketpair[];
 183         // maps watch descriptor to Key
 184         private final Map<Integer,LinuxWatchKey> wdToKey;
 185         // address of read buffer
 186         private final long address;
 187 
 188         Poller(UnixFileSystem fs, LinuxWatchService watcher, int ifd, int[] sp) {
 189             this.fs = fs;
 190             this.watcher = watcher;
 191             this.ifd = ifd;
 192             this.socketpair = sp;
 193             this.wdToKey = new HashMap<>();
 194             this.address = unsafe.allocateMemory(BUFFER_SIZE);
 195         }
 196 
 197         @Override
 198         void wakeup() throws IOException {
 199             // write to socketpair to wakeup polling thread
 200             try {
 201                 write(socketpair[1], address, 1);
 202             } catch (UnixException x) {
 203                 throw new IOException(x.errorString());
 204             }
 205         }
 206 
 207         @Override
 208         Object implRegister(Path obj,
 209                             Set<? extends WatchEvent.Kind<?>> events,
 210                             WatchEvent.Modifier... modifiers)
 211         {
 212             UnixPath dir = (UnixPath)obj;
 213 


 440 
 441     // offsets of inotify_event
 442     private static native int[] eventOffsets();
 443 
 444     private static native int inotifyInit() throws UnixException;
 445 
 446     private static native int inotifyAddWatch(int fd, long pathAddress, int mask)
 447         throws UnixException;
 448 
 449     private static native void inotifyRmWatch(int fd, int wd)
 450         throws UnixException;
 451 
 452     private static native void configureBlocking(int fd, boolean blocking)
 453         throws UnixException;
 454 
 455     private static native void socketpair(int[] sv) throws UnixException;
 456 
 457     private static native int poll(int fd1, int fd2) throws UnixException;
 458 
 459     static {
 460         AccessController.doPrivileged(new PrivilegedAction<>() {
 461             public Void run() {
 462                 System.loadLibrary("nio");
 463                 return null;
 464         }});
 465     }
 466 }
< prev index next >