io_wait.h File Reference

tcp io wait common stuff used by tcp_main.c & tcp_read.c More...

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

Include dependency graph for io_wait.h:

Go to the source code of this file.

Data Structures

struct  fd_map
 maps a fd to some other structure; used in almost all cases except epoll and maybe kqueue or /dev/poll More...
struct  io_wait_handler
 handler structure More...

Defines

#define fd_array_setup
#define fix_fd_array
#define get_fd_map(h, fd)   (&(h)->fd_hash[(fd)])
 get the corresponding fd_map structure pointer
#define IO_FD_CLOSING   16
#define set_fd_flags(f)
#define unhash_fd_map(pfm)
 remove a fd_map structure from the hash; the pointer must be returned by get_fd_map or hash_fd_map

Typedefs

typedef int fd_type
typedef struct io_wait_handler io_wait_h

Functions

void destroy_io_wait (io_wait_h *h)
 destroys everything init_io_wait allocated
static int handle_io (struct fd_map *fm, int idx)
static struct fd_maphash_fd_map (io_wait_h *h, int fd, fd_type type, void *data)
 add a fd_map structure to the fd hash
int init_io_wait (io_wait_h *h, int max_fd, enum poll_types poll_method)
 initializes the static vars/arrays
static int io_wait_loop_poll (io_wait_h *h, int t, int repeat)
 io_wait_loop_x style function wait for io using poll()
static int io_watch_add (io_wait_h *h, int fd, fd_type type, void *data)
 generic io_watch_add function
static int io_watch_del (io_wait_h *h, int fd, int idx, int flags)


Detailed Description

tcp io wait common stuff used by tcp_main.c & tcp_read.c

Definition in file io_wait.h.


Define Documentation

#define fd_array_setup

Value:

do{ \
      h->fd_array[h->fd_no].fd=fd; \
      h->fd_array[h->fd_no].events=POLLIN; /* 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

Referenced by io_watch_del().

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

get the corresponding fd_map structure pointer

Definition at line 168 of file io_wait.h.

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

#define IO_FD_CLOSING   16

Definition at line 463 of file io_wait.h.

Referenced by io_watch_del().

#define set_fd_flags (  ) 

Referenced by io_watch_add().

#define unhash_fd_map ( pfm   ) 

Value:

do{ \
      (pfm)->type=0 /*F_NONE */; \
      (pfm)->fd=-1; \
   }while(0)
remove a fd_map structure from the hash; the pointer must be returned by get_fd_map or hash_fd_map

Definition at line 173 of file io_wait.h.

Referenced by io_watch_add(), and io_watch_del().


Typedef Documentation

typedef int fd_type

Definition at line 102 of file io_wait.h.

typedef struct io_wait_handler io_wait_h

Definition at line 164 of file io_wait.h.


Function Documentation

void destroy_io_wait ( io_wait_h h  ) 

destroys everything init_io_wait allocated

static int handle_io ( struct fd_map fm,
int  idx 
) [static]

Definition at line 210 of file io_wait.h.

Referenced by io_wait_loop_poll(), and io_watch_add().

static struct fd_map* hash_fd_map ( io_wait_h h,
int  fd,
fd_type  type,
void *  data 
) [static, read]

add a fd_map structure to the fd hash

Definition at line 180 of file io_wait.h.

References fd_map::data, 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 
)

initializes the static vars/arrays

Parameters:
h pointer to the io_wait_h that will be initialized
max_fd maximum allowed fd number
poll_method poll method (0 for automatic best fit)

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

io_wait_loop_x style function wait for io using poll()

Parameters:
h io_wait handle
t timeout in s
repeat if !=0 handle_io will be called until it returns <=0
Returns:
number of IO events handled on success (can be 0), -1 on error

Definition at line 632 of file io_wait.h.

References io_wait_handler::fd_array, io_wait_handler::fd_no, get_fd_map, handle_io(), LM_CRIT, LM_ERR, and io_wait_handler::max_fd_no.

static int io_watch_add ( io_wait_h h,
int  fd,
fd_type  type,
void *  data 
) [inline, static]

generic io_watch_add function

Returns:
0 on success, -1 on error
this version should be faster than pointers to poll_method specific functions (it avoids functions calls, the overhead being only an extra switch())

Definition at line 260 of file io_wait.h.

References fd_map::data, fd_map::fd, fd_array_setup, io_wait_handler::fd_no, get_fd_map, handle_io(), hash_fd_map(), LM_CRIT, LM_DBG, LM_ERR, io_wait_handler::max_fd_no, my_pid(), POLL_DEVPOLL, POLL_EPOLL_ET, POLL_EPOLL_LT, POLL_KQUEUE, io_wait_handler::poll_method, poll_method_str, POLL_POLL, POLL_SELECT, POLL_SIGIO_RT, set_fd_flags, fd_map::type, and unhash_fd_map.

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

Parameters:
h handler
fd file descriptor
idx index in the fd_array if known, -1 if not (if index==-1 fd_array will be searched for the corresponding fd* entry -- slower but unavoidable in some cases). index is not used (no fd_array) for epoll, /dev/poll and kqueue
flags optimization flags, e.g. IO_FD_CLOSING, the fd was or will shortly be closed, in some cases we can avoid extra remove operations (e.g.: epoll, kqueue, sigio)
Returns:
0 if ok, -1 on error

Definition at line 479 of file io_wait.h.

References fd_map::data, fd_map::fd, io_wait_handler::fd_no, fix_fd_array, get_fd_map, IO_FD_CLOSING, LM_CRIT, LM_DBG, LM_ERR, io_wait_handler::max_fd_no, POLL_DEVPOLL, POLL_EPOLL_ET, POLL_EPOLL_LT, POLL_KQUEUE, io_wait_handler::poll_method, poll_method_str, POLL_POLL, POLL_SELECT, POLL_SIGIO_RT, fd_map::type, and unhash_fd_map.


Generated on Wed May 23 08:01:16 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6