poll.c

Cross-platform polling library for C
git clone git://git.finwo.net/lib/poll.c
Log | Files | Refs | README

poll_compat.h (1591B)


      1 /*
      2  * Public domain
      3  *
      4  * poll(2) emulation for Windows
      5  *
      6  * This emulates just-enough poll functionality on Windows to work in the
      7  * context of this program. This is not a replacement for POSIX.1-2001 poll(2),
      8  * though it may come closer than I care to admit.
      9  *
     10  * Dongsheng Song <dongsheng.song@gmail.com>
     11  * Brent Cook <bcook@openbsd.org>
     12  */
     13 
     14 #ifndef COMPAT_POLL_H
     15 #define COMPAT_POLL_H
     16 
     17 #ifndef _WIN32
     18 #include_next <poll.h>
     19 #else
     20 
     21 #include <winsock2.h>
     22 
     23 /* Type used for the number of file descriptors. */
     24 typedef unsigned long int nfds_t;
     25 
     26 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0600)
     27 /* Data structure describing a polling request. */
     28 struct pollfd {
     29 	int fd; /* file descriptor */
     30 	short events; /* requested events */
     31 	short revents; /* returned events */
     32 };
     33 
     34 /* Event types that can be polled */
     35 #define POLLIN 0x001 /* There is data to read. */
     36 #define POLLPRI 0x002 /* There is urgent data to read. */
     37 #define POLLOUT 0x004 /* Writing now will not block. */
     38 
     39 # define POLLRDNORM 0x040 /* Normal data may be read. */
     40 # define POLLRDBAND 0x080 /* Priority data may be read. */
     41 # define POLLWRNORM 0x100 /* Writing now will not block. */
     42 # define POLLWRBAND 0x200 /* Priority data may be written. */
     43 
     44 /* Event types always implicitly polled. */
     45 #define POLLERR 0x008 /* Error condition. */
     46 #define POLLHUP 0x010 /* Hung up. */
     47 #define POLLNVAL 0x020 /* Invalid polling request. */
     48 
     49 #endif
     50 
     51 #ifdef __cplusplus
     52 extern "C" {
     53 #endif
     54 
     55 int poll(struct pollfd *pfds, nfds_t nfds, int timeout);
     56 
     57 #ifdef __cplusplus
     58 }
     59 #endif
     60 
     61 #endif /* HAVE_POLL */
     62 
     63 #endif /* COMPAT_POLL_H */