blob: e7d05561aa718ec14ac622aeb47846871025b8c4 [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
Benny Prijono9033e312005-11-21 02:08:39 +000069struct accept_operation
70{
71 PJ_DECL_LIST_MEMBER(struct accept_operation);
72 pj_ioqueue_operation_e op;
73
74 pj_sock_t *accept_fd;
75 pj_sockaddr_t *local_addr;
76 pj_sockaddr_t *rmt_addr;
77 int *addrlen;
78};
Benny Prijono9033e312005-11-21 02:08:39 +000079
80union operation_key
81{
82 struct generic_operation generic;
83 struct read_operation read;
84 struct write_operation write;
85#if PJ_HAS_TCP
86 struct accept_operation accept;
87#endif
88};
89
Benny Prijono5accbd02006-03-30 16:32:18 +000090#if PJ_IOQUEUE_HAS_SAFE_UNREG
91# define UNREG_FIELDS \
92 unsigned ref_count; \
93 pj_bool_t closing; \
94 pj_time_val free_time; \
95
96#else
97# define UNREG_FIELDS
98#endif
99
Benny Prijono9033e312005-11-21 02:08:39 +0000100#define DECLARE_COMMON_KEY \
101 PJ_DECL_LIST_MEMBER(struct pj_ioqueue_key_t); \
102 pj_ioqueue_t *ioqueue; \
103 pj_mutex_t *mutex; \
Benny Prijonoac52df42006-03-25 10:06:00 +0000104 pj_bool_t inside_callback; \
105 pj_bool_t destroy_requested; \
Benny Prijono9033e312005-11-21 02:08:39 +0000106 pj_sock_t fd; \
107 int fd_type; \
108 void *user_data; \
109 pj_ioqueue_callback cb; \
110 int connecting; \
111 struct read_operation read_list; \
112 struct write_operation write_list; \
Benny Prijono5accbd02006-03-30 16:32:18 +0000113 struct accept_operation accept_list; \
114 UNREG_FIELDS
Benny Prijono9033e312005-11-21 02:08:39 +0000115
116
117#define DECLARE_COMMON_IOQUEUE \
118 pj_lock_t *lock; \
119 pj_bool_t auto_delete_lock;
120
121
122enum ioqueue_event_type
123{
124 NO_EVENT,
125 READABLE_EVENT,
126 WRITEABLE_EVENT,
127 EXCEPTION_EVENT,
128};
129
130static void ioqueue_add_to_set( pj_ioqueue_t *ioqueue,
131 pj_sock_t fd,
132 enum ioqueue_event_type event_type );
133static void ioqueue_remove_from_set( pj_ioqueue_t *ioqueue,
134 pj_sock_t fd,
135 enum ioqueue_event_type event_type);
136