Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

io_wait.h File Reference

#include <errno.h>
#include <string.h>
#include <sys/poll.h>
#include <fcntl.h>
#include "dprint.h"
#include "poll_types.h"
#include "compiler_opt.h"

Go to the source code of this file.

Data Structures

struct  fd_map
struct  io_wait_handler

Defines

#define _GNU_SOURCE
#define get_fd_map(h, fd)   (&(h)->fd_hash[(fd)])
#define unhash_fd_map(pfm)
#define fd_array_setup(ev)
#define set_fd_flags(f)
#define IO_FD_CLOSING   16
#define fix_fd_array
#define fd_array_chg(ev)

Typedefs

typedef int fd_type
typedef io_wait_handler io_wait_h

Functions

fd_maphash_fd_map (io_wait_h *h, int fd, short events, fd_type type, void *data)
int handle_io (struct fd_map *fm, short events, int idx)
int io_watch_add (io_wait_h *h, int fd, short events, fd_type type, void *data)
int io_watch_del (io_wait_h *h, int fd, int idx, int flags)
int io_watch_chg (io_wait_h *h, int fd, short events, int idx)
int io_wait_loop_poll (io_wait_h *h, int t, int repeat)
int init_io_wait (io_wait_h *h, int max_fd, enum poll_types poll_method)
void destroy_io_wait (io_wait_h *h)

Variables

int _os_ver


Define Documentation

#define _GNU_SOURCE
 

Definition at line 64 of file io_wait.h.

#define fd_array_chg ev   ) 
 

Value:

do{\
                        if (unlikely(idx==-1)){ \
                                /* fix idx if -1 and needed */ \
                                for (idx=0; (idx<h->fd_no) && \
                                                        (h->fd_array[idx].fd!=fd); idx++); \
                        } \
                        if (likely(idx<h->fd_no)){ \
                                h->fd_array[idx].events=(ev); \
                        } \
        }while(0)

Referenced by io_watch_chg().

#define fd_array_setup ev   ) 
 

Value:

do{ \
                h->fd_array[h->fd_no].fd=fd; \
                h->fd_array[h->fd_no].events=(ev); /* useless for select */ \
                h->fd_array[h->fd_no].revents=0;     /* useless for select */ \
        }while(0)

Referenced by io_watch_add().

#define fix_fd_array
 

Value:

do{\
                        if (unlikely(idx==-1)){ \
                                /* fix idx if -1 and needed */ \
                                for (idx=0; (idx<h->fd_no) && \
                                                        (h->fd_array[idx].fd!=fd); idx++); \
                        } \
                        if (likely(idx<h->fd_no)){ \
                                memmove(&h->fd_array[idx], &h->fd_array[idx+1], \
                                        (h->fd_no-(idx+1))*sizeof(*(h->fd_array))); \
                                if ((idx<=h->crt_fd_array_idx) && (h->crt_fd_array_idx>=0)) \
                                        h->crt_fd_array_idx--; \
                        } \
        }while(0)

#define get_fd_map h,
fd   )     (&(h)->fd_hash[(fd)])
 

Definition at line 188 of file io_wait.h.

Referenced by io_wait_loop_poll(), io_watch_add(), io_watch_chg(), and io_watch_del().

#define IO_FD_CLOSING   16
 

Definition at line 539 of file io_wait.h.

Referenced by handle_stream_read().

#define set_fd_flags  ) 
 

Value:

do{ \
                        flags=fcntl(fd, F_GETFL); \
                        if (flags==-1){ \
                                LOG(L_ERR, "ERROR: io_watch_add: fnctl: GETFL failed:" \
                                                " %s [%d]\n", strerror(errno), errno); \
                                goto error; \
                        } \
                        if (fcntl(fd, F_SETFL, flags|(f))==-1){ \
                                LOG(L_ERR, "ERROR: io_watch_add: fnctl: SETFL" \
                                                        " failed: %s [%d]\n", strerror(errno), errno); \
                                goto error; \
                        } \
        }while(0)

Referenced by io_watch_add().

#define unhash_fd_map pfm   ) 
 

Value:

do{ \
                (pfm)->type=0 /*F_NONE */; \
                (pfm)->fd=-1; \
        }while(0)

Definition at line 191 of file io_wait.h.

Referenced by io_watch_add(), and io_watch_del().


Typedef Documentation

typedef int fd_type
 

Definition at line 116 of file io_wait.h.

typedef struct io_wait_handler io_wait_h
 

Definition at line 184 of file io_wait.h.

Referenced by destroy_io_wait(), and init_io_wait().


Function Documentation

void destroy_io_wait io_wait_h h  ) 
 

Definition at line 583 of file io_wait.c.

References io_wait_handler::fd_array, io_wait_handler::fd_hash, io_wait_h, local_free, POLL_DEVPOLL, POLL_EPOLL_ET, POLL_EPOLL_LT, POLL_KQUEUE, and POLL_SIGIO_RT.

int handle_io struct fd_map fm,
short  events,
int  idx
 

struct fd_map* hash_fd_map io_wait_h h,
int  fd,
short  events,
fd_type  type,
void data
[inline, static]
 

Definition at line 198 of file io_wait.h.

References fd_map::data, fd_map::events, fd_map::fd, io_wait_handler::fd_hash, and fd_map::type.

Referenced by io_watch_add().

int init_io_wait io_wait_h h,
int  max_fd,
enum poll_types  poll_method
 

Definition at line 446 of file io_wait.c.

References _os_ver, check_poll_method(), choose_poll_method(), io_wait_handler::fd_hash, get_sys_version(), io_wait_h, L_CRIT, L_ERR, L_INFO, local_malloc, LOG, io_wait_handler::max_fd_no, POLL_DEVPOLL, POLL_EPOLL_ET, POLL_EPOLL_LT, POLL_KQUEUE, poll_method_str, POLL_POLL, POLL_SELECT, and POLL_SIGIO_RT.

Referenced by io_listen_loop().

int io_wait_loop_poll io_wait_h h,
int  t,
int  repeat
[inline, static]
 

Definition at line 922 of file io_wait.h.

References io_wait_handler::crt_fd_array_idx, fd_map::events, io_wait_handler::fd_array, io_wait_handler::fd_no, get_fd_map, handle_io(), L_CRIT, L_ERR, LOG, io_wait_handler::max_fd_no, fd_map::type, and unlikely.

Referenced by io_listen_loop().

int io_watch_add io_wait_h h,
int  fd,
short  events,
fd_type  type,
void data
[inline, static]
 

Definition at line 293 of file io_wait.h.

References fd_map::data, DBG, fd_map::events, fd_map::fd, fd_array_setup, io_wait_handler::fd_no, get_fd_map, handle_io(), hash_fd_map(), idx, L_CRIT, L_ERR, likely, LOG, io_wait_handler::max_fd_no, my_pid(), POLL_DEVPOLL, POLL_EPOLL_ET, POLL_EPOLL_LT, POLL_KQUEUE, poll_method_str, POLL_POLL, POLL_SELECT, POLL_SIGIO_RT, set_fd_flags, fd_map::type, unhash_fd_map, and unlikely.

Referenced by handle_new_connect(), and io_listen_loop().

int io_watch_chg io_wait_h h,
int  fd,
short  events,
int  idx
[inline, static]
 

Definition at line 731 of file io_wait.h.

References fd_map::data, DBG, fd_map::events, fd_map::fd, fd_array_chg, io_wait_handler::fd_no, get_fd_map, idx, L_CRIT, L_ERR, likely, LOG, io_wait_handler::max_fd_no, POLL_DEVPOLL, POLL_EPOLL_ET, POLL_EPOLL_LT, POLL_KQUEUE, poll_method_str, POLL_POLL, POLL_SELECT, POLL_SIGIO_RT, fd_map::type, and unlikely.

int io_watch_del io_wait_h h,
int  fd,
int  idx,
int  flags
[inline, static]
 

Definition at line 551 of file io_wait.h.

References fd_map::data, DBG, fd_map::events, fd_map::fd, io_wait_handler::fd_no, flags, get_fd_map, idx, L_CRIT, L_ERR, likely, LOG, io_wait_handler::max_fd_no, POLL_DEVPOLL, POLL_EPOLL_ET, POLL_EPOLL_LT, POLL_KQUEUE, poll_method_str, POLL_POLL, POLL_SELECT, POLL_SIGIO_RT, fd_map::type, unhash_fd_map, and unlikely.

Referenced by handle_stream_read().


Variable Documentation

int _os_ver
 

Definition at line 81 of file io_wait.c.

Referenced by check_poll_method(), choose_poll_method(), and init_io_wait().


Generated on Thu Jul 29 04:15:54 2010 for SIPExpressRouter by  doxygen 1.3.9.1