Debian Codegraph @

Xpjproject/pjlib/src/pj/ioqueue_common_abs.h

raw symbols SCIP
1 /* $Id */
2 /*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /* ioqueue_common_abs.h
22 *
23 * This file contains private declarations for abstracting various
24 * event polling/dispatching mechanisms (e.g. select, poll, epoll)
25 * to the ioqueue.
26 */
27
28 #include <pj/list.h>
29
30 /*
31 * The select ioqueue relies on socket functions (pj_sock_xxx()) to return
32 * the correct error code.
33 */
34 #if PJ_RETURN_OS_ERROR(100) != PJ_STATUS_FROM_OS(100)
35 # error "Proper error reporting must be enabled for ioqueue to work!"
36 #endif
37
38
39 struct generic_operation
40 {
41 PJ_DECL_LIST_MEMBER(struct generic_operation);
42 pj_ioqueue_operation_e op;
43 };
44
45 struct read_operation
46 {
47 PJ_DECL_LIST_MEMBER(struct read_operation);
48 pj_ioqueue_operation_e op;
49
50 void *buf;
51 pj_size_t size;
52 unsigned flags;
53 pj_sockaddr_t *rmt_addr;
54 int *rmt_addrlen;
55 pj_ssize_t bytes_read;
56 };
57
58 struct write_operation
59 {
60 PJ_DECL_LIST_MEMBER(struct write_operation);
61 pj_ioqueue_operation_e op;
62
63 char *buf;
64 pj_size_t size;
65 pj_ssize_t written;
66 unsigned flags;
67 pj_sockaddr rmt_addr;
68 int rmt_addrlen;
69 };
70
71 struct accept_operation
72 {
73 PJ_DECL_LIST_MEMBER(struct accept_operation);
74 pj_ioqueue_operation_e op;
75
76 pj_sock_t *accept_fd;
77 pj_sockaddr_t *local_addr;
78 pj_sockaddr_t *rmt_addr;
79 int *addrlen;
80 };
81
82 union operation_key
83 {
84 struct generic_operation generic_op;
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 #if PJ_IOQUEUE_HAS_SAFE_UNREG
93 # define UNREG_FIELDS \
94 unsigned ref_count; \
95 pj_time_val free_time; \
96
97 #else
98 # define UNREG_FIELDS
99 #endif
100
101 #define DECLARE_COMMON_KEY \
102 PJ_DECL_LIST_MEMBER(struct pj_ioqueue_key_t); \
103 pj_ioqueue_t *ioqueue; \
104 pj_grp_lock_t *grp_lock; \
105 pj_lock_t *lock; \
106 pj_bool_t closing; \
107 pj_thread_t *read_callback_thread; \
108 pj_thread_t *write_callback_thread; \
109 pj_bool_t destroy_requested; \
110 pj_bool_t allow_concurrent; \
111 pj_sock_t fd; \
112 int fd_type; \
113 void *user_data; \
114 pj_ioqueue_callback cb; \
115 int connecting; \
116 struct read_operation read_list; \
117 struct write_operation write_list; \
118 struct accept_operation accept_list; \
119 struct read_operation read_cb_list; \
120 struct write_operation write_cb_list; \
121 UNREG_FIELDS
122
123
124 #define DECLARE_COMMON_IOQUEUE \
125 pj_lock_t *lock; \
126 pj_bool_t auto_delete_lock; \
127 pj_ioqueue_cfg cfg;
128
129
130 enum ioqueue_event_type
131 {
132 NO_EVENT,
133 READABLE_EVENT = 1,
134 WRITEABLE_EVENT = 2,
135 EXCEPTION_EVENT = 4,
136 };
137
138 static void ioqueue_add_to_set( pj_ioqueue_t *ioqueue,
139 pj_ioqueue_key_t *key,
140 enum ioqueue_event_type event_type );
141 static void ioqueue_add_to_set2(pj_ioqueue_t *ioqueue,
142 pj_ioqueue_key_t *key,
143 unsigned event_types );
144 static void ioqueue_remove_from_set( pj_ioqueue_t *ioqueue,
145 pj_ioqueue_key_t *key,
146 enum ioqueue_event_type event_type);
147 static void ioqueue_remove_from_set2(pj_ioqueue_t *ioqueue,
148 pj_ioqueue_key_t *key,
149 unsigned event_types);
150