00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __PJ_IOQUEUE_H__
00022 #define __PJ_IOQUEUE_H__
00023
00029 #include <pj/types.h>
00030
00031 PJ_BEGIN_DECL
00032
00209 typedef struct pj_ioqueue_op_key_t
00210 {
00211 void *internal__[32];
00212 void *activesock_data;
00213 void *user_data;
00214 } pj_ioqueue_op_key_t;
00215
00220 typedef struct pj_ioqueue_callback
00221 {
00233 void (*on_read_complete)(pj_ioqueue_key_t *key,
00234 pj_ioqueue_op_key_t *op_key,
00235 pj_ssize_t bytes_read);
00236
00248 void (*on_write_complete)(pj_ioqueue_key_t *key,
00249 pj_ioqueue_op_key_t *op_key,
00250 pj_ssize_t bytes_sent);
00251
00260 void (*on_accept_complete)(pj_ioqueue_key_t *key,
00261 pj_ioqueue_op_key_t *op_key,
00262 pj_sock_t sock,
00263 pj_status_t status);
00264
00271 void (*on_connect_complete)(pj_ioqueue_key_t *key,
00272 pj_status_t status);
00273 } pj_ioqueue_callback;
00274
00275
00280 typedef enum pj_ioqueue_operation_e
00281 {
00282 PJ_IOQUEUE_OP_NONE = 0,
00283 PJ_IOQUEUE_OP_READ = 1,
00284 PJ_IOQUEUE_OP_RECV = 2,
00285 PJ_IOQUEUE_OP_RECV_FROM = 4,
00286 PJ_IOQUEUE_OP_WRITE = 8,
00287 PJ_IOQUEUE_OP_SEND = 16,
00288 PJ_IOQUEUE_OP_SEND_TO = 32,
00289 #if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
00290 PJ_IOQUEUE_OP_ACCEPT = 64,
00291 PJ_IOQUEUE_OP_CONNECT = 128
00292 #endif
00293 } pj_ioqueue_operation_e;
00294
00295
00302 #ifndef PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL
00303 # define PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL (16)
00304 #endif
00305
00310 #define PJ_IOQUEUE_ALWAYS_ASYNC ((pj_uint32_t)1 << (pj_uint32_t)31)
00311
00317 PJ_DECL(const char*) pj_ioqueue_name(void);
00318
00319
00330 PJ_DECL(pj_status_t) pj_ioqueue_create( pj_pool_t *pool,
00331 pj_size_t max_fd,
00332 pj_ioqueue_t **ioqueue);
00333
00341 PJ_DECL(pj_status_t) pj_ioqueue_destroy( pj_ioqueue_t *ioque );
00342
00358 PJ_DECL(pj_status_t) pj_ioqueue_set_lock( pj_ioqueue_t *ioque,
00359 pj_lock_t *lock,
00360 pj_bool_t auto_delete );
00361
00377 PJ_DECL(pj_status_t) pj_ioqueue_set_default_concurrency(pj_ioqueue_t *ioqueue,
00378 pj_bool_t allow);
00379
00400 PJ_DECL(pj_status_t) pj_ioqueue_register_sock( pj_pool_t *pool,
00401 pj_ioqueue_t *ioque,
00402 pj_sock_t sock,
00403 void *user_data,
00404 const pj_ioqueue_callback *cb,
00405 pj_ioqueue_key_t **key );
00406
00428 PJ_DECL(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key );
00429
00430
00440 PJ_DECL(void*) pj_ioqueue_get_user_data( pj_ioqueue_key_t *key );
00441
00452 PJ_DECL(pj_status_t) pj_ioqueue_set_user_data( pj_ioqueue_key_t *key,
00453 void *user_data,
00454 void **old_data);
00455
00478 PJ_DECL(pj_status_t) pj_ioqueue_set_concurrency(pj_ioqueue_key_t *key,
00479 pj_bool_t allow);
00480
00491 PJ_DECL(pj_status_t) pj_ioqueue_lock_key(pj_ioqueue_key_t *key);
00492
00500 PJ_DECL(pj_status_t) pj_ioqueue_unlock_key(pj_ioqueue_key_t *key);
00501
00508 PJ_DECL(void) pj_ioqueue_op_key_init( pj_ioqueue_op_key_t *op_key,
00509 pj_size_t size );
00510
00523 PJ_DECL(pj_bool_t) pj_ioqueue_is_pending( pj_ioqueue_key_t *key,
00524 pj_ioqueue_op_key_t *op_key );
00525
00526
00541 PJ_DECL(pj_status_t) pj_ioqueue_post_completion( pj_ioqueue_key_t *key,
00542 pj_ioqueue_op_key_t *op_key,
00543 pj_ssize_t bytes_status );
00544
00545
00546
00547 #if defined(PJ_HAS_TCP) && PJ_HAS_TCP != 0
00548
00580 PJ_DECL(pj_status_t) pj_ioqueue_accept( pj_ioqueue_key_t *key,
00581 pj_ioqueue_op_key_t *op_key,
00582 pj_sock_t *new_sock,
00583 pj_sockaddr_t *local,
00584 pj_sockaddr_t *remote,
00585 int *addrlen );
00586
00604 PJ_DECL(pj_status_t) pj_ioqueue_connect( pj_ioqueue_key_t *key,
00605 const pj_sockaddr_t *addr,
00606 int addrlen );
00607
00608 #endif
00609
00625 PJ_DECL(int) pj_ioqueue_poll( pj_ioqueue_t *ioque,
00626 const pj_time_val *timeout);
00627
00628
00664 PJ_DECL(pj_status_t) pj_ioqueue_recv( pj_ioqueue_key_t *key,
00665 pj_ioqueue_op_key_t *op_key,
00666 void *buffer,
00667 pj_ssize_t *length,
00668 pj_uint32_t flags );
00669
00707 PJ_DECL(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_key_t *key,
00708 pj_ioqueue_op_key_t *op_key,
00709 void *buffer,
00710 pj_ssize_t *length,
00711 pj_uint32_t flags,
00712 pj_sockaddr_t *addr,
00713 int *addrlen);
00714
00749 PJ_DECL(pj_status_t) pj_ioqueue_send( pj_ioqueue_key_t *key,
00750 pj_ioqueue_op_key_t *op_key,
00751 const void *data,
00752 pj_ssize_t *length,
00753 pj_uint32_t flags );
00754
00755
00789 PJ_DECL(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_key_t *key,
00790 pj_ioqueue_op_key_t *op_key,
00791 const void *data,
00792 pj_ssize_t *length,
00793 pj_uint32_t flags,
00794 const pj_sockaddr_t *addr,
00795 int addrlen);
00796
00797
00802 PJ_END_DECL
00803
00804 #endif
00805