blob: 3bdbb52486d0778f005274de83e99c91834e3342 [file] [log] [blame]
Tristan Matthews0a329cc2013-07-17 13:20:14 -04001/* $Id */
2/*
3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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
39struct generic_operation
40{
41 PJ_DECL_LIST_MEMBER(struct generic_operation);
42 pj_ioqueue_operation_e op;
43};
44
45struct 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};
56
57struct write_operation
58{
59 PJ_DECL_LIST_MEMBER(struct write_operation);
60 pj_ioqueue_operation_e op;
61
62 char *buf;
63 pj_size_t size;
64 pj_ssize_t written;
65 unsigned flags;
66 pj_sockaddr_in rmt_addr;
67 int rmt_addrlen;
68};
69
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
81union operation_key
82{
83 struct generic_operation generic;
84 struct read_operation read;
85 struct write_operation write;
86#if PJ_HAS_TCP
87 struct accept_operation accept;
88#endif
89};
90
91#if PJ_IOQUEUE_HAS_SAFE_UNREG
92# define UNREG_FIELDS \
93 unsigned ref_count; \
94 pj_bool_t closing; \
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 inside_callback; \
107 pj_bool_t destroy_requested; \
108 pj_bool_t allow_concurrent; \
109 pj_sock_t fd; \
110 int fd_type; \
111 void *user_data; \
112 pj_ioqueue_callback cb; \
113 int connecting; \
114 struct read_operation read_list; \
115 struct write_operation write_list; \
116 struct accept_operation accept_list; \
117 UNREG_FIELDS
118
119
120#define DECLARE_COMMON_IOQUEUE \
121 pj_lock_t *lock; \
122 pj_bool_t auto_delete_lock; \
123 pj_bool_t default_concurrency;
124
125
126enum ioqueue_event_type
127{
128 NO_EVENT,
129 READABLE_EVENT,
130 WRITEABLE_EVENT,
131 EXCEPTION_EVENT,
132};
133
134static void ioqueue_add_to_set( pj_ioqueue_t *ioqueue,
135 pj_ioqueue_key_t *key,
136 enum ioqueue_event_type event_type );
137static void ioqueue_remove_from_set( pj_ioqueue_t *ioqueue,
138 pj_ioqueue_key_t *key,
139 enum ioqueue_event_type event_type);
140