446
447 } finally {
448 if (!registered) CloseHandle(handle);
449 }
450 }
451
452 /**
453 * Cancels the outstanding I/O operation on the directory
454 * associated with the given key and releases the associated
455 * resources.
456 */
457 private void releaseResources(WindowsWatchKey key) {
458 try {
459 CancelIo(key.handle());
460 GetOverlappedResult(key.handle(), key.overlappedAddress());
461 } catch (WindowsException expected) {
462 // expected as I/O operation has been cancelled
463 }
464 CloseHandle(key.handle());
465 closeAttachedEvent(key.overlappedAddress());
466 key.buffer().cleaner().clean();
467 }
468
469 /**
470 * Creates an unnamed event and set it as the hEvent field
471 * in the given OVERLAPPED structure
472 */
473 private void createAndAttachEvent(long ov) throws WindowsException {
474 long hEvent = CreateEvent(false, false);
475 UNSAFE.putAddress(ov + OFFSETOF_HEVENT, hEvent);
476 }
477
478 /**
479 * Closes the event attached to the given OVERLAPPED structure. A
480 * no-op if there isn't an event attached.
481 */
482 private void closeAttachedEvent(long ov) {
483 long hEvent = UNSAFE.getAddress(ov + OFFSETOF_HEVENT);
484 if (hEvent != 0 && hEvent != INVALID_HANDLE_VALUE)
485 CloseHandle(hEvent);
486 }
|
446
447 } finally {
448 if (!registered) CloseHandle(handle);
449 }
450 }
451
452 /**
453 * Cancels the outstanding I/O operation on the directory
454 * associated with the given key and releases the associated
455 * resources.
456 */
457 private void releaseResources(WindowsWatchKey key) {
458 try {
459 CancelIo(key.handle());
460 GetOverlappedResult(key.handle(), key.overlappedAddress());
461 } catch (WindowsException expected) {
462 // expected as I/O operation has been cancelled
463 }
464 CloseHandle(key.handle());
465 closeAttachedEvent(key.overlappedAddress());
466 key.buffer().cleanable().clean();
467 }
468
469 /**
470 * Creates an unnamed event and set it as the hEvent field
471 * in the given OVERLAPPED structure
472 */
473 private void createAndAttachEvent(long ov) throws WindowsException {
474 long hEvent = CreateEvent(false, false);
475 UNSAFE.putAddress(ov + OFFSETOF_HEVENT, hEvent);
476 }
477
478 /**
479 * Closes the event attached to the given OVERLAPPED structure. A
480 * no-op if there isn't an event attached.
481 */
482 private void closeAttachedEvent(long ov) {
483 long hEvent = UNSAFE.getAddress(ov + OFFSETOF_HEVENT);
484 if (hEvent != 0 && hEvent != INVALID_HANDLE_VALUE)
485 CloseHandle(hEvent);
486 }
|