3909N/A * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. 893N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 893N/A * This code is free software; you can redistribute it and/or modify it 893N/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 893N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 893N/A * This code is distributed in the hope that it will be useful, but WITHOUT 893N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 893N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 893N/A * version 2 for more details (a copy is included in the LICENSE file that 893N/A * accompanied this code). 893N/A * You should have received a copy of the GNU General Public License version 893N/A * 2 along with this work; if not, write to the Free Software Foundation, 893N/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 893N/A * Win32 implementation of WatchService based on ReadDirectoryChangesW. 893N/A // background thread to service I/O completion port 893N/A * Creates an I/O completion port and a daemon thread to service it 893N/A // create I/O completion port 893N/A * Windows implementation of WatchKey. 893N/A // file key (used to detect existing registrations) 893N/A // buffer for change events 893N/A // pointer to bytes returned (in buffer) 893N/A // pointer to overlapped structure (in buffer) 893N/A // completion key (used to map I/O completion to WatchKey) 893N/A // close directory and release buffer 893N/A // Invalidate key by closing directory and releasing buffer 893N/A // file key to unique identify (open) directory 893N/A * Background thread to service I/O completion port. 893N/A * typedef struct _OVERLAPPED { 893N/A * typedef struct _FILE_NOTIFY_INFORMATION { 893N/A * DWORD NextEntryOffset; 893N/A * DWORD FileNameLength; 893N/A // size of per-directory buffer for events (FIXME - make this configurable) 893N/A // maps completion key to WatchKey 893N/A // maps file key to WatchKey 893N/A // unique completion key for each directory 893N/A * Register a directory for changes as follows: 893N/A * 2. Read its attributes (and check it really is a directory) 893N/A * 3. Assign completion key and associated handle with completion port 893N/A * 4. Call ReadDirectoryChangesW to start (async) read of changes 893N/A * 5. Create or return existing key representing registration 893N/A // FILE_TREE modifier allowed 893N/A // read attributes and check file is a directory 893N/A // check if this directory is already registered 893N/A // if already registered and we're not changing the subtree 893N/A // modifier then simply update the event and return the key. 893N/A // unique completion key (skip 0) 893N/A // associate handle with completion port 893N/A // allocate memory for events, including space for other structures 893N/A // needed to do overlapped I/O 893N/A // start async read of changes to directory 893N/A // not registered so create new watch key 893N/A // map file key to watch key 893N/A // directory already registered so need to: 893N/A // 1. remove mapping from old completion key to existing watch key 893N/A // map completion map to watch key 893N/A // close I/O completion port 893N/A // Translate file change action into watch event 893N/A // process events (list of FILE_NOTIFY_INFORMATION structures) 893N/A // create FileName and queue event 893N/A // this should not happen 893N/A // map completionKey to get WatchKey 893N/A // We get here when a registration is changed. In that case 893N/A // the directory is closed which causes an event with the 893N/A // ReadDirectoryChangesW failed 893N/A // other error so cancel key 893N/A // insufficient buffer size 893N/A // start read for next batch of changes 893N/A // no choice but to cancel key