Go to the documentation of this file.
23 #ifdef HAVE_SYS_SELECT_H
24 # include <sys/select.h>
28 static void _mio_fds_init(mio_priv_t m) \
31 for(fd = 0; fd < m->maxfd; fd++) \
33 m->fds[fd].mio_fd.fd = fd; \
36 m->lowfd = m->maxfd; \
39 static mio_fd_t _mio_alloc_fd(mio_priv_t m, int fd) \
41 if(fd > m->highfd) m->highfd = fd; \
42 if(fd < m->lowfd) m->lowfd = fd; \
43 return &m->fds[fd].mio_fd; \
46 static int _mio_select(mio_priv_t m, int t) \
50 m->rfds_out = m->rfds_in; \
51 m->wfds_out = m->wfds_in; \
55 return select(m->highfd + 1, &m->rfds_out, &m->wfds_out, NULL, &tv); \
61 struct mio_priv_fd_st *fds; \
64 fd_set rfds_in, wfds_in, rfds_out, wfds_out;
66 #define MIO_INIT_VARS(m) \
68 if (maxfd > FD_SETSIZE) \
70 mio_debug(ZONE,"wanted MIO larger than %d file descriptors", FD_SETSIZE); \
75 if((MIO(m)->fds = calloc(1, sizeof(struct mio_priv_fd_st) * maxfd)) == NULL) \
77 mio_debug(ZONE,"internal error creating new mio"); \
82 _mio_fds_init(MIO(m)); \
83 FD_ZERO(&MIO(m)->rfds_in); \
84 FD_ZERO(&MIO(m)->wfds_in); \
87 #define MIO_FREE_VARS(m) free(MIO(m)->fds)
89 #define MIO_ALLOC_FD(m, rfd) _mio_alloc_fd(MIO(m), rfd)
90 #define MIO_FREE_FD(m, mfd)
92 #define MIO_REMOVE_FD(m, mfd) \
94 FD_CLR(mfd->mio_fd.fd, &MIO(m)->rfds_in); \
95 FD_CLR(mfd->mio_fd.fd, &MIO(m)->wfds_in); \
98 #define MIO_CHECK(m, t) _mio_select(MIO(m), t)
100 #define MIO_SET_READ(m, mfd) FD_SET(mfd->mio_fd.fd, &MIO(m)->rfds_in)
101 #define MIO_SET_WRITE(m, mfd) FD_SET(mfd->mio_fd.fd, &MIO(m)->wfds_in)
103 #define MIO_UNSET_READ(m, mfd) FD_CLR(mfd->mio_fd.fd, &MIO(m)->rfds_in)
104 #define MIO_UNSET_WRITE(m, mfd) FD_CLR(mfd->mio_fd.fd, &MIO(m)->wfds_in)
106 #define MIO_CAN_READ(m, iter) FD_ISSET(iter, &MIO(m)->rfds_out)
107 #define MIO_CAN_WRITE(m, iter) FD_ISSET(iter, &MIO(m)->wfds_out)
108 #define MIO_CAN_FREE(m) 1
111 #define MIO_INIT_ITERATOR(iter) \
114 #define MIO_ITERATE_RESULTS(m, retval, iter) \
115 for(iter = MIO(m)->lowfd; iter <= MIO(m)->highfd; iter++)
117 #define MIO_ITERATOR_FD(m, iter) \
118 (&MIO(m)->fds[iter].mio_fd)