Changeset 1620 for pjproject/trunk/pjsip-apps/src/samples/debug.c
- Timestamp:
- Dec 5, 2007 4:30:04 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/debug.c
r1618 r1620 28 28 * #include "playfile.c" 29 29 */ 30 //#include "aectest.c" 31 //#include "strerror.c" 30 #include "aectest.c" 32 31 33 #include <pjlib.h>34 #include <pjlib-util.h>35 36 #define THIS_FILE "test.c"37 38 void check_error(const char *func, pj_status_t status)39 {40 if (status != PJ_SUCCESS) {41 char errmsg[PJ_ERR_MSG_SIZE];42 pj_strerror(status, errmsg, sizeof(errmsg));43 PJ_LOG(1,(THIS_FILE, "%s error: %s", func, errmsg));44 exit(1);45 }46 }47 48 #define DO(func) status = func; check_error(#func, status);49 50 int main()51 {52 pj_sock_t sock;53 pj_sockaddr_in addr;54 pj_str_t stun_srv = pj_str("stun.fwdnet.net");55 pj_caching_pool cp;56 pj_status_t status;57 58 DO( pj_init() );59 60 pj_caching_pool_init(&cp, NULL, 0);61 62 DO( pjlib_util_init() );63 DO( pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sock) );64 DO( pj_sock_bind_in(sock, 0, 0) );65 66 DO( pjstun_get_mapped_addr(&cp.factory, 1, &sock,67 &stun_srv, 3478,68 &stun_srv, 3478,69 &addr) );70 71 PJ_LOG(3,(THIS_FILE, "Mapped address is %s:%d",72 pj_inet_ntoa(addr.sin_addr),73 (int)pj_ntohs(addr.sin_port)));74 75 DO( pj_sock_close(sock) );76 pj_caching_pool_destroy(&cp);77 pj_shutdown();78 79 return 0;80 }81 82 83 #if 084 #include <pjlib.h>85 86 static void on_accept_complete(pj_ioqueue_key_t *key,87 pj_ioqueue_op_key_t *op_key,88 pj_sock_t sock,89 pj_status_t status)90 {91 }92 93 static void on_read_complete(pj_ioqueue_key_t *key,94 pj_ioqueue_op_key_t *op_key,95 pj_ssize_t bytes_read)96 {97 }98 99 100 int main()101 {102 pj_status_t status;103 pj_caching_pool cp;104 pj_pool_t *pool;105 pj_sock_t sock, new_sock;106 pj_ioqueue_t *ioqueue;107 pj_ioqueue_op_key_t op_key;108 pj_ioqueue_callback cb;109 pj_ioqueue_key_t *key;110 111 status = pj_init();112 PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);113 114 pj_caching_pool_init(&cp, NULL, 0);115 pool = pj_pool_create(&cp.factory, "app", 1000, 1000, NULL);116 117 status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &sock);118 PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);119 120 status = pj_sock_bind_in(sock, 0, 80);121 if (status != PJ_SUCCESS)122 return 1;123 124 status = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, &ioqueue);125 PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);126 127 status = pj_sock_listen(sock, 5);128 PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);129 130 pj_bzero(&cb, sizeof(cb));131 cb.on_accept_complete = &on_accept_complete;132 cb.on_read_complete = &on_read_complete;133 134 status = pj_ioqueue_register_sock(pool, ioqueue, sock, NULL, &cb, &key);135 PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1);136 137 pj_ioqueue_op_key_init(&op_key, sizeof(op_key));138 status = pj_ioqueue_accept(key, &op_key, &new_sock, NULL, NULL, NULL);139 PJ_ASSERT_RETURN(status==PJ_EPENDING, 1);140 }141 142 #endif
Note: See TracChangeset
for help on using the changeset viewer.