1
/* $Id: ioqueue_linux_kernel.c 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#include <pj/ioqueue.h>
25
#include <pj/string.h>
26
#include <pj/assert.h>
29
#define THIS_FILE "ioqueue"
31
#define PJ_IOQUEUE_IS_READ_OP(op) \
32
((op & PJ_IOQUEUE_OP_READ) || (op & PJ_IOQUEUE_OP_RECV_FROM))
33
#define PJ_IOQUEUE_IS_WRITE_OP(op) \
34
((op & PJ_IOQUEUE_OP_WRITE) || (op & PJ_IOQUEUE_OP_SEND_TO))
38
# define PJ_IOQUEUE_IS_ACCEPT_OP(op) (op & PJ_IOQUEUE_OP_ACCEPT)
39
# define PJ_IOQUEUE_IS_CONNECT_OP(op) (op & PJ_IOQUEUE_OP_CONNECT)
41
# define PJ_IOQUEUE_IS_ACCEPT_OP(op) 0
42
# define PJ_IOQUEUE_IS_CONNECT_OP(op) 0
45
#if defined(PJ_DEBUG) && PJ_DEBUG != 0
46
# define VALIDATE_FD_SET 1
48
# define VALIDATE_FD_SET 0
51
struct pj_ioqueue_key_t
53
PJ_DECL_LIST_MEMBER(struct pj_ioqueue_key_t)
55
pj_ioqueue_operation_e op;
57
pj_ioqueue_callback cb;
64
PJ_DEF(pj_ioqueue_t*) pj_ioqueue_create(pj_pool_t *pool, pj_size_t max_fd)
69
PJ_DEF(pj_status_t) pj_ioqueue_destroy(pj_ioqueue_t *ioque)
74
PJ_DEF(pj_ioqueue_key_t*) pj_ioqueue_register( pj_pool_t *pool,
78
const pj_ioqueue_callback *cb)
83
PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_t *ioque,
84
pj_ioqueue_key_t *key)
89
PJ_DEF(void*) pj_ioqueue_get_user_data( pj_ioqueue_key_t *key )
95
PJ_DEF(int) pj_ioqueue_poll( pj_ioqueue_t *ioque, const pj_time_val *timeout)
100
PJ_DEF(int) pj_ioqueue_read( pj_ioqueue_t *ioque,
101
pj_ioqueue_key_t *key,
108
PJ_DEF(int) pj_ioqueue_recvfrom( pj_ioqueue_t *ioque,
109
pj_ioqueue_key_t *key,
118
PJ_DEF(int) pj_ioqueue_write( pj_ioqueue_t *ioque,
119
pj_ioqueue_key_t *key,
126
PJ_DEF(int) pj_ioqueue_sendto( pj_ioqueue_t *ioque,
127
pj_ioqueue_key_t *key,
130
const pj_sockaddr_t *addr,
138
* Initiate overlapped accept() operation.
140
PJ_DEF(int) pj_ioqueue_accept( pj_ioqueue_t *ioqueue,
141
pj_ioqueue_key_t *key,
143
pj_sockaddr_t *local,
144
pj_sockaddr_t *remote,
151
* Initiate overlapped connect() operation (well, it's non-blocking actually,
152
* since there's no overlapped version of connect()).
154
PJ_DEF(pj_status_t) pj_ioqueue_connect( pj_ioqueue_t *ioqueue,
155
pj_ioqueue_key_t *key,
156
const pj_sockaddr_t *addr,
161
#endif /* PJ_HAS_TCP */