While starting to think about Windows compability, I realized the newly
exposed API for registering an external EventImpl is not adequate.
Currently it's assuming 32-bit unix fds. But Windows uses a pointer
(HANDLE) here. So we need to generalize this interface so it can be
implemented for 64-bit Windows. The attached patch does this. (I'm
sure it conflicts with work Dan B is doing, so I'm hoping he'll just
incorporate this into his changes.)
Dave
include/libvirt/libvirt.h.in | 24 +++++++++++++++---------
src/event.c | 18 +++++++++---------
2 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 0ee657a..3e4e8de 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1118,20 +1118,26 @@ typedef enum {
VIR_EVENT_HANDLE_HANGUP = (1 << 3),
} virEventHandleType;
+#if (defined _WIN32 || defined __WIN32__)
+typedef HANDLE virHandle;
+#else
+typedef int virHandle;
+#endif
+
/**
* virEventHandleCallback:
*
- * @fd: file handle on which the event occurred
+ * @handle: handle on which the event occurred
* @events: bitset of events from virEventHandleType constants
* @opaque: user data registered with handle
*
* callback for receiving file handle events
*/
-typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
+typedef void (*virEventHandleCallback)(virHandle handle, int events, void *opaque);
/**
* virEventAddHandleFunc:
- * @fd: file descriptor to listen on
+ * @handle: handle to listen on
* @event: bitset of events on which to fire the callback
* @cb: the callback to be called
* @opaque: user data to pass to the callback
@@ -1139,27 +1145,27 @@ typedef void (*virEventHandleCallback)(int fd, int events, void *opaque);
* Part of the EventImpl, this callback Adds a file handle callback to
* listen for specific events
*/
-typedef int (*virEventAddHandleFunc)(int fd, int event,
+typedef int (*virEventAddHandleFunc)(virHandle handle, int event,
virEventHandleCallback cb, void *opaque);
/**
* virEventUpdateHandleFunc:
- * @fd: file descriptor to modify
+ * @handle: handle to modify
* @event: new events to listen on
*
* Part of the EventImpl, this user-provided callback is notified when
* events to listen on change
*/
-typedef void (*virEventUpdateHandleFunc)(int fd, int event);
+typedef void (*virEventUpdateHandleFunc)(virHandle handle, int event);
/**
* virEventRemoveHandleFunc:
- * @fd: file descriptor to stop listening on
+ * @handle: handle to stop listening on
*
* Part of the EventImpl, this user-provided callback is notified when
- * an fd is no longer being listened on
+ * a handle is no longer being listened on
*/
-typedef int (*virEventRemoveHandleFunc)(int fd);
+typedef int (*virEventRemoveHandleFunc)(virHandle handle);
/**
* virEventTimeoutCallback:
diff --git a/src/event.c b/src/event.c
index ac6f886..5740573 100644
--- a/src/event.c
+++ b/src/event.c
@@ -34,23 +34,23 @@ static virEventAddTimeoutFunc addTimeoutImpl = NULL;
static virEventUpdateTimeoutFunc updateTimeoutImpl = NULL;
static virEventRemoveTimeoutFunc removeTimeoutImpl = NULL;
-int virEventAddHandle(int fd, int events, virEventHandleCallback cb,
+int virEventAddHandle(virHandle handle, int events, virEventHandleCallback cb,
void *opaque) {
if (!addHandleImpl)
return -1;
- return addHandleImpl(fd, events, cb, opaque);
+ return addHandleImpl(handle, events, cb, opaque);
}
-void virEventUpdateHandle(int fd, int events) {
- updateHandleImpl(fd, events);
+void virEventUpdateHandle(virHandle handle, int events) {
+ updateHandleImpl(handle, events);
}
-int virEventRemoveHandle(int fd) {
+int virEventRemoveHandle(virHandle handle) {
if (!removeHandleImpl)
return -1;
- return removeHandleImpl(fd);
+ return removeHandleImpl(handle);
}
int virEventAddTimeout(int timeout, virEventTimeoutCallback cb, void *opaque) {
@@ -74,9 +74,9 @@ int virEventRemoveTimeout(int timer) {
/**
* virEventRegisterImpl:
* Register an EventImpl
- * @addHandle: the callback to add fd handles
- * @updateHandle: the callback to update fd handles
- * @removeHandle: the callback to remove fd handles
+ * @addHandle: the callback to add handles
+ * @updateHandle: the callback to update handles
+ * @removeHandle: the callback to remove handles
* @addTimeout: the callback to add a timeout
* @updateTimeout: the callback to update a timeout
* @removeTimeout: the callback to remove a timeout
--
Libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list