2362N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Linux implementation of WatchService based on inotify. 0N/A * In summary a background thread polls inotify plus a socket used for the wakeup 0N/A * mechanism. Requests to add or remove a watch, or close the watch service, 0N/A * cause the thread to wakeup and process the request. Events are processed 0N/A * by the thread which causes it to signal/queue the corresponding watch keys. 0N/A // background thread to read change events 0N/A // initialize inotify 0N/A // configure inotify to be non-blocking 0N/A // create socketpair used in the close mechanism 0N/A // delegate to poller 0N/A // delegate to poller 0N/A * WatchKey implementation 0N/A // inotify descriptor 0N/A // delegate to poller 0N/A * Background thread to read from inotify 0N/A * struct inotify_event { 0N/A * char name __flexarr; // present if len > 0 0N/A // sizeof buffer for when polling inotify 0N/A // inotify file descriptor 0N/A // socketpair used to shutdown polling thread 0N/A // maps watch descriptor to Key 0N/A // address of read buffer 0N/A // write to socketpair to wakeup polling thread 0N/A // no modifiers supported at this time 0N/A // check file is directory 0N/A // register with inotify (replaces existing mask if already registered) 0N/A // ensure watch descriptor is in map 0N/A // cancel single key 0N/A // close watch service 0N/A // invalidate all keys 0N/A // wait for close or inotify event 0N/A // read from inotify 0N/A // process any pending requests 0N/A // iterate over buffer to decode events 0N/A // null-terminated and maybe additional null bytes to 0N/A // align the next event * map inotify event to WatchEvent.Kind * Process event from inotify // overflow - signal all keys return;
// should not happen // event for directory itself // map to event and queue to key // offsets of inotify_event