blob: 8c3a1ff9ae0daa452b8ecef98b0c5adbcd3a7236 [file] [log] [blame]
Benny Prijono9033e312005-11-21 02:08:39 +00001/* $Id */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/* ioqueue_common_abs.h
21 *
22 * This file contains private declarations for abstracting various
23 * event polling/dispatching mechanisms (e.g. select, poll, epoll)
24 * to the ioqueue.
25 */
26
27#include <pj/list.h>
28
29/*
30 * The select ioqueue relies on socket functions (pj_sock_xxx()) to return
31 * the correct error code.
32 */
33#if PJ_RETURN_OS_ERROR(100) != PJ_STATUS_FROM_OS(100)
34# error "Proper error reporting must be enabled for ioqueue to work!"
35#endif
36
37
38struct generic_operation
39{
40 PJ_DECL_LIST_MEMBER(struct generic_operation);
41 pj_ioqueue_operation_e op;
42};
43
44struct read_operation
45{
46 PJ_DECL_LIST_MEMBER(struct read_operation);
47 pj_ioqueue_operation_e op;
48
49 void *buf;
50 pj_size_t size;
51 unsigned flags;
52 pj_sockaddr_t *rmt_addr;
53 int *rmt_addrlen;
54};
55
56struct write_operation
57{
58 PJ_DECL_LIST_MEMBER(struct write_operation);
59 pj_ioqueue_operation_e op;
60
61 char *buf;
62 pj_size_t size;
63 pj_ssize_t written;
64 unsigned flags;
65 pj_sockaddr_in rmt_addr;
66 int rmt_addrlen;
67};
68
69#if PJ_HAS_TCP
70struct accept_operation
71{
72 PJ_DECL_LIST_MEMBER(struct accept_operation);
73 pj_ioqueue_operation_e op;
74
75 pj_sock_t *accept_fd;
76 pj_sockaddr_t *local_addr;
77 pj_sockaddr_t *rmt_addr;
78 int *addrlen;
79};
80#endif
81
82union operation_key
83{
84 struct generic_operation generic;
85 struct read_operation read;
86 struct write_operation write;
87#if PJ_HAS_TCP
88 struct accept_operation accept;
89#endif
90};
91
92#define DECLARE_COMMON_KEY \
93 PJ_DECL_LIST_MEMBER(struct pj_ioqueue_key_t); \
94 pj_ioqueue_t *ioqueue; \
95 pj_mutex_t *mutex; \
96 pj_sock_t fd; \
97 int fd_type; \
98 void *user_data; \
99 pj_ioqueue_callback cb; \
100 int connecting; \
101 struct read_operation read_list; \
102 struct write_operation write_list; \
103 struct accept_operation accept_list;
104
105
106#define DECLARE_COMMON_IOQUEUE \
107 pj_lock_t *lock; \
108 pj_bool_t auto_delete_lock;
109
110
111enum ioqueue_event_type
112{
113 NO_EVENT,
114 READABLE_EVENT,
115 WRITEABLE_EVENT,
116 EXCEPTION_EVENT,
117};
118
119static void ioqueue_add_to_set( pj_ioqueue_t *ioqueue,
120 pj_sock_t fd,
121 enum ioqueue_event_type event_type );
122static void ioqueue_remove_from_set( pj_ioqueue_t *ioqueue,
123 pj_sock_t fd,
124 enum ioqueue_event_type event_type);
125