本文整理汇总了C++中pj_ioqueue_create函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_ioqueue_create函数的具体用法?C++ pj_ioqueue_create怎么用?C++ pj_ioqueue_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_ioqueue_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: create_stun_config
pj_status_t create_stun_config(pj_pool_t *pool, pj_stun_config *stun_cfg)
{
pj_ioqueue_t *ioqueue;
pj_timer_heap_t *timer_heap;
pj_lock_t *lock;
pj_status_t status;
status = pj_ioqueue_create(pool, 64, &ioqueue);
if (status != PJ_SUCCESS) {
app_perror(" pj_ioqueue_create()", status);
return status;
}
status = pj_timer_heap_create(pool, 256, &timer_heap);
if (status != PJ_SUCCESS) {
app_perror(" pj_timer_heap_create()", status);
pj_ioqueue_destroy(ioqueue);
return status;
}
pj_lock_create_recursive_mutex(pool, NULL, &lock);
pj_timer_heap_set_lock(timer_heap, lock, PJ_TRUE);
pj_stun_config_init(stun_cfg, mem, 0, ioqueue, timer_heap);
return PJ_SUCCESS;
}
开发者ID:aemonfly,项目名称:android-client,代码行数:27,代码来源:test.c
示例2: udp_echo_srv_ioqueue
int udp_echo_srv_ioqueue(void)
{
pj_pool_t *pool;
pj_sock_t sock;
pj_ioqueue_t *ioqueue;
pj_ioqueue_callback callback;
int i;
pj_thread_t *thread[ECHO_SERVER_MAX_THREADS];
pj_status_t rc;
pj_bzero(&callback, sizeof(callback));
callback.on_read_complete = &on_read_complete;
callback.on_write_complete = &on_write_complete;
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return -10;
rc = pj_ioqueue_create(pool, 2, &ioqueue);
if (rc != PJ_SUCCESS) {
app_perror("...pj_ioqueue_create error", rc);
return -20;
}
rc = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0,
ECHO_SERVER_START_PORT, &sock);
if (rc != PJ_SUCCESS) {
app_perror("...app_socket error", rc);
return -30;
}
rc = pj_ioqueue_register_sock(pool, ioqueue, sock, NULL,
&callback, &key);
if (rc != PJ_SUCCESS) {
app_perror("...error registering socket", rc);
return -40;
}
rc = pj_atomic_create(pool, 0, &total_bytes);
if (rc != PJ_SUCCESS) {
app_perror("...error creating atomic variable", rc);
return -45;
}
for (i=0; i<ECHO_SERVER_MAX_THREADS; ++i) {
rc = pj_thread_create(pool, NULL, &worker_thread, ioqueue,
PJ_THREAD_DEFAULT_STACK_SIZE, 0,
&thread[i]);
if (rc != PJ_SUCCESS) {
app_perror("...create thread error", rc);
return -50;
}
}
echo_srv_common_loop(total_bytes);
return 0;
}
开发者ID:AbhaySingh,项目名称:pjproject,代码行数:58,代码来源:udp_echo_srv_ioqueue.c
示例3: stun_sock_test
int stun_sock_test(void)
{
struct pjlib_state pjlib_state;
pj_stun_config stun_cfg;
pj_ioqueue_t *ioqueue = NULL;
pj_timer_heap_t *timer_heap = NULL;
pj_pool_t *pool = NULL;
pj_status_t status;
int ret = 0;
pool = pj_pool_create(mem, NULL, 512, 512, NULL);
status = pj_ioqueue_create(pool, 12, &ioqueue);
if (status != PJ_SUCCESS) {
app_perror(" pj_ioqueue_create()", status);
ret = -4;
goto on_return;
}
status = pj_timer_heap_create(pool, 100, &timer_heap);
if (status != PJ_SUCCESS) {
app_perror(" pj_timer_heap_create()", status);
ret = -8;
goto on_return;
}
pj_stun_config_init(&stun_cfg, mem, 0, ioqueue, timer_heap);
DO_TEST(timeout_test(&stun_cfg, PJ_FALSE));
DO_TEST(timeout_test(&stun_cfg, PJ_TRUE));
DO_TEST(missing_attr_test(&stun_cfg, PJ_FALSE));
DO_TEST(missing_attr_test(&stun_cfg, PJ_TRUE));
DO_TEST(keep_alive_test(&stun_cfg));
on_return:
if (timer_heap) pj_timer_heap_destroy(timer_heap);
if (ioqueue) pj_ioqueue_destroy(ioqueue);
if (pool) pj_pool_release(pool);
return ret;
}
开发者ID:AmoebaLabs,项目名称:pjsip,代码行数:42,代码来源:stun_sock_test.c
示例4: getURL
pj_status_t getURL(const char *curl)
{
pj_str_t url;
pj_http_req_callback hcb;
pj_status_t status;
pj_bzero(&hcb, sizeof(hcb));
hcb.on_complete = &on_complete;
hcb.on_data_read = &on_data_read;
hcb.on_send_data = &on_send_data;
hcb.on_response = &on_response;
/* Create pool, timer, and ioqueue */
pool = pj_pool_create(mem, NULL, 8192, 4096, NULL);
if (pj_timer_heap_create(pool, 16, &timer_heap))
return -31;
if (pj_ioqueue_create(pool, 16, &ioqueue))
return -32;
pj_strdup2(pool, &url, curl);
if ((status = pj_http_req_create(pool, &url, timer_heap, ioqueue,
NULL, &hcb, &http_req)) != PJ_SUCCESS)
return status;
if ((status = pj_http_req_start(http_req)) != PJ_SUCCESS)
return status;
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
pj_http_req_destroy(http_req);
pj_ioqueue_destroy(ioqueue);
pj_timer_heap_destroy(timer_heap);
pj_pool_release(pool);
return PJ_SUCCESS;
}
开发者ID:avble,项目名称:natClientEx,代码行数:41,代码来源:httpdemo.c
示例5: create
//
// Create proactor.
//
pj_status_t create( Pj_Pool *pool, pj_size_t max_fd,
pj_size_t timer_entry_count)
{
pj_status_t status;
destroy();
status = pj_ioqueue_create(pool->pool_(), max_fd, &ioq_);
if (status != PJ_SUCCESS)
return status;
status = pj_timer_heap_create(pool->pool_(),
timer_entry_count, &th_);
if (status != PJ_SUCCESS) {
pj_ioqueue_destroy(ioq_);
ioq_ = NULL;
return NULL;
}
return status;
}
开发者ID:BenBarahona,项目名称:Interdig,代码行数:24,代码来源:proactor.hpp
示例6: many_handles_test
/*
* Testing with many handles.
* This will just test registering PJ_IOQUEUE_MAX_HANDLES count
* of sockets to the ioqueue.
*/
static int many_handles_test(pj_bool_t allow_concur)
{
enum { MAX = PJ_IOQUEUE_MAX_HANDLES };
pj_pool_t *pool;
pj_ioqueue_t *ioqueue;
pj_sock_t *sock;
pj_ioqueue_key_t **key;
pj_status_t rc;
int count, i; /* must be signed */
PJ_LOG(3,(THIS_FILE,"...testing with so many handles"));
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return PJ_ENOMEM;
key = (pj_ioqueue_key_t**)
pj_pool_alloc(pool, MAX*sizeof(pj_ioqueue_key_t*));
sock = (pj_sock_t*) pj_pool_alloc(pool, MAX*sizeof(pj_sock_t));
/* Create IOQueue */
rc = pj_ioqueue_create(pool, MAX, &ioqueue);
if (rc != PJ_SUCCESS || ioqueue == NULL) {
app_perror("...error in pj_ioqueue_create", rc);
return -10;
}
// Set concurrency
rc = pj_ioqueue_set_default_concurrency(ioqueue, allow_concur);
if (rc != PJ_SUCCESS) {
return -11;
}
/* Register as many sockets. */
for (count=0; count<MAX; ++count) {
sock[count] = PJ_INVALID_SOCKET;
rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sock[count]);
if (rc != PJ_SUCCESS || sock[count] == PJ_INVALID_SOCKET) {
PJ_LOG(3,(THIS_FILE, "....unable to create %d-th socket, rc=%d",
count, rc));
break;
}
key[count] = NULL;
rc = pj_ioqueue_register_sock(pool, ioqueue, sock[count],
NULL, &test_cb, &key[count]);
if (rc != PJ_SUCCESS || key[count] == NULL) {
PJ_LOG(3,(THIS_FILE, "....unable to register %d-th socket, rc=%d",
count, rc));
return -30;
}
}
/* Test complete. */
/* Now deregister and close all handles. */
/* NOTE for RTEMS:
* It seems that the order of close(sock) is pretty important here.
* If we close the sockets with the same order as when they were created,
* RTEMS doesn't seem to reuse the sockets, thus next socket created
* will have descriptor higher than the last socket created.
* If we close the sockets in the reverse order, then the descriptor will
* get reused.
* This used to cause problem with select ioqueue, since the ioqueue
* always gives FD_SETSIZE for the first select() argument. This ioqueue
* behavior can be changed with setting PJ_SELECT_NEEDS_NFDS macro.
*/
for (i=count-1; i>=0; --i) {
///for (i=0; i<count; ++i) {
rc = pj_ioqueue_unregister(key[i]);
if (rc != PJ_SUCCESS) {
app_perror("...error in pj_ioqueue_unregister", rc);
}
}
rc = pj_ioqueue_destroy(ioqueue);
if (rc != PJ_SUCCESS) {
app_perror("...error in pj_ioqueue_destroy", rc);
}
pj_pool_release(pool);
PJ_LOG(3,(THIS_FILE,"....many_handles_test() ok"));
return 0;
}
开发者ID:AbhaySingh,项目名称:pjproject,代码行数:91,代码来源:ioq_udp.c
示例7: unregister_test
/*
* unregister_test()
* Check if callback is still called after socket has been unregistered or
* closed.
*/
static int unregister_test(pj_bool_t allow_concur)
{
enum { RPORT = 50000, SPORT = 50001 };
pj_pool_t *pool;
pj_ioqueue_t *ioqueue;
pj_sock_t ssock;
pj_sock_t rsock;
int addrlen;
pj_sockaddr_in addr;
pj_ioqueue_key_t *key;
pj_ioqueue_op_key_t opkey;
pj_ioqueue_callback cb;
unsigned packet_cnt;
char sendbuf[10], recvbuf[10];
pj_ssize_t bytes;
pj_time_val timeout;
pj_status_t status;
pool = pj_pool_create(mem, "test", 4000, 4000, NULL);
if (!pool) {
app_perror("Unable to create pool", PJ_ENOMEM);
return -100;
}
status = pj_ioqueue_create(pool, 16, &ioqueue);
if (status != PJ_SUCCESS) {
app_perror("Error creating ioqueue", status);
return -110;
}
// Set concurrency
TRACE_("set concurrency...");
status = pj_ioqueue_set_default_concurrency(ioqueue, allow_concur);
if (status != PJ_SUCCESS) {
return -112;
}
/* Create sender socket */
status = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, SPORT, &ssock);
if (status != PJ_SUCCESS) {
app_perror("Error initializing socket", status);
return -120;
}
/* Create receiver socket. */
status = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, RPORT, &rsock);
if (status != PJ_SUCCESS) {
app_perror("Error initializing socket", status);
return -130;
}
/* Register rsock to ioqueue. */
pj_bzero(&cb, sizeof(cb));
cb.on_read_complete = &on_read_complete;
packet_cnt = 0;
status = pj_ioqueue_register_sock(pool, ioqueue, rsock, &packet_cnt,
&cb, &key);
if (status != PJ_SUCCESS) {
app_perror("Error registering to ioqueue", status);
return -140;
}
/* Init operation key. */
pj_ioqueue_op_key_init(&opkey, sizeof(opkey));
/* Start reading. */
bytes = sizeof(recvbuf);
status = pj_ioqueue_recv( key, &opkey, recvbuf, &bytes, 0);
if (status != PJ_EPENDING) {
app_perror("Expecting PJ_EPENDING, but got this", status);
return -150;
}
/* Init destination address. */
addrlen = sizeof(addr);
status = pj_sock_getsockname(rsock, &addr, &addrlen);
if (status != PJ_SUCCESS) {
app_perror("getsockname error", status);
return -160;
}
/* Override address with 127.0.0.1, since getsockname will return
* zero in the address field.
*/
addr.sin_addr = pj_inet_addr2("127.0.0.1");
/* Init buffer to send */
pj_ansi_strcpy(sendbuf, "Hello0123");
/* Send one packet. */
bytes = sizeof(sendbuf);
status = pj_sock_sendto(ssock, sendbuf, &bytes, 0,
&addr, sizeof(addr));
if (status != PJ_SUCCESS) {
//.........这里部分代码省略.........
开发者ID:AbhaySingh,项目名称:pjproject,代码行数:101,代码来源:ioq_udp.c
示例8: compliance_test
/*
* compliance_test()
* To test that the basic IOQueue functionality works. It will just exchange
* data between two sockets.
*/
static int compliance_test(pj_bool_t allow_concur)
{
pj_sock_t ssock=-1, csock=-1;
pj_sockaddr_in addr, dst_addr;
int addrlen;
pj_pool_t *pool = NULL;
char *send_buf, *recv_buf;
pj_ioqueue_t *ioque = NULL;
pj_ioqueue_key_t *skey = NULL, *ckey = NULL;
pj_ioqueue_op_key_t read_op, write_op;
int bufsize = BUF_MIN_SIZE;
pj_ssize_t bytes;
int status = -1;
pj_str_t temp;
pj_bool_t send_pending, recv_pending;
pj_status_t rc;
pj_set_os_error(PJ_SUCCESS);
// Create pool.
pool = pj_pool_create(mem, NULL, POOL_SIZE, 4000, NULL);
// Allocate buffers for send and receive.
send_buf = (char*)pj_pool_alloc(pool, bufsize);
recv_buf = (char*)pj_pool_alloc(pool, bufsize);
// Allocate sockets for sending and receiving.
TRACE_("creating sockets...");
rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &ssock);
if (rc==PJ_SUCCESS)
rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &csock);
else
csock = PJ_INVALID_SOCKET;
if (rc != PJ_SUCCESS) {
app_perror("...ERROR in pj_sock_socket()", rc);
status=-1; goto on_error;
}
// Bind server socket.
TRACE_("bind socket...");
pj_bzero(&addr, sizeof(addr));
addr.sin_family = pj_AF_INET();
addr.sin_port = pj_htons(PORT);
if (pj_sock_bind(ssock, &addr, sizeof(addr))) {
status=-10; goto on_error;
}
// Create I/O Queue.
TRACE_("create ioqueue...");
rc = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, &ioque);
if (rc != PJ_SUCCESS) {
status=-20; goto on_error;
}
// Set concurrency
TRACE_("set concurrency...");
rc = pj_ioqueue_set_default_concurrency(ioque, allow_concur);
if (rc != PJ_SUCCESS) {
status=-21; goto on_error;
}
// Register server and client socket.
// We put this after inactivity socket, hopefully this can represent the
// worst waiting time.
TRACE_("registering first sockets...");
rc = pj_ioqueue_register_sock(pool, ioque, ssock, NULL,
&test_cb, &skey);
if (rc != PJ_SUCCESS) {
app_perror("...error(10): ioqueue_register error", rc);
status=-25; goto on_error;
}
TRACE_("registering second sockets...");
rc = pj_ioqueue_register_sock( pool, ioque, csock, NULL,
&test_cb, &ckey);
if (rc != PJ_SUCCESS) {
app_perror("...error(11): ioqueue_register error", rc);
status=-26; goto on_error;
}
// Randomize send_buf.
pj_create_random_string(send_buf, bufsize);
// Register reading from ioqueue.
TRACE_("start recvfrom...");
pj_bzero(&addr, sizeof(addr));
addrlen = sizeof(addr);
bytes = bufsize;
rc = pj_ioqueue_recvfrom(skey, &read_op, recv_buf, &bytes, 0,
&addr, &addrlen);
if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
app_perror("...error: pj_ioqueue_recvfrom", rc);
status=-28; goto on_error;
} else if (rc == PJ_EPENDING) {
recv_pending = 1;
PJ_LOG(3, (THIS_FILE,
//.........这里部分代码省略.........
开发者ID:AbhaySingh,项目名称:pjproject,代码行数:101,代码来源:ioq_udp.c
示例9: stun_destroy_test
static int stun_destroy_test(void)
{
enum { LOOP = 500 };
struct stun_test_session test_sess;
pj_sockaddr bind_addr;
int addr_len;
pj_caching_pool cp;
pj_pool_t *pool;
unsigned i;
pj_status_t status;
int rc = 0;
PJ_LOG(3,(THIS_FILE, " STUN destroy concurrency test"));
pj_bzero(&test_sess, sizeof(test_sess));
pj_caching_pool_init(&cp, NULL, 0);
pool = pj_pool_create(&cp.factory, "testsess", 512, 512, NULL);
pj_stun_config_init(&test_sess.stun_cfg, &cp.factory, 0, NULL, NULL);
status = pj_timer_heap_create(pool, 1023, &test_sess.stun_cfg.timer_heap);
pj_assert(status == PJ_SUCCESS);
status = pj_lock_create_recursive_mutex(pool, NULL, &test_sess.lock);
pj_assert(status == PJ_SUCCESS);
pj_timer_heap_set_lock(test_sess.stun_cfg.timer_heap, test_sess.lock, PJ_TRUE);
pj_assert(status == PJ_SUCCESS);
status = pj_ioqueue_create(pool, 512, &test_sess.stun_cfg.ioqueue);
pj_assert(status == PJ_SUCCESS);
pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &test_sess.server_sock);
pj_sockaddr_init(pj_AF_INET(), &bind_addr, NULL, 0);
status = pj_sock_bind(test_sess.server_sock, &bind_addr, pj_sockaddr_get_len(&bind_addr));
pj_assert(status == PJ_SUCCESS);
addr_len = sizeof(bind_addr);
status = pj_sock_getsockname(test_sess.server_sock, &bind_addr, &addr_len);
pj_assert(status == PJ_SUCCESS);
test_sess.server_port = pj_sockaddr_get_port(&bind_addr);
status = pj_event_create(pool, NULL, PJ_TRUE, PJ_FALSE, &test_sess.server_event);
pj_assert(status == PJ_SUCCESS);
for (i=0; i<SERVER_THREAD_CNT; ++i) {
status = pj_thread_create(pool, NULL,
&server_thread_proc, &test_sess,
0, 0, &test_sess.server_threads[i]);
pj_assert(status == PJ_SUCCESS);
}
for (i=0; i<WORKER_THREAD_CNT; ++i) {
status = pj_thread_create(pool, NULL,
&worker_thread_proc, &test_sess,
0, 0, &test_sess.worker_threads[i]);
pj_assert(status == PJ_SUCCESS);
}
/* Test 1: Main thread calls destroy while callback is processing response */
PJ_LOG(3,(THIS_FILE, " Destroy in main thread while callback is running"));
for (i=0; i<LOOP; ++i) {
int sleep = pj_rand() % 5;
PJ_LOG(3,(THIS_FILE, " Try %-3d of %d", i+1, LOOP));
/* Test 1: destroy at the same time when receiving response */
pj_bzero(&test_sess.param, sizeof(test_sess.param));
test_sess.param.client_sleep_after_start = 20;
test_sess.param.client_sleep_before_destroy = sleep;
test_sess.param.server_wait_for_event = PJ_TRUE;
stun_destroy_test_session(&test_sess);
PJ_LOG(3,(THIS_FILE,
" stun test a: sleep delay:%d: clients with response: %d",
sleep, test_sess.param.client_got_response));
/* Test 2: destroy at the same time with STUN retransmit timer */
test_sess.param.server_drop_request = PJ_TRUE;
test_sess.param.client_sleep_after_start = 0;
test_sess.param.client_sleep_before_destroy = PJ_STUN_RTO_VALUE;
test_sess.param.server_wait_for_event = PJ_FALSE;
stun_destroy_test_session(&test_sess);
PJ_LOG(3,(THIS_FILE, " stun test b: retransmit concurrency"));
/* Test 3: destroy at the same time with receiving response
* AND STUN retransmit timer */
test_sess.param.client_got_response = 0;
test_sess.param.server_drop_request = PJ_FALSE;
test_sess.param.client_sleep_after_start = PJ_STUN_RTO_VALUE;
test_sess.param.client_sleep_before_destroy = 0;
test_sess.param.server_wait_for_event = PJ_TRUE;
stun_destroy_test_session(&test_sess);
PJ_LOG(3,(THIS_FILE,
" stun test c: clients with response: %d",
test_sess.param.client_got_response));
pj_thread_sleep(10);
//.........这里部分代码省略.........
开发者ID:AmoebaLabs,项目名称:pjsip,代码行数:101,代码来源:concur_test.c
示例10: http_client_test_delete
int http_client_test_delete()
{
pj_str_t url;
pj_http_req_callback hcb;
pj_http_req_param param;
char urlbuf[80];
pj_bzero(&hcb, sizeof(hcb));
hcb.on_complete = &on_complete;
hcb.on_response = &on_response;
/* Create pool, timer, and ioqueue */
pool = pj_pool_create(mem, NULL, 8192, 4096, NULL);
if (pj_timer_heap_create(pool, 16, &timer_heap))
return -61;
if (pj_ioqueue_create(pool, 16, &ioqueue))
return -62;
#ifdef USE_LOCAL_SERVER
thread_quit = PJ_FALSE;
g_server.action = ACTION_REPLY;
g_server.send_content_length = PJ_TRUE;
g_server.data_size = 0;
g_server.buf_size = 1024;
sstatus = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0,
&g_server.sock);
if (sstatus != PJ_SUCCESS)
return -41;
pj_sockaddr_in_init(&addr, NULL, 0);
sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr));
if (sstatus != PJ_SUCCESS)
return -43;
{
pj_sockaddr_in addr;
int addr_len = sizeof(addr);
sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d/test/test2.txt",
g_server.port);
url = pj_str(urlbuf);
}
sstatus = pj_sock_listen(g_server.sock, 8);
if (sstatus != PJ_SUCCESS)
return -45;
sstatus = pj_thread_create(pool, NULL, &server_thread, &g_server,
0, 0, &g_server.thread);
if (sstatus != PJ_SUCCESS)
return -47;
#else
pj_cstr(&url, "http://127.0.0.1:280/test/test2.txt");
#endif
pj_http_req_param_default(¶m);
pj_strset2(¶m.method, (char*)"DELETE");
if (pj_http_req_create(pool, &url, timer_heap, ioqueue,
¶m, &hcb, &http_req))
return -63;
if (pj_http_req_start(http_req))
return -65;
while (pj_http_req_is_running(http_req)) {
pj_time_val delay = {0, 50};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer_heap, NULL);
}
#ifdef USE_LOCAL_SERVER
thread_quit = PJ_TRUE;
pj_thread_join(g_server.thread);
pj_sock_close(g_server.sock);
#endif
pj_http_req_destroy(http_req);
pj_ioqueue_destroy(ioqueue);
pj_timer_heap_destroy(timer_heap);
pj_pool_release(pool);
return PJ_SUCCESS;
}
开发者ID:Archipov,项目名称:android-client,代码行数:90,代码来源:http_client.c
示例11: http_client_test2
/*
* GET request scenario 2: using on_complete() to get the
* complete data. Server does not reply with content-length.
* Request timed out, application sets a longer timeout, then
* then restart the request.
*/
int http_client_test2()
{
pj_str_t url;
pj_http_req_callback hcb;
pj_http_req_param param;
pj_time_val timeout;
char urlbuf[80];
pj_bzero(&hcb, sizeof(hcb));
hcb.on_complete = &on_complete;
hcb.on_response = &on_response;
pj_http_req_param_default(¶m);
/* Create pool, timer, and ioqueue */
pool = pj_pool_create(mem, NULL, 8192, 4096, NULL);
if (pj_timer_heap_create(pool, 16, &timer_heap))
return -41;
if (pj_ioqueue_create(pool, 16, &ioqueue))
return -42;
#ifdef USE_LOCAL_SERVER
pj_cstr(&url, "http://127.0.0.1:380");
param.timeout.sec = 0;
param.timeout.msec = 2000;
thread_quit = PJ_FALSE;
g_server.action = ACTION_IGNORE;
g_server.send_content_length = PJ_FALSE;
g_server.data_size = 4173;
g_server.buf_size = 1024;
sstatus = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0,
&g_server.sock);
if (sstatus != PJ_SUCCESS)
return -41;
pj_sockaddr_in_init(&addr, NULL, 0);
sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr));
if (sstatus != PJ_SUCCESS)
return -43;
{
pj_sockaddr_in addr;
int addr_len = sizeof(addr);
sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len);
if (sstatus != PJ_SUCCESS)
return -44;
g_server.port = pj_sockaddr_in_get_port(&addr);
pj_ansi_snprintf(urlbuf, sizeof(urlbuf),
"http://127.0.0.1:%d",
g_server.port);
url = pj_str(urlbuf);
}
sstatus = pj_sock_listen(g_server.sock, 8);
if (sstatus != PJ_SUCCESS)
return -45;
sstatus = pj_thread_create(pool, NULL, &server_thread, &g_server,
0, 0, &g_server.thread);
if (sstatus != PJ_SUCCESS)
return -47;
#else
pj_cstr(&url, "http://www.google.com.sg");
param.timeout.sec = 0;
param.timeout.msec = 50;
#endif
pj_http_headers_add_elmt2(¶m.headers, (char*)"Accept",
(char*)"image/gif, image/x-xbitmap, image/jpeg, "
"image/pjpeg, application/x-ms-application,"
" application/vnd.ms-xpsdocument, "
"application/xaml+xml, "
"application/x-ms-xbap, "
"application/x-shockwave-flash, "
"application/vnd.ms-excel, "
"application/vnd.ms-powerpoint, "
"application/msword, */*");
pj_http_headers_add_elmt2(¶m.headers, (char*)"Accept-Language",
(char*)"en-sg");
pj_http_headers_add_elmt2(¶m.headers, (char*)"User-Agent",
(char*)"Mozilla/4.0 (compatible; MSIE 7.0; "
"Windows NT 6.0; SLCC1; "
".NET CLR 2.0.50727; "
".NET CLR 3.0.04506)");
if (pj_http_req_create(pool, &url, timer_heap, ioqueue,
¶m, &hcb, &http_req))
return -43;
if (pj_http_req_start(http_req))
return -45;
//.........这里部分代码省略.........
开发者ID:Archipov,项目名称:android-client,代码行数:101,代码来源:http_client.c
示例12: client_non_ssl
/* Raw TCP socket try to connect to SSL socket server, once
* connection established, it will just do nothing, SSL socket
* server should be able to close the connection after specified
* timeout period (set ms_timeout to 0 to disable timer).
*/
static int client_non_ssl(unsigned ms_timeout)
{
pj_pool_t *pool = NULL;
pj_ioqueue_t *ioqueue = NULL;
pj_timer_heap_t *timer = NULL;
pj_ssl_sock_t *ssock_serv = NULL;
pj_activesock_t *asock_cli = NULL;
pj_activesock_cb asock_cb = { 0 };
pj_sock_t sock = PJ_INVALID_SOCKET;
pj_ssl_sock_param param;
struct test_state state_serv = { 0 };
struct test_state state_cli = { 0 };
pj_sockaddr listen_addr;
pj_ssl_cert_t *cert = NULL;
pj_status_t status;
pool = pj_pool_create(mem, "ssl_accept_raw_tcp", 256, 256, NULL);
status = pj_ioqueue_create(pool, 4, &ioqueue);
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_timer_heap_create(pool, 4, &timer);
if (status != PJ_SUCCESS) {
goto on_return;
}
/* Set cert */
{
pj_str_t tmp1, tmp2, tmp3, tmp4;
status = pj_ssl_cert_load_from_files(pool,
pj_strset2(&tmp1, (char*)CERT_CA_FILE),
pj_strset2(&tmp2, (char*)CERT_FILE),
pj_strset2(&tmp3, (char*)CERT_PRIVKEY_FILE),
pj_strset2(&tmp4, (char*)CERT_PRIVKEY_PASS),
&cert);
if (status != PJ_SUCCESS) {
goto on_return;
}
}
pj_ssl_sock_param_default(¶m);
param.cb.on_accept_complete = &ssl_on_accept_complete;
param.cb.on_data_read = &ssl_on_data_read;
param.cb.on_data_sent = &ssl_on_data_sent;
param.ioqueue = ioqueue;
param.timer_heap = timer;
param.timeout.sec = 0;
param.timeout.msec = ms_timeout;
pj_time_val_normalize(¶m.timeout);
/* SERVER */
param.user_data = &state_serv;
state_serv.pool = pool;
state_serv.is_server = PJ_TRUE;
state_serv.is_verbose = PJ_TRUE;
status = pj_ssl_sock_create(pool, ¶m, &ssock_serv);
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_ssl_sock_set_certificate(ssock_serv, pool, cert);
if (status != PJ_SUCCESS) {
goto on_return;
}
/* Init bind address */
{
pj_str_t tmp_st;
pj_sockaddr_init(PJ_AF_INET, &listen_addr, pj_strset2(&tmp_st, "127.0.0.1"), 0);
}
status = pj_ssl_sock_start_accept(ssock_serv, pool, &listen_addr, pj_sockaddr_get_len(&listen_addr));
if (status != PJ_SUCCESS) {
goto on_return;
}
/* Update listener address */
{
pj_ssl_sock_info info;
pj_ssl_sock_get_info(ssock_serv, &info);
pj_sockaddr_cp(&listen_addr, &info.local_addr);
}
/* CLIENT */
state_cli.pool = pool;
status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &sock);
if (status != PJ_SUCCESS) {
goto on_return;
}
asock_cb.on_connect_complete = &asock_on_connect_complete;
//.........这里部分代码省略.........
开发者ID:kaaustubh,项目名称:pjsip,代码行数:101,代码来源:ssl_sock.c
示例13: PJ_DEF
/**
* Initialize and get the instance of media endpoint.
*/
PJ_DEF(pj_status_t) pjmedia_endpt_create(pj_pool_factory *pf,
pj_ioqueue_t *ioqueue,
unsigned worker_cnt,
pjmedia_endpt **p_endpt)
{
pj_pool_t *pool;
pjmedia_endpt *endpt;
unsigned i;
pj_status_t status;
if (!error_subsys_registered) {
pj_register_strerror(PJMEDIA_ERRNO_START, PJ_ERRNO_SPACE_SIZE,
&pjmedia_strerror);
error_subsys_registered = 1;
}
PJ_ASSERT_RETURN(pf && p_endpt, PJ_EINVAL);
PJ_ASSERT_RETURN(worker_cnt <= MAX_THREADS, PJ_EINVAL);
pool = pj_pool_create(pf, "med-ept", 512, 512, NULL);
if (!pool)
return PJ_ENOMEM;
endpt = PJ_POOL_ZALLOC_T(pool, struct pjmedia_endpt);
endpt->pool = pool;
endpt->pf = pf;
endpt->ioqueue = ioqueue;
endpt->thread_cnt = worker_cnt;
/* Sound */
status = pjmedia_aud_subsys_init(pf);
if (status != PJ_SUCCESS)
goto on_error;
/* Init codec manager. */
status = pjmedia_codec_mgr_init(&endpt->codec_mgr);
if (status != PJ_SUCCESS)
goto on_error;
/* Create ioqueue if none is specified. */
if (endpt->ioqueue == NULL) {
endpt->own_ioqueue = PJ_TRUE;
status = pj_ioqueue_create( endpt->pool, PJ_IOQUEUE_MAX_HANDLES,
&endpt->ioqueue);
if (status != PJ_SUCCESS)
goto on_error;
if (worker_cnt == 0) {
PJ_LOG(4,(THIS_FILE, "Warning: no worker thread is created in"
"media endpoint for internal ioqueue"));
}
}
/* Create worker threads if asked. */
for (i=0; i<worker_cnt; ++i) {
status = pj_thread_create( endpt->pool, "media", &worker_proc,
endpt, 0, 0, &endpt->thread[i]);
if (status != PJ_SUCCESS)
goto on_error;
}
*p_endpt = endpt;
return PJ_SUCCESS;
on_error:
/* Destroy threads */
for (i=0; i<endpt->thread_cnt; ++i) {
if (endpt->thread[i]) {
pj_thread_destroy(endpt->thread[i]);
}
}
/* Destroy internal ioqueue */
if (endpt->ioqueue && endpt->own_ioqueue)
pj_ioqueue_destroy(endpt->ioqueue);
pjmedia_aud_subsys_shutdown();
pj_pool_release(pool);
return status;
}
开发者ID:max3903,项目名称:SFLphone,代码行数:87,代码来源:endpoint.c
示例14: bench_test
/*
* Benchmarking IOQueue
*/
static int bench_test(pj_bool_t allow_concur, int bufsize,
int inactive_sock_count)
{
pj_sock_t ssock=-1, csock=-1;
pj_sockaddr_in addr;
pj_pool_t *pool = NULL;
pj_sock_t *inactive_sock=NULL;
pj_ioqueue_op_key_t *inactive_read_op;
char *send_buf, *recv_buf;
pj_ioqueue_t *ioque = NULL;
pj_ioqueue_key_t *skey, *ckey, *keys[SOCK_INACTIVE_MAX+2];
pj_timestamp t1, t2, t_elapsed;
int rc=0, i; /* i must be signed */
pj_str_t temp;
char errbuf[PJ_ERR_MSG_SIZE];
TRACE__((THIS_FILE, " bench test %d", inactive_sock_count));
// Create pool.
pool = pj_pool_create(mem, NULL, POOL_SIZE, 4000, NULL);
// Allocate buffers for send and receive.
send_buf = (char*)pj_pool_alloc(pool, bufsize);
recv_buf = (char*)pj_pool_alloc(pool, bufsize);
// Allocate sockets for sending and receiving.
rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &ssock);
if (rc == PJ_SUCCESS) {
rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &csock);
} else
csock = PJ_INVALID_SOCKET;
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_sock_socket()", rc);
goto on_error;
}
// Bind server socket.
pj_bzero(&addr, sizeof(addr));
addr.sin_family = pj_AF_INET();
addr.sin_port = pj_htons(PORT);
if (pj_sock_bind(ssock, &addr, sizeof(addr)))
goto on_error;
pj_assert(inactive_sock_count+2 <= PJ_IOQUEUE_MAX_HANDLES);
// Create I/O Queue.
rc = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, &ioque);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_ioqueue_create()", rc);
goto on_error;
}
// Set concurrency
rc = pj_ioqueue_set_default_concurrency(ioque, allow_concur);
if (rc != PJ_SUCCESS) {
app_perror("...error: pj_ioqueue_set_default_concurrency()", rc);
goto on_error;
}
// Allocate inactive sockets, and bind them to some arbitrary address.
// Then register them to the I/O queue, and start a read operation.
inactive_sock = (pj_sock_t*)pj_pool_alloc(pool,
inactive_sock_count*sizeof(pj_sock_t));
inactive_read_op = (pj_ioqueue_op_key_t*)pj_pool_alloc(pool,
inactive_sock_count*sizeof(pj_ioqueue_op_key_t));
pj_bzero(&addr, sizeof(addr));
addr.sin_family = pj_AF_INET();
for (i=0; i<inactive_sock_count; ++i) {
pj_ssize_t bytes;
rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &inactive_sock[i]);
if (rc != PJ_SUCCESS || inactive_sock[i] < 0) {
app_perror("...error: pj_sock_socket()", rc);
goto on_error;
}
if ((rc=pj_sock_bind(inactive_sock[i], &addr, sizeof(addr))) != 0) {
pj_sock_close(inactive_sock[i]);
inactive_sock[i] = PJ_INVALID_SOCKET;
app_perror("...error: pj_sock_bind()", rc);
goto on_error;
}
rc = pj_ioqueue_register_sock(pool, ioque, inactive_sock[i],
NULL, &test_cb, &keys[i]);
if (rc != PJ_SUCCESS) {
pj_sock_close(inactive_sock[i]);
inactive_sock[i] = PJ_INVALID_SOCKET;
app_perror("...error(1): pj_ioqueue_register_sock()", rc);
PJ_LOG(3,(THIS_FILE, "....i=%d", i));
goto on_error;
}
bytes = bufsize;
rc = pj_ioqueue_recv(keys[i], &inactive_read_op[i], recv_buf, &bytes, 0);
if (rc != PJ_EPENDING) {
pj_sock_close(inactive_sock[i]);
inactive_sock[i] = PJ_INVALID_SOCKET;
app_perror("...error: pj_ioqueue_read()", rc);
goto on_error;
//.........这里部分代码省略.........
开发者ID:AbhaySingh,项目名称:pjproject,代码行数:101,代码来源:ioq_udp.c
示例15: https_client_test
static int https_client_test(unsigned ms_timeout)
{
pj_pool_t *pool = NULL;
pj_ioqueue_t *ioqueue = NULL;
pj_timer_heap_t *timer = NULL;
pj_ssl_sock_t *ssock = NULL;
pj_ssl_sock_param param;
pj_status_t status;
struct test_state state = {0};
pj_sockaddr local_addr, rem_addr;
pj_str_t tmp_st;
pool = pj_pool_create(mem, "https_get", 256, 256, NULL);
status = pj_ioqueue_create(pool, 4, &ioqueue);
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_timer_heap_create(pool, 4, &timer);
if (status != PJ_SUCCESS) {
goto on_return;
}
state.pool = pool;
state.send_str = HTTP_REQ;
state.send_str_len = pj_ansi_strlen(state.send_str);
state.is_verbose = PJ_TRUE;
pj_ssl_sock_param_default(¶m);
param.cb.on_connect_complete = &ssl_on_connect_complete;
param.cb.on_data_read = &ssl_on_data_read;
param.cb.on_data_sent = &ssl_on_data_sent;
param.ioqueue = ioqueue;
param.user_data = &state;
param.server_name = pj_str((char*)HTTP_SERVER_ADDR);
param.timer_heap = timer;
param.timeout.sec = 0;
param.timeout.msec = ms_timeout;
param.proto = PJ_SSL_SOCK_PROTO_SSL23;
pj_time_val_normalize(¶m.timeout);
status = pj_ssl_sock_create(pool, ¶m, &ssock);
if (status != PJ_SUCCESS) {
goto on_return;
}
pj_sockaddr_init(PJ_AF_INET, &local_addr, pj_strset2(&tmp_st, "0.0.0.0"), 0);
pj_sockaddr_init(PJ_AF_INET, &rem_addr, pj_strset2(&tmp_st, HTTP_SERVER_ADDR), HTTP_SERVER_PORT);
status = pj_ssl_sock_start_connect(ssock, pool, &local_addr, &rem_addr, sizeof(rem_addr));
if (status == PJ_SUCCESS) {
ssl_on_connect_complete(ssock, PJ_SUCCESS);
} else if (status == PJ_EPENDING) {
status = PJ_SUCCESS;
} else {
goto on_return;
}
/* Wait until everything has been sent/received */
while (state.err == PJ_SUCCESS && !state.done) {
#ifdef PJ_SYMBIAN
pj_symbianos_poll(-1, 1000);
#else
pj_time_val delay = {0, 100};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer, &delay);
#endif
}
if (state.err) {
status = state.err;
goto on_return;
}
PJ_LOG(3, ("", "...Done!"));
PJ_LOG(3, ("", ".....Sent/recv: %d/%d bytes", state.sent, state.recv));
on_return:
if (ssock && !state.err && !state.done)
pj_ssl_sock_close(ssock);
if (ioqueue)
pj_ioqueue_destroy(ioqueue);
if (timer)
pj_timer_heap_destroy(timer);
if (pool)
pj_pool_release(pool);
return status;
}
开发者ID:kaaustubh,项目名称:pjsip,代码行数:89,代码来源:ssl_sock.c
示例16: PJ_DEF
/*
* Create the resolver.
*/
PJ_DEF(pj_status_t) pj_dns_resolver_create( pj_pool_factory *pf,
const char *name,
unsigned options,
pj_timer_heap_t *timer,
pj_ioqueue_t *ioqueue,
pj_dns_resolver **p_resolver)
{
pj_pool_t *pool;
pj_dns_resolver *resv;
pj_ioqueue_callback socket_cb;
pj_status_t status;
/* Sanity check */
PJ_ASSERT_RETURN(pf && p_resolver, PJ_EINVAL);
if (name == NULL)
name = THIS_FILE;
/* Create and initialize resolver instance */
pool = pj_pool_create(pf, name, 4000, 4000, NULL);
if (!pool)
return PJ_ENOMEM;
/* Create pool and name */
resv = PJ_POOL_ZALLOC_T(pool, struct pj_dns_resolver);
resv->pool = pool;
resv->udp_sock = PJ_INVALID_SOCKET;
pj_strdup2_with_null(pool, &resv->name, name);
/* Create the mutex */
status = pj_mutex_create_recursive(pool, name, &resv->mutex);
if (status != PJ_SUCCESS)
goto on_error;
/* Timer, ioqueue, and settings */
resv->timer = timer;
resv->ioqueue = ioqueue;
resv->last_id = 1;
pj_dns_settings_default(&resv->settings);
resv->settings.options = options;
/* Create the timer heap if one is not specified */
if (resv->timer == NULL) {
status = pj_timer_heap_create(pool, TIMER_SIZE, &resv->timer);
if (status != PJ_SUCCESS)
goto on_error;
}
/* Create the ioqueue if one is not specified */
if (resv->ioqueue == NULL) {
status = pj_ioqueue_create(pool, MAX_FD, &resv->ioqueue);
if (status != PJ_SUCCESS)
goto on_error;
}
/* Response cache hash table */
resv->hrescache = pj_hash_create(pool, RES_HASH_TABLE_SIZE);
/* Query hash table and free list. */
resv->hquerybyid = pj_hash_create(pool, Q_HASH_TABLE_SIZE);
resv->hquerybyres = pj_hash_create(pool, Q_HASH_TABLE_SIZE);
pj_list_init(&resv->query_free_nodes);
/* Create the UDP socket */
status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &resv->udp_sock);
if (status != PJ_SUCCESS)
goto on_error;
/* Bind to any address/port */
status = pj_sock_bind_in(resv->udp_sock, 0, 0);
if (status != PJ_SUCCESS)
goto on_error;
/* Register to ioqueue */
pj_bzero(&socket_cb, sizeof(socket_cb));
socket_cb.on_read_complete = &on_read_complete;
status = pj_ioqueue_register_sock(pool, resv->ioqueue, resv->udp_sock,
resv, &socket_cb, &resv->udp_key);
if (status != PJ_SUCCESS)
goto on_error;
pj_ioqueue_op_key_init(&resv->udp_op_key, sizeof(resv->udp_op_key));
/* Start asynchronous read to the UDP socket */
resv->udp_len = sizeof(resv->udp_rx_pkt);
resv->udp_addr_len = sizeof(resv->udp_src_addr);
status = pj_ioqueue_recvfrom(resv->udp_key, &resv->udp_op_key,
resv->udp_rx_pkt, &resv->udp_len,
PJ_IOQUEUE_ALWAYS_ASYNC,
&resv->udp_src_addr, &resv->udp_addr_len);
if (status != PJ_EPENDING)
goto on_error;
/* Looks like everything is okay */
*p_resolver = resv;
//.........这里部分代码省略.........
开发者ID:leprechuanese,项目名称:factsys,代码行数:101,代码来源:resolver.c
示例17: PJ_DEF
/**
* Initialize and get the instance of media endpoint.
*/
PJ_DEF(pj_status_t) pjmedia_endpt_create2(pj_pool_factory *pf,
pj_ioqueue_t *ioqueue,
unsigned worker_cnt,
pjmedia_endpt **p_endpt)
{
pj_pool_t *pool;
pjmedia_endpt *endpt;
unsigned i;
pj_status_t status;
status = pj_register_strerror(PJMEDIA_ERRNO_START, PJ_ERRNO_SPACE_SIZE,
&pjmedia_strerror);
pj_assert(status == PJ_SUCCESS);
PJ_ASSERT_RETURN(pf && p_endpt, PJ_EINVAL);
PJ_ASSERT_RETURN(worker_cnt <= MAX_THREADS, PJ_EINVAL);
pool = pj_pool_create(pf, "med-ept", 512, 512, NULL);
if (!pool)
return PJ_ENOMEM;
endpt = PJ_POOL_ZALLOC_T(pool, struct pjmedia_endpt);
endpt->pool = pool;
endpt->pf = pf;
endpt->ioqueue = ioqueue;
endpt->thread_cnt = worker_cnt;
endpt->has_telephone_event = PJ_TRUE;
/* Initialize audio subsystem.
* To avoid pjmedia's dependendy on pjmedia-audiodev, the initialization
* (and shutdown) of audio subsystem will be done in the application
* level instead, when it calls inline functions pjmedia_endpt_create()
* and pjmedia_endpt_destroy().
*/
//status = pjmedia_aud_subsys_init(pf);
//if (status != PJ_SUCCESS)
/
|
请发表评论