diff options
author | root <root> | 2009-08-19 23:44:51 +0000 |
---|---|---|
committer | root <root> | 2009-08-19 23:44:51 +0000 |
commit | 7e01fd517f7b34988d3438bdde655b75c389de2d (patch) | |
tree | a3d40ab1d554899ad553eb38c35d59d0866b01cc | |
parent | 72dedbe4624c9dfb3b928a1c3e2d4d5c23bb144c (diff) |
*** empty log message ***
-rw-r--r-- | Changes | 2 | ||||
-rw-r--r-- | ev.c | 24 | ||||
-rw-r--r-- | ev.pod | 16 | ||||
-rw-r--r-- | ev_win32.c | 4 |
4 files changed, 34 insertions, 12 deletions
@@ -1,6 +1,8 @@ Revision history for libev, a high-performance and full-featured event loop. - backport inotify code to C89. + - implement EV_WIN32_HANDLE_TO_FD and EV_WIN32_CLOSE_FD configuration + symbols to make ti easier for apps to do their own fd management. 3.8 Sun Aug 9 14:30:45 CEST 2009 - incompatible change: do not necessarily reset signal handler @@ -478,6 +478,16 @@ static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ #endif +#ifndef EV_FD_TO_WIN32_HANDLE +# define EV_FD_TO_WIN32_HANDLE(fd) _get_osfhandle (fd) +#endif +#ifndef EV_WIN32_HANDLE_TO_FD +# define EV_WIN32_HANDLE_TO_FD(handle) _open_osfhandle (fd, 0) +#endif +#ifndef EV_WIN32_CLOSE_FD +# define EV_WIN32_CLOSE_FD(fd) close (fd) +#endif + #ifdef _WIN32 # include "ev_win32.c" #endif @@ -878,11 +888,7 @@ fd_reify (EV_P) if (events) { unsigned long arg; - #ifdef EV_FD_TO_WIN32_HANDLE - anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); - #else - anfd->handle = _get_osfhandle (fd); - #endif + anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); } #endif @@ -1623,8 +1629,8 @@ loop_destroy (EV_P) if (evpipe [0] >= 0) { - close (evpipe [0]); - close (evpipe [1]); + EV_WIN32_CLOSE_FD (evpipe [0]); + EV_WIN32_CLOSE_FD (evpipe [1]); } } @@ -1730,8 +1736,8 @@ loop_fork (EV_P) if (evpipe [0] >= 0) { - close (evpipe [0]); - close (evpipe [1]); + EV_WIN32_CLOSE_FD (evpipe [0]); + EV_WIN32_CLOSE_FD (evpipe [1]); } evpipe_init (EV_A); @@ -3665,7 +3665,7 @@ C<_get_osfhandle> on the fd to convert it to an OS handle. Otherwise, it is assumed that all these functions actually work on fds, even on win32. Should not be defined on non-win32 platforms. -=item EV_FD_TO_WIN32_HANDLE +=item EV_FD_TO_WIN32_HANDLE(fd) If C<EV_SELECT_IS_WINSOCKET> is enabled, then libev needs a way to map file descriptors to socket handles. When not defining this symbol (the @@ -3673,6 +3673,20 @@ default), then libev will call C<_get_osfhandle>, which is usually correct. In some cases, programs use their own file descriptor management, in which case they can provide this function to map fds to socket handles. +=item EV_WIN32_HANDLE_TO_FD(handle) + +If C<EV_SELECT_IS_WINSOCKET> then libev maps handles to file descriptors +using the standard C<_open_osfhandle> function. For programs implementing +their own fd to handle mapping, overwriting this function makes it easier +to do so. This can be done by defining this macro to an appropriate value. + +=item EV_WIN32_CLOSE_FD(fd) + +If programs implement their own fd to handle mapping on win32, then this +macro can be used to override the C<close> function, useful to unregister +file descriptors again. Note that the replacement function has to close +the underlying OS handle. + =item EV_USE_POLL If defined to be C<1>, libev will compile in support for the C<poll>(2) @@ -111,8 +111,8 @@ ev_pipe (int filedes [2]) closesocket (listener); #if EV_SELECT_IS_WINSOCKET - filedes [0] = _open_osfhandle (sock [0], 0); - filedes [1] = _open_osfhandle (sock [1], 0); + filedes [0] = EV_WIN32_HANDLE_TO_FD (sock [0]); + filedes [1] = EV_WIN32_HANDLE_TO_FD (sock [1]); #else /* when select isn't winsocket, we also expect socket, connect, accept etc. * to work on fds */ |