Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #60: W32FileMonitor. #100

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ULONG_PTR() {
}

public ULONG_PTR(long value) {
super(Pointer.SIZE, value);
super(Pointer.SIZE, value, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.Map;

import com.sun.jna.Pointer;
import com.sun.jna.platform.FileMonitor;
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTRByReference;
import com.sun.jna.platform.win32.WinBase.OVERLAPPED;
Expand Down Expand Up @@ -109,15 +110,15 @@ private void handleChanges(FileInfo finfo) throws IOException {
}

private FileInfo waitForChange() {
Kernel32 klib = Kernel32.INSTANCE;
IntByReference rcount = new IntByReference();
ULONG_PTRByReference rkey = new ULONG_PTRByReference();
PointerByReference roverlap = new PointerByReference();
klib.GetQueuedCompletionStatus(port, rcount, rkey, roverlap, WinBase.INFINITE);
if (! Kernel32.INSTANCE.GetQueuedCompletionStatus(port, rcount, rkey, roverlap, WinBase.INFINITE))
return null;

synchronized (this) {
return handleMap.get(rkey.getValue());
}
return handleMap.get(new HANDLE(new Pointer(rkey.getValue().longValue())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how this would affect the 32-bit version. In addition, I think all of the _PTR variants should add a .toPointer() method, which further makes clear that their value can be either integer or pointer. rkey.getValue().toPointer() would make this particular expression more clear, and avoid new Pointer(), which implies something different.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added toPointer to ULONG_PTR, which does make this much cleaner.

This affects both the 32 and the 64 bit versions. The problem is that the map has HANDLE and the result of GetQueuedCompletionStatus is a ULONG_PTR. So you cannot lookup one by the other. We could add a way to compare a HANDLE to a Pointer transparently, but that's something that seems like an overkill and a possible source of confusion elsewhere.

}
}

private int convertMask(int mask) {
Expand Down