Skip to content

Commit 0e09706

Browse files
committed
util: add note about event file descriptors on Windows
When using GNULIB with Winsock, libvirt will never see the normal HANDLE objects, instead GNULIB guarantees that libvirt gets a C runtime file descriptor. The GNULIB poll impl also expects to get C runtime file descriptors rather than HANDLE objects. Document this behaviour so that it is clear to applications providing event loop implementations if they need Windows portability. Reviewed-by: Fabiano Fidêncio <[email protected]> Signed-off-by: Daniel P. Berrangé <[email protected]>
1 parent 7201a25 commit 0e09706

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

build-aux/syntax-check.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,7 @@ exclude_file_name_regexp--sc_prohibit_strdup = \
22382238
^(docs/|examples/|src/util/virstring\.c|tests/vir(netserverclient|cgroup)mock.c|tests/commandhelper\.c|tools/nss/libvirt_nss_(leases|macs)\.c$$)
22392239
22402240
exclude_file_name_regexp--sc_prohibit_close = \
2241-
(\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/virfile\.c|src/libvirt-stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c)|tools/nss/libvirt_nss_(leases|macs)\.c)$$)
2241+
(\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/vir(file|event)\.c|src/libvirt-stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c)|tools/nss/libvirt_nss_(leases|macs)\.c)$$)
22422242
22432243
exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF = \
22442244
(^tests/(virhostcpu|virpcitest)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/no-newline\.conf$$)

include/libvirt/libvirt-event.h

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ typedef void (*virEventHandleCallback)(int watch, int fd, int events, void *opaq
6767
* listen for specific events. The same file handle can be registered
6868
* multiple times provided the requested event sets are non-overlapping
6969
*
70+
* @fd will always be a C runtime file descriptor. On Windows
71+
* the _get_osfhandle() method can be used if a HANDLE is required
72+
* instead.
73+
*
7074
* If the opaque user data requires free'ing when the handle
7175
* is unregistered, then a 2nd callback can be supplied for
7276
* this purpose. This callback needs to be invoked from a clean stack.

src/util/virevent.c

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ static virEventRemoveTimeoutFunc removeTimeoutImpl;
6060
* requires that an event loop has previously been registered with
6161
* virEventRegisterImpl() or virEventRegisterDefaultImpl().
6262
*
63+
* @fd must always always be a C runtime file descriptor. On Windows
64+
* if the caller only has a HANDLE, the _open_osfhandle() method can
65+
* be used to open an associated C runtime file descriptor for use
66+
* with this API. After opening a runtime file descriptor, CloseHandle()
67+
* must not be used, instead close() will close the runtime file
68+
* descriptor and its original associated HANDLE.
69+
*
6370
* Returns -1 if the file handle cannot be registered, otherwise a handle
6471
* watch number to be used for updating and unregistering for events.
6572
*/

0 commit comments

Comments
 (0)