diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-07-20 08:08:30 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-07-20 08:08:30 +0000 |
commit | d24a9aee403d6540ec792d3b56a1934fbc0969d4 (patch) | |
tree | 0706522f9173a479f4f3af4e6fbf1e1cddb9ef2b /pjlib/src | |
parent | c3f4bae326d9e2dfa78d23f288e822e7ae16c2db (diff) |
Ticket #354: build PJLIB as dynamic libraries (.DSO) in Symbian
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1405 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src')
32 files changed, 523 insertions, 175 deletions
diff --git a/pjlib/src/pj/addr_resolv_sock.c b/pjlib/src/pj/addr_resolv_sock.c index 9e64378b..408eae12 100644 --- a/pjlib/src/pj/addr_resolv_sock.c +++ b/pjlib/src/pj/addr_resolv_sock.c @@ -83,7 +83,7 @@ PJ_DEF(pj_status_t) pj_gethostip(pj_in_addr *addr) pj_sockaddr_in a; int len; - status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &fd); + status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &fd); if (status != PJ_SUCCESS) { return status; } diff --git a/pjlib/src/pj/addr_resolv_symbian.cpp b/pjlib/src/pj/addr_resolv_symbian.cpp index 95da5cdd..ea3c7660 100644 --- a/pjlib/src/pj/addr_resolv_symbian.cpp +++ b/pjlib/src/pj/addr_resolv_symbian.cpp @@ -76,7 +76,7 @@ PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he) // Return hostent he->h_name = resolved_name; he->h_aliases = no_aliases; - he->h_addrtype = PJ_AF_INET; + he->h_addrtype = pj_AF_INET(); he->h_length = 4; he->h_addr_list = (char**) addr_list; @@ -85,7 +85,7 @@ PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he) /* Resolve the IP address of local machine */ -pj_status_t pj_gethostip(pj_in_addr *addr) +PJ_DEF(pj_status_t) pj_gethostip(pj_in_addr *addr) { const pj_str_t *hostname = pj_gethostname(); struct pj_hostent he; @@ -111,7 +111,7 @@ pj_status_t pj_gethostip(pj_in_addr *addr) pj_sockaddr_in a; int len; - status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &fd); + status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &fd); if (status != PJ_SUCCESS) { return status; } diff --git a/pjlib/src/pj/errno.c b/pjlib/src/pj/errno.c index f7273a42..a11f3b43 100644 --- a/pjlib/src/pj/errno.c +++ b/pjlib/src/pj/errno.c @@ -101,7 +101,7 @@ static int pjlib_error(pj_status_t code, char *buf, pj_size_t size) #define IN_RANGE(val,start,end) ((val)>=(start) && (val)<(end)) /* Register strerror handle. */ -PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start, +PJ_DEF(pj_status_t) pj_register_strerror( pj_status_t start, pj_status_t space, pjsip_error_callback f) { diff --git a/pjlib/src/pj/fifobuf.c b/pjlib/src/pj/fifobuf.c index 08bf907a..54a23753 100644 --- a/pjlib/src/pj/fifobuf.c +++ b/pjlib/src/pj/fifobuf.c @@ -25,8 +25,7 @@ #define SZ sizeof(unsigned) -PJ_DEF(void) -pj_fifobuf_init (pj_fifobuf_t *fifobuf, void *buffer, unsigned size) +PJ_DEF(void) pj_fifobuf_init (pj_fifobuf_t *fifobuf, void *buffer, unsigned size) { PJ_CHECK_STACK(); @@ -40,8 +39,7 @@ pj_fifobuf_init (pj_fifobuf_t *fifobuf, void *buffer, unsigned size) fifobuf->full = 0; } -PJ_DEF(unsigned) -pj_fifobuf_max_size (pj_fifobuf_t *fifobuf) +PJ_DEF(unsigned) pj_fifobuf_max_size (pj_fifobuf_t *fifobuf) { unsigned s1, s2; @@ -57,8 +55,7 @@ pj_fifobuf_max_size (pj_fifobuf_t *fifobuf) return s1<s2 ? s2 : s1; } -PJ_DEF(void*) -pj_fifobuf_alloc (pj_fifobuf_t *fifobuf, unsigned size) +PJ_DEF(void*) pj_fifobuf_alloc (pj_fifobuf_t *fifobuf, unsigned size) { unsigned available; char *start; @@ -115,8 +112,7 @@ pj_fifobuf_alloc (pj_fifobuf_t *fifobuf, unsigned size) return NULL; } -PJ_DEF(pj_status_t) -pj_fifobuf_unalloc (pj_fifobuf_t *fifobuf, void *buf) +PJ_DEF(pj_status_t) pj_fifobuf_unalloc (pj_fifobuf_t *fifobuf, void *buf) { char *ptr = (char*)buf; char *endptr; @@ -146,8 +142,7 @@ pj_fifobuf_unalloc (pj_fifobuf_t *fifobuf, void *buf) return 0; } -PJ_DEF(pj_status_t) -pj_fifobuf_free (pj_fifobuf_t *fifobuf, void *buf) +PJ_DEF(pj_status_t) pj_fifobuf_free (pj_fifobuf_t *fifobuf, void *buf) { char *ptr = (char*)buf; char *end; diff --git a/pjlib/src/pj/file_io_ansi.c b/pjlib/src/pj/file_io_ansi.c index 6d340ce1..1bdfef8b 100644 --- a/pjlib/src/pj/file_io_ansi.c +++ b/pjlib/src/pj/file_io_ansi.c @@ -109,11 +109,13 @@ PJ_DEF(pj_status_t) pj_file_read( pj_oshandle_t fd, return PJ_SUCCESS; } +/* PJ_DEF(pj_bool_t) pj_file_eof(pj_oshandle_t fd, enum pj_file_access access) { PJ_UNUSED_ARG(access); return feof((FILE*)fd) ? PJ_TRUE : 0; } +*/ PJ_DEF(pj_status_t) pj_file_setpos( pj_oshandle_t fd, pj_off_t offset, diff --git a/pjlib/src/pj/ioqueue_common_abs.c b/pjlib/src/pj/ioqueue_common_abs.c index 8fd1be72..fdd1afe7 100644 --- a/pjlib/src/pj/ioqueue_common_abs.c +++ b/pjlib/src/pj/ioqueue_common_abs.c @@ -100,10 +100,10 @@ static pj_status_t ioqueue_init_key( pj_pool_t *pool, * will be performed during send to allow parallel send operations. */ optlen = sizeof(key->fd_type); - rc = pj_sock_getsockopt(sock, PJ_SOL_SOCKET, PJ_SO_TYPE, + rc = pj_sock_getsockopt(sock, pj_SOL_SOCKET(), pj_SO_TYPE(), &key->fd_type, &optlen); if (rc != PJ_SUCCESS) - key->fd_type = PJ_SOCK_STREAM; + key->fd_type = pj_SOCK_STREAM(); /* Create mutex for the key. */ #if !PJ_IOQUEUE_HAS_SAFE_UNREG @@ -269,7 +269,7 @@ void ioqueue_dispatch_write_event(pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h) /* For datagrams, we can remove the write_op from the list * so that send() can work in parallel. */ - if (h->fd_type == PJ_SOCK_DGRAM) { + if (h->fd_type == pj_SOCK_DGRAM()) { pj_list_erase(write_op); if (pj_list_empty(&h->write_list)) @@ -315,12 +315,12 @@ void ioqueue_dispatch_write_event(pj_ioqueue_t *ioqueue, pj_ioqueue_key_t *h) /* Are we finished with this buffer? */ if (send_rc!=PJ_SUCCESS || write_op->written == (pj_ssize_t)write_op->size || - h->fd_type == PJ_SOCK_DGRAM) + h->fd_type == pj_SOCK_DGRAM()) { write_op->op = PJ_IOQUEUE_OP_NONE; - if (h->fd_type != PJ_SOCK_DGRAM) { + if (h->fd_type != pj_SOCK_DGRAM()) { /* Write completion of the whole stream. */ pj_list_erase(write_op); diff --git a/pjlib/src/pj/ioqueue_select.c b/pjlib/src/pj/ioqueue_select.c index e200d642..48612d22 100644 --- a/pjlib/src/pj/ioqueue_select.c +++ b/pjlib/src/pj/ioqueue_select.c @@ -64,22 +64,6 @@ # error "Error reporting must be enabled for this function to work!" #endif -/** - * Get the number of descriptors in the set. This is defined in sock_select.c - * This function will only return the number of sockets set from PJ_FD_SET - * operation. When the set is modified by other means (such as by select()), - * the count will not be reflected here. - * - * That's why don't export this function in the header file, to avoid - * misunderstanding. - * - * @param fdsetp The descriptor set. - * - * @return Number of descriptors in the set. - */ -PJ_DECL(pj_size_t) PJ_FD_COUNT(const pj_fd_set_t *fdsetp); - - /* * During debugging build, VALIDATE_FD_SET is set. * This will check the validity of the fd_sets. diff --git a/pjlib/src/pj/ioqueue_winnt.c b/pjlib/src/pj/ioqueue_winnt.c index 8d17878e..3e8253e1 100644 --- a/pjlib/src/pj/ioqueue_winnt.c +++ b/pjlib/src/pj/ioqueue_winnt.c @@ -1106,7 +1106,7 @@ PJ_DEF(pj_status_t) pj_ioqueue_accept( pj_ioqueue_key_t *key, */ op_key_rec = (union operation_key*)op_key->internal__; - status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0, + status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &op_key_rec->accept.newsock); if (status != PJ_SUCCESS) return status; diff --git a/pjlib/src/pj/log.c b/pjlib/src/pj/log.c index 518854c4..59e8956f 100644 --- a/pjlib/src/pj/log.c +++ b/pjlib/src/pj/log.c @@ -24,7 +24,11 @@ #if PJ_LOG_MAX_LEVEL >= 1 -PJ_DEF(int) pj_log_max_level = PJ_LOG_MAX_LEVEL; +#if 0 +PJ_DEF_DATA(int) pj_log_max_level = PJ_LOG_MAX_LEVEL; +#else +static int pj_log_max_level = PJ_LOG_MAX_LEVEL; +#endif static pj_log_func *log_writer = &pj_log_write; static unsigned log_decor = PJ_LOG_HAS_TIME | PJ_LOG_HAS_MICRO_SEC | PJ_LOG_HAS_SENDER | PJ_LOG_HAS_NEWLINE; @@ -48,7 +52,7 @@ PJ_DEF(void) pj_log_set_level(int level) pj_log_max_level = level; } -#if 0 +#if 1 PJ_DEF(int) pj_log_get_level(void) { return pj_log_max_level; @@ -169,6 +173,7 @@ PJ_DEF(void) pj_log( const char *sender, int level, (*log_writer)(level, log_buffer, len); } +/* PJ_DEF(void) pj_log_0(const char *obj, const char *format, ...) { va_list arg; @@ -176,6 +181,7 @@ PJ_DEF(void) pj_log_0(const char *obj, const char *format, ...) pj_log(obj, 0, format, arg); va_end(arg); } +*/ PJ_DEF(void) pj_log_1(const char *obj, const char *format, ...) { diff --git a/pjlib/src/pj/os_core_symbian.cpp b/pjlib/src/pj/os_core_symbian.cpp index a3ec3c04..f13365a5 100644 --- a/pjlib/src/pj/os_core_symbian.cpp +++ b/pjlib/src/pj/os_core_symbian.cpp @@ -260,8 +260,6 @@ PJ_DEF(pj_uint32_t) pj_getpid(void) } -PJ_DECL(void) pj_shutdown(void); - /* * pj_init(void). * Init PJLIB! @@ -333,6 +331,94 @@ PJ_DEF(void) pj_shutdown(void) os->Shutdown(); } +///////////////////////////////////////////////////////////////////////////// + +class CPollTimeoutTimer : public CActive +{ +public: + static CPollTimeoutTimer* NewL(int msec, TInt prio); + ~CPollTimeoutTimer(); + + virtual void RunL(); + virtual void DoCancel(); + +private: + RTimer rtimer_; + + explicit CPollTimeoutTimer(TInt prio); + void ConstructL(int msec); +}; + +CPollTimeoutTimer::CPollTimeoutTimer(TInt prio) +: CActive(prio) +{ +} + + +CPollTimeoutTimer::~CPollTimeoutTimer() +{ + rtimer_.Close(); +} + +void CPollTimeoutTimer::ConstructL(int msec) +{ + rtimer_.CreateLocal(); + CActiveScheduler::Add(this); + rtimer_.After(iStatus, msec*1000); + SetActive(); +} + +CPollTimeoutTimer* CPollTimeoutTimer::NewL(int msec, TInt prio) +{ + CPollTimeoutTimer *self = new CPollTimeoutTimer(prio); + CleanupStack::PushL(self); + self->ConstructL(msec); + CleanupStack::Pop(self); + + return self; +} + +void CPollTimeoutTimer::RunL() +{ +} + +void CPollTimeoutTimer::DoCancel() +{ + rtimer_.Cancel(); +} + + +/* + * Wait the completion of any Symbian active objects. + */ +PJ_DEF(pj_bool_t) pj_symbianos_poll(int priority, int ms_timeout) +{ + CPollTimeoutTimer *timer = NULL; + + if (priority==-1) + priority = CActive::EPriorityStandard; + + if (ms_timeout >= 0) { + timer = CPollTimeoutTimer::NewL(ms_timeout, priority); + } + + PjSymbianOS::Instance()->WaitForActiveObjects(priority); + + if (timer) { + bool timer_is_active = timer->IsActive(); + + if (timer_is_active) + timer->Cancel(); + + delete timer; + + return timer_is_active ? PJ_TRUE : PJ_FALSE; + + } else { + return PJ_TRUE; + } +} + /* * pj_thread_register(..) diff --git a/pjlib/src/pj/os_symbian.h b/pjlib/src/pj/os_symbian.h index a1977871..abfa7f04 100644 --- a/pjlib/src/pj/os_symbian.h +++ b/pjlib/src/pj/os_symbian.h @@ -220,7 +220,7 @@ public: pj_sockaddr_in &pj_addr) { pj_bzero(&pj_addr, sizeof(pj_sockaddr_in)); - pj_addr.sin_family = PJ_AF_INET; + pj_addr.sin_family = pj_AF_INET(); pj_addr.sin_addr.s_addr = pj_htonl(sym_addr.Address()); pj_addr.sin_port = pj_htons((pj_uint16_t) sym_addr.Port()); } diff --git a/pjlib/src/pj/os_time_common.c b/pjlib/src/pj/os_time_common.c index 5fffe948..331116bc 100644 --- a/pjlib/src/pj/os_time_common.c +++ b/pjlib/src/pj/os_time_common.c @@ -18,6 +18,8 @@ */ #include <pj/os.h> #include <pj/compat/time.h> +#include <pj/errno.h> + /////////////////////////////////////////////////////////////////////////////// @@ -65,11 +67,19 @@ PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv) /** * Convert local time to GMT. */ -PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv); +PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv) +{ + PJ_UNUSED_ARG(tv); + return PJ_EBUG; +} /** * Convert GMT to local time. */ -PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv); +PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv) +{ + PJ_UNUSED_ARG(tv); + return PJ_EBUG; +} diff --git a/pjlib/src/pj/pool_caching.c b/pjlib/src/pj/pool_caching.c index 01c303d6..295d6b9a 100644 --- a/pjlib/src/pj/pool_caching.c +++ b/pjlib/src/pj/pool_caching.c @@ -65,6 +65,10 @@ PJ_DEF(void) pj_caching_pool_init( pj_caching_pool *cp, for (i=0; i<PJ_CACHING_POOL_ARRAY_SIZE; ++i) pj_list_init(&cp->free_list[i]); + if (policy == NULL) { + policy = &pj_pool_factory_default_policy; + } + pj_memcpy(&cp->factory.policy, policy, sizeof(pj_pool_factory_policy)); cp->factory.create_pool = &cpool_create_pool; cp->factory.release_pool = &cpool_release_pool; diff --git a/pjlib/src/pj/pool_policy_kmalloc.c b/pjlib/src/pj/pool_policy_kmalloc.c index 439fa4c5..7dc4044d 100644 --- a/pjlib/src/pj/pool_policy_kmalloc.c +++ b/pjlib/src/pj/pool_policy_kmalloc.c @@ -56,3 +56,8 @@ pj_pool_factory_policy pj_pool_factory_default_policy = 0 }; +PJ_DEF(const pj_pool_factory_policy*) pj_pool_factory_get_default_policy(void) +{ + return &pj_pool_factory_default_policy; +} + diff --git a/pjlib/src/pj/pool_policy_malloc.c b/pjlib/src/pj/pool_policy_malloc.c index d7e8ad1f..38db7fd7 100644 --- a/pjlib/src/pj/pool_policy_malloc.c +++ b/pjlib/src/pj/pool_policy_malloc.c @@ -86,7 +86,7 @@ static void default_pool_callback(pj_pool_t *pool, pj_size_t size) PJ_THROW(PJ_NO_MEMORY_EXCEPTION); } -pj_pool_factory_policy pj_pool_factory_default_policy = +PJ_DECL_DATA(pj_pool_factory_policy) pj_pool_factory_default_policy = { &default_block_alloc, &default_block_free, @@ -94,4 +94,10 @@ pj_pool_factory_policy pj_pool_factory_default_policy = 0 }; +PJ_DEF(const pj_pool_factory_policy*) pj_pool_factory_get_default_policy(void) +{ + return &pj_pool_factory_default_policy; +} + + #endif /* PJ_HAS_POOL_ALT_API */ diff --git a/pjlib/src/pj/pool_policy_new.cpp b/pjlib/src/pj/pool_policy_new.cpp index 82374adc..42771660 100644 --- a/pjlib/src/pj/pool_policy_new.cpp +++ b/pjlib/src/pj/pool_policy_new.cpp @@ -77,19 +77,19 @@ static void default_pool_callback(pj_pool_t *pool, pj_size_t size) PJ_THROW(PJ_NO_MEMORY_EXCEPTION); } -pj_pool_factory_policy pj_pool_factory_default_policy = +PJ_DEF_DATA(pj_pool_factory_policy) pj_pool_factory_default_policy = { &operator_new, &operator_delete, &default_pool_callback, 0 }; - -PJ_DEF(pj_pool_factory_policy*) pj_pool_factory_get_default_policy(void) + +PJ_DEF(const pj_pool_factory_policy*) pj_pool_factory_get_default_policy(void) { return &pj_pool_factory_default_policy; } - + #endif /* PJ_HAS_POOL_ALT_API */ diff --git a/pjlib/src/pj/sock_common.c b/pjlib/src/pj/sock_common.c new file mode 100644 index 00000000..4431f593 --- /dev/null +++ b/pjlib/src/pj/sock_common.c @@ -0,0 +1,145 @@ +/* $Id$ */ +/* + * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <pj/sock.h> + +PJ_DEF(pj_uint16_t) pj_AF_UNIX(void) +{ + return PJ_AF_UNIX; +} + +PJ_DEF(pj_uint16_t) pj_AF_INET(void) +{ + return PJ_AF_INET; +} + +PJ_DEF(pj_uint16_t) pj_AF_INET6(void) +{ + return PJ_AF_INET6; +} + +PJ_DEF(pj_uint16_t) pj_AF_PACKET(void) +{ + return PJ_AF_PACKET; +} + +PJ_DEF(pj_uint16_t) pj_AF_IRDA(void) +{ + return PJ_AF_IRDA; +} + +PJ_DEF(int) pj_SOCK_STREAM(void) +{ + return PJ_SOCK_STREAM; +} + +PJ_DEF(int) pj_SOCK_DGRAM(void) +{ + return PJ_SOCK_DGRAM; +} + +PJ_DEF(int) pj_SOCK_RAW(void) +{ + return PJ_SOCK_RAW; +} + +PJ_DEF(int) pj_SOCK_RDM(void) +{ + return PJ_SOCK_RDM; +} + +PJ_DEF(pj_uint16_t) pj_SOL_SOCKET(void) +{ + return PJ_SOL_SOCKET; +} + +PJ_DEF(pj_uint16_t) pj_SOL_IP(void) +{ + return PJ_SOL_IP; +} + +PJ_DEF(pj_uint16_t) pj_SOL_TCP(void) +{ + return PJ_SOL_TCP; +} + +PJ_DEF(pj_uint16_t) pj_SOL_UDP(void) +{ + return PJ_SOL_UDP; +} + +PJ_DEF(pj_uint16_t) pj_SOL_IPV6(void) +{ + return PJ_SOL_IPV6; +} + +PJ_DEF(int) pj_IP_TOS(void) +{ + return PJ_IP_TOS; +} + +PJ_DEF(int) pj_IPTOS_LOWDELAY(void) +{ + return PJ_IPTOS_LOWDELAY; +} + +PJ_DEF(int) pj_IPTOS_THROUGHPUT(void) +{ + return PJ_IPTOS_THROUGHPUT; +} + +PJ_DEF(int) pj_IPTOS_RELIABILITY(void) +{ + return PJ_IPTOS_RELIABILITY; +} + +PJ_DEF(int) pj_IPTOS_MINCOST(void) +{ + return PJ_IPTOS_MINCOST; +} + +PJ_DEF(pj_uint16_t) pj_SO_TYPE(void) +{ + return PJ_SO_TYPE; +} + +PJ_DEF(pj_uint16_t) pj_SO_RCVBUF(void) +{ + return PJ_SO_RCVBUF; +} + +PJ_DEF(pj_uint16_t) pj_SO_SNDBUF(void) +{ + return PJ_SO_SNDBUF; +} + +PJ_DEF(int) pj_MSG_OOB(void) +{ + return PJ_MSG_OOB; +} + +PJ_DEF(int) pj_MSG_PEEK(void) +{ + return PJ_MSG_PEEK; +} + +PJ_DEF(int) pj_MSG_DONTROUTE(void) +{ + return PJ_MSG_DONTROUTE; +} + diff --git a/pjlib/src/pj/sock_symbian.cpp b/pjlib/src/pj/sock_symbian.cpp index 38960917..7c7680a9 100644 --- a/pjlib/src/pj/sock_symbian.cpp +++ b/pjlib/src/pj/sock_symbian.cpp @@ -52,11 +52,22 @@ const pj_uint16_t PJ_SOL_TCP = 0xFFFF; const pj_uint16_t PJ_SOL_UDP = 0xFFFF; const pj_uint16_t PJ_SOL_IPV6 = 0xFFFF; +/* TOS */ +const pj_uint16_t PJ_IP_TOS = 0; +const pj_uint16_t PJ_IPTOS_LOWDELAY = 0; +const pj_uint16_t PJ_IPTOS_THROUGHPUT = 0; +const pj_uint16_t PJ_IPTOS_RELIABILITY = 0; +const pj_uint16_t PJ_IPTOS_MINCOST = 0; + /* ioctl() is also not supported. */ const pj_uint16_t PJ_SO_TYPE = 0xFFFF; const pj_uint16_t PJ_SO_RCVBUF = 0xFFFF; const pj_uint16_t PJ_SO_SNDBUF = 0xFFFF; +/* Flags */ +const int PJ_MSG_OOB = 0; +const int PJ_MSG_PEEK = KSockReadPeek; +const int PJ_MSG_DONTROUTE = 0; ///////////////////////////////////////////////////////////////////////////// // @@ -455,9 +466,9 @@ PJ_DEF(pj_status_t) pj_sock_socket(int af, /* Set proto if none is specified. */ if (proto == 0) { - if (type == PJ_SOCK_STREAM) + if (type == pj_SOCK_STREAM()) proto = KProtocolInetTcp; - else if (type == PJ_SOCK_DGRAM) + else if (type == pj_SOCK_DGRAM()) proto = KProtocolInetUdp; } diff --git a/pjlib/src/pj/types.c b/pjlib/src/pj/types.c index 030d6fce..1581b4c1 100644 --- a/pjlib/src/pj/types.c +++ b/pjlib/src/pj/types.c @@ -19,7 +19,7 @@ #include <pj/types.h> #include <pj/os.h> -void pj_time_val_normalize(pj_time_val *t) +PJ_DEF(void) pj_time_val_normalize(pj_time_val *t) { PJ_CHECK_STACK(); diff --git a/pjlib/src/pjlib-test/echo_clt.c b/pjlib/src/pjlib-test/echo_clt.c index d13391e9..4f7448b0 100644 --- a/pjlib/src/pjlib-test/echo_clt.c +++ b/pjlib/src/pjlib-test/echo_clt.c @@ -65,7 +65,7 @@ static int echo_client_thread(void *arg) pj_status_t last_recv_err = PJ_SUCCESS, last_send_err = PJ_SUCCESS; unsigned counter = 0; - rc = app_socket(PJ_AF_INET, client->sock_type, 0, -1, &sock); + rc = app_socket(pj_AF_INET(), client->sock_type, 0, -1, &sock); if (rc != PJ_SUCCESS) { app_perror("...unable to create socket", rc); return -10; diff --git a/pjlib/src/pjlib-test/ioq_perf.c b/pjlib/src/pjlib-test/ioq_perf.c index e15fe1be..92d4540d 100644 --- a/pjlib/src/pjlib-test/ioq_perf.c +++ b/pjlib/src/pjlib-test/ioq_perf.c @@ -275,7 +275,7 @@ static int perform_test(int sock_type, const char *type_name, /* Create socket pair. */ TRACE_((THIS_FILE, " calling socketpair..")); - rc = app_socketpair(PJ_AF_INET, sock_type, 0, + rc = app_socketpair(pj_AF_INET(), sock_type, 0, &items[i].server_fd, &items[i].client_fd); if (rc != PJ_SUCCESS) { app_perror("...error: unable to create socket pair", rc); @@ -451,49 +451,49 @@ int ioqueue_perf_test(void) int sockpair_cnt; } test_param[] = { - { PJ_SOCK_DGRAM, "udp", 1, 1}, - { PJ_SOCK_DGRAM, "udp", 1, 2}, - { PJ_SOCK_DGRAM, "udp", 1, 4}, - { PJ_SOCK_DGRAM, "udp", 1, 8}, - { PJ_SOCK_DGRAM, "udp", 2, 1}, - { PJ_SOCK_DGRAM, "udp", 2, 2}, - { PJ_SOCK_DGRAM, "udp", 2, 4}, - { PJ_SOCK_DGRAM, "udp", 2, 8}, - { PJ_SOCK_DGRAM, "udp", 4, 1}, - { PJ_SOCK_DGRAM, "udp", 4, 2}, - { PJ_SOCK_DGRAM, "udp", 4, 4}, - { PJ_SOCK_DGRAM, "udp", 4, 8}, - { PJ_SOCK_DGRAM, "udp", 4, 16}, - { PJ_SOCK_STREAM, "tcp", 1, 1}, - { PJ_SOCK_STREAM, "tcp", 1, 2}, - { PJ_SOCK_STREAM, "tcp", 1, 4}, - { PJ_SOCK_STREAM, "tcp", 1, 8}, - { PJ_SOCK_STREAM, "tcp", 2, 1}, - { PJ_SOCK_STREAM, "tcp", 2, 2}, - { PJ_SOCK_STREAM, "tcp", 2, 4}, - { PJ_SOCK_STREAM, "tcp", 2, 8}, - { PJ_SOCK_STREAM, "tcp", 4, 1}, - { PJ_SOCK_STREAM, "tcp", 4, 2}, - { PJ_SOCK_STREAM, "tcp", 4, 4}, - { PJ_SOCK_STREAM, "tcp", 4, 8}, - { PJ_SOCK_STREAM, "tcp", 4, 16}, + { pj_SOCK_DGRAM(), "udp", 1, 1}, + { pj_SOCK_DGRAM(), "udp", 1, 2}, + { pj_SOCK_DGRAM(), "udp", 1, 4}, + { pj_SOCK_DGRAM(), "udp", 1, 8}, + { pj_SOCK_DGRAM(), "udp", 2, 1}, + { pj_SOCK_DGRAM(), "udp", 2, 2}, + { pj_SOCK_DGRAM(), "udp", 2, 4}, + { pj_SOCK_DGRAM(), "udp", 2, 8}, + { pj_SOCK_DGRAM(), "udp", 4, 1}, + { pj_SOCK_DGRAM(), "udp", 4, 2}, + { pj_SOCK_DGRAM(), "udp", 4, 4}, + { pj_SOCK_DGRAM(), "udp", 4, 8}, + { pj_SOCK_DGRAM(), "udp", 4, 16}, + { pj_SOCK_STREAM(), "tcp", 1, 1}, + { pj_SOCK_STREAM(), "tcp", 1, 2}, + { pj_SOCK_STREAM(), "tcp", 1, 4}, + { pj_SOCK_STREAM(), "tcp", 1, 8}, + { pj_SOCK_STREAM(), "tcp", 2, 1}, + { pj_SOCK_STREAM(), "tcp", 2, 2}, + { pj_SOCK_STREAM(), "tcp", 2, 4}, + { pj_SOCK_STREAM(), "tcp", 2, 8}, + { pj_SOCK_STREAM(), "tcp", 4, 1}, + { pj_SOCK_STREAM(), "tcp", 4, 2}, + { pj_SOCK_STREAM(), "tcp", 4, 4}, + { pj_SOCK_STREAM(), "tcp", 4, 8}, + { pj_SOCK_STREAM(), "tcp", 4, 16}, /* - { PJ_SOCK_DGRAM, "udp", 32, 1}, - { PJ_SOCK_DGRAM, "udp", 32, 1}, - { PJ_SOCK_DGRAM, "udp", 32, 1}, - { PJ_SOCK_DGRAM, "udp", 32, 1}, - { PJ_SOCK_DGRAM, "udp", 1, 32}, - { PJ_SOCK_DGRAM, "udp", 1, 32}, - { PJ_SOCK_DGRAM, "udp", 1, 32}, - { PJ_SOCK_DGRAM, "udp", 1, 32}, - { PJ_SOCK_STREAM, "tcp", 32, 1}, - { PJ_SOCK_STREAM, "tcp", 32, 1}, - { PJ_SOCK_STREAM, "tcp", 32, 1}, - { PJ_SOCK_STREAM, "tcp", 32, 1}, - { PJ_SOCK_STREAM, "tcp", 1, 32}, - { PJ_SOCK_STREAM, "tcp", 1, 32}, - { PJ_SOCK_STREAM, "tcp", 1, 32}, - { PJ_SOCK_STREAM, "tcp", 1, 32}, + { pj_SOCK_DGRAM(), "udp", 32, 1}, + { pj_SOCK_DGRAM(), "udp", 32, 1}, + { pj_SOCK_DGRAM(), "udp", 32, 1}, + { pj_SOCK_DGRAM(), "udp", 32, 1}, + { pj_SOCK_DGRAM(), "udp", 1, 32}, + { pj_SOCK_DGRAM(), "udp", 1, 32}, + { pj_SOCK_DGRAM(), "udp", 1, 32}, + { pj_SOCK_DGRAM(), "udp", 1, 32}, + { pj_SOCK_STREAM(), "tcp", 32, 1}, + { pj_SOCK_STREAM(), "tcp", 32, 1}, + { pj_SOCK_STREAM(), "tcp", 32, 1}, + { pj_SOCK_STREAM(), "tcp", 32, 1}, + { pj_SOCK_STREAM(), "tcp", 1, 32}, + { pj_SOCK_STREAM(), "tcp", 1, 32}, + { pj_SOCK_STREAM(), "tcp", 1, 32}, + { pj_SOCK_STREAM(), "tcp", 1, 32}, */ }; pj_size_t best_bandwidth; diff --git a/pjlib/src/pjlib-test/ioq_tcp.c b/pjlib/src/pjlib-test/ioq_tcp.c index fc280de3..c6e117db 100644 --- a/pjlib/src/pjlib-test/ioq_tcp.c +++ b/pjlib/src/pjlib-test/ioq_tcp.c @@ -50,6 +50,7 @@ static pj_ssize_t callback_read_size, callback_write_size, callback_accept_status, callback_connect_status; +static unsigned callback_call_count; static pj_ioqueue_key_t *callback_read_key, *callback_write_key, *callback_accept_key, @@ -65,6 +66,7 @@ static void on_ioqueue_read(pj_ioqueue_key_t *key, callback_read_key = key; callback_read_op = op_key; callback_read_size = bytes_read; + callback_call_count++; } static void on_ioqueue_write(pj_ioqueue_key_t *key, @@ -74,6 +76,7 @@ static void on_ioqueue_write(pj_ioqueue_key_t *key, callback_write_key = key; callback_write_op = op_key; callback_write_size = bytes_written; + callback_call_count++; } static void on_ioqueue_accept(pj_ioqueue_key_t *key, @@ -96,6 +99,7 @@ static void on_ioqueue_accept(pj_ioqueue_key_t *key, callback_accept_key = key; callback_accept_op = op_key; callback_accept_status = status; + callback_call_count++; } } @@ -103,6 +107,7 @@ static void on_ioqueue_connect(pj_ioqueue_key_t *key, int status) { callback_connect_key = key; callback_connect_status = status; + callback_call_count++; } static pj_ioqueue_callback test_cb = @@ -168,7 +173,12 @@ static int send_recv_test(pj_ioqueue_t *ioque, status = 0; while (pending_op > 0) { timeout.sec = 1; timeout.msec = 0; +#ifdef PJ_SYMBIAN + PJ_UNUSED_ARG(ioque); + status = pj_symbianos_poll(-1, 1000); +#else status = pj_ioqueue_poll(ioque, &timeout); +#endif if (status > 0) { if (callback_read_size) { if (callback_read_size != bufsize) @@ -197,7 +207,11 @@ static int send_recv_test(pj_ioqueue_t *ioque, // Pending op is zero. // Subsequent poll should yield zero too. timeout.sec = timeout.msec = 0; +#ifdef PJ_SYMBIAN + status = pj_symbianos_poll(-1, 1); +#else status = pj_ioqueue_poll(ioque, &timeout); +#endif if (status != 0) return -173; @@ -226,7 +240,7 @@ static int compliance_test_0(void) pj_pool_t *pool = NULL; char *send_buf, *recv_buf; pj_ioqueue_t *ioque = NULL; - pj_ioqueue_key_t *skey, *ckey0, *ckey1; + pj_ioqueue_key_t *skey=NULL, *ckey0=NULL, *ckey1=NULL; pj_ioqueue_op_key_t accept_op; int bufsize = BUF_MIN_SIZE; pj_ssize_t status = -1; @@ -243,13 +257,13 @@ static int compliance_test_0(void) recv_buf = (char*)pj_pool_alloc(pool, bufsize); // Create server socket and client socket for connecting - rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0, &ssock); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &ssock); if (rc != PJ_SUCCESS) { app_perror("...error creating socket", rc); status=-1; goto on_error; } - rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0, &csock1); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &csock1); if (rc != PJ_SUCCESS) { app_perror("...error creating socket", rc); status=-1; goto on_error; @@ -321,6 +335,7 @@ static int compliance_test_0(void) // Poll until connected callback_read_size = callback_write_size = 0; callback_accept_status = callback_connect_status = -2; + callback_call_count = 0; callback_read_key = callback_write_key = callback_accept_key = callback_connect_key = NULL; @@ -329,7 +344,13 @@ static int compliance_test_0(void) while (pending_op) { pj_time_val timeout = {1, 0}; - status=pj_ioqueue_poll(ioque, &timeout); +#ifdef PJ_SYMBIAN + callback_call_count = 0; + pj_symbianos_poll(-1, 1000); + status = callback_call_count; +#else + status = pj_ioqueue_poll(ioque, &timeout); +#endif if (status > 0) { if (callback_accept_status != -2) { if (callback_accept_status != 0) { @@ -373,7 +394,11 @@ static int compliance_test_0(void) // When we poll the ioqueue, there must not be events. if (pending_op == 0) { pj_time_val timeout = {1, 0}; +#ifdef PJ_SYMBIAN + status = pj_symbianos_poll(-1, 1000); +#else status = pj_ioqueue_poll(ioque, &timeout); +#endif if (status != 0) { status=-60; goto on_error; } @@ -407,12 +432,21 @@ static int compliance_test_0(void) status = 0; on_error: - if (ssock != PJ_INVALID_SOCKET) + if (skey != NULL) + pj_ioqueue_unregister(skey); + else if (ssock != PJ_INVALID_SOCKET) pj_sock_close(ssock); - if (csock1 != PJ_INVALID_SOCKET) + + if (ckey1 != NULL) + pj_ioqueue_unregister(ckey1); + else if (csock1 != PJ_INVALID_SOCKET) pj_sock_close(csock1); - if (csock0 != PJ_INVALID_SOCKET) + + if (ckey0 != NULL) + pj_ioqueue_unregister(ckey0); + else if (csock0 != PJ_INVALID_SOCKET) pj_sock_close(csock0); + if (ioque != NULL) pj_ioqueue_destroy(ioque); pj_pool_release(pool); @@ -426,11 +460,11 @@ on_error: */ static int compliance_test_1(void) { - pj_sock_t csock1=-1; + pj_sock_t csock1=PJ_INVALID_SOCKET; pj_sockaddr_in addr; pj_pool_t *pool = NULL; pj_ioqueue_t *ioque = NULL; - pj_ioqueue_key_t *ckey1; + pj_ioqueue_key_t *ckey1 = NULL; pj_ssize_t status = -1; int pending_op = 0; pj_str_t s; @@ -446,7 +480,7 @@ static int compliance_test_1(void) } // Create client socket - rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0, &csock1); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &csock1); if (rc != PJ_SUCCESS) { app_perror("...ERROR in pj_sock_socket()", rc); status=-1; goto on_error; @@ -483,7 +517,13 @@ static int compliance_test_1(void) while (pending_op) { pj_time_val timeout = {1, 0}; - status=pj_ioqueue_poll(ioque, &timeout); +#ifdef PJ_SYMBIAN + callback_call_count = 0; + pj_symbianos_poll(-1, 1000); + status = callback_call_count; +#else + status = pj_ioqueue_poll(ioque, &timeout); +#endif if (status > 0) { if (callback_connect_key==ckey1) { if (callback_connect_status == 0) { @@ -512,7 +552,11 @@ static int compliance_test_1(void) // When we poll the ioqueue, there must not be events. if (pending_op == 0) { pj_time_val timeout = {1, 0}; +#ifdef PJ_SYMBIAN + status = pj_symbianos_poll(-1, 1000); +#else status = pj_ioqueue_poll(ioque, &timeout); +#endif if (status != 0) { status=-60; goto on_error; } @@ -522,8 +566,11 @@ static int compliance_test_1(void) status = 0; on_error: - if (csock1 != PJ_INVALID_SOCKET) + if (ckey1 != NULL) + pj_ioqueue_unregister(ckey1); + else if (csock1 != PJ_INVALID_SOCKET) pj_sock_close(csock1); + if (ioque != NULL) pj_ioqueue_destroy(ioque); pj_pool_release(pool); @@ -576,6 +623,19 @@ static int compliance_test_2(void) pj_str_t s; pj_status_t rc; + listener.sock = PJ_INVALID_SOCKET; + listener.key = NULL; + + for (i=0; i<MAX_PAIR; ++i) { + server[i].sock = PJ_INVALID_SOCKET; + server[i].key = NULL; + } + + for (i=0; i<MAX_PAIR; ++i) { + client[i].sock = PJ_INVALID_SOCKET; + client[i].key = NULL; + } + // Create pool. pool = pj_pool_create(mem, NULL, POOL_SIZE, 4000, NULL); @@ -593,7 +653,7 @@ static int compliance_test_2(void) recv_buf = (char*)pj_pool_alloc(pool, bufsize); // Create listener socket - rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0, &listener.sock); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &listener.sock); if (rc != PJ_SUCCESS) { app_perror("...error creating socket", rc); status=-20; goto on_error; @@ -635,7 +695,7 @@ static int compliance_test_2(void) for (test_loop=0; test_loop < TEST_LOOP; ++test_loop) { // Client connect and server accept. for (i=0; i<MAX_PAIR; ++i) { - rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, 0, &client[i].sock); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &client[i].sock); if (rc != PJ_SUCCESS) { app_perror("...error creating socket", rc); status=-70; goto on_error; @@ -683,7 +743,11 @@ static int compliance_test_2(void) while (pending_op) { pj_time_val timeout = {1, 0}; - status=pj_ioqueue_poll(ioque, &timeout); +#ifdef PJ_SYMBIAN + status = pj_symbianos_poll(-1, 1000); +#else + status = pj_ioqueue_poll(ioque, &timeout); +#endif if (status > 0) { if (status > pending_op) { PJ_LOG(3,(THIS_FILE, @@ -704,7 +768,11 @@ static int compliance_test_2(void) // When we poll the ioqueue, there must not be events. if (pending_op == 0) { pj_time_val timeout = {1, 0}; +#ifdef PJ_SYMBIAN + status = pj_symbianos_poll(-1, 1000); +#else status = pj_ioqueue_poll(ioque, &timeout); +#endif if (status != 0) { status=-120; goto on_error; } @@ -719,7 +787,7 @@ static int compliance_test_2(void) } // Check addresses - if (server[i].local_addr.sin_family != PJ_AF_INET || + if (server[i].local_addr.sin_family != pj_AF_INET() || server[i].local_addr.sin_addr.s_addr == 0 || server[i].local_addr.sin_port == 0) { @@ -728,7 +796,7 @@ static int compliance_test_2(void) goto on_error; } - if (server[i].rem_addr.sin_family != PJ_AF_INET || + if (server[i].rem_addr.sin_family != pj_AF_INET() || server[i].rem_addr.sin_addr.s_addr == 0 || server[i].rem_addr.sin_port == 0) { diff --git a/pjlib/src/pjlib-test/ioq_udp.c b/pjlib/src/pjlib-test/ioq_udp.c index e6f4c0f9..1bbe494f 100644 --- a/pjlib/src/pjlib-test/ioq_udp.c +++ b/pjlib/src/pjlib-test/ioq_udp.c @@ -133,7 +133,7 @@ static int compliance_test(void) pj_pool_t *pool = NULL; char *send_buf, *recv_buf; pj_ioqueue_t *ioque = NULL; - pj_ioqueue_key_t *skey, *ckey; + 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, status = -1; @@ -152,9 +152,9 @@ static int compliance_test(void) // Allocate sockets for sending and receiving. TRACE_("creating sockets..."); - rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &ssock); + 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); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &csock); else csock = PJ_INVALID_SOCKET; if (rc != PJ_SUCCESS) { @@ -165,7 +165,7 @@ static int compliance_test(void) // Bind server socket. TRACE_("bind socket..."); pj_bzero(&addr, sizeof(addr)); - addr.sin_family = PJ_AF_INET; + 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; @@ -258,7 +258,11 @@ static int compliance_test(void) pj_time_val timeout = { 5, 0 }; TRACE_("poll..."); +#ifdef PJ_SYMBIAN + rc = pj_symbianos_poll(-1, 5000); +#else rc = pj_ioqueue_poll(ioque, &timeout); +#endif if (rc == 0) { PJ_LOG(1,(THIS_FILE, "...ERROR: timed out...")); @@ -285,7 +289,7 @@ static int compliance_test(void) if (addrlen != sizeof(pj_sockaddr_in)) { status=-68; goto on_error; } - if (addr.sin_family != PJ_AF_INET) { + if (addr.sin_family != pj_AF_INET()) { status=-69; goto on_error; } @@ -312,10 +316,16 @@ static int compliance_test(void) status = 0; on_error: - if (ssock) + if (skey) + pj_ioqueue_unregister(skey); + else if (ssock != -1) pj_sock_close(ssock); - if (csock) + + if (ckey) + pj_ioqueue_unregister(ckey); + else if (csock != -1) pj_sock_close(csock); + if (ioque != NULL) pj_ioqueue_destroy(ioque); pj_pool_release(pool); @@ -372,14 +382,14 @@ static int unregister_test(void) } /* Create sender socket */ - status = app_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, SPORT, &ssock); + 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); + status = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, RPORT, &rsock); if (status != PJ_SUCCESS) { app_perror("Error initializing socket", status); return -130; @@ -435,7 +445,11 @@ static int unregister_test(void) /* Check if packet is received. */ timeout.sec = 1; timeout.msec = 0; +#ifdef PJ_SYMBIAN + pj_symbianos_poll(-1, 1000); +#else pj_ioqueue_poll(ioqueue, &timeout); +#endif if (packet_cnt != 1) { return -180; @@ -469,8 +483,12 @@ static int unregister_test(void) pj_ioqueue_unregister(key); /* Poll ioqueue. */ +#ifdef PJ_SYMBIAN + pj_symbianos_poll(-1, 1000); +#else timeout.sec = 1; timeout.msec = 0; pj_ioqueue_poll(ioqueue, &timeout); +#endif /* Must NOT receive any packets after socket is closed! */ if (packet_cnt > 0) { @@ -524,7 +542,7 @@ static int many_handles_test(void) /* 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]); + 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)); @@ -591,7 +609,7 @@ static int bench_test(int bufsize, int inactive_sock_count) pj_ioqueue_op_key_t *inactive_read_op; char *send_buf, *recv_buf; pj_ioqueue_t *ioque = NULL; - pj_ioqueue_key_t *skey, *ckey, *key; + 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; @@ -607,9 +625,9 @@ static int bench_test(int bufsize, int inactive_sock_count) 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); + 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); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &csock); } else csock = PJ_INVALID_SOCKET; if (rc != PJ_SUCCESS) { @@ -619,7 +637,7 @@ static int bench_test(int bufsize, int inactive_sock_count) // Bind server socket. pj_bzero(&addr, sizeof(addr)); - addr.sin_family = PJ_AF_INET; + addr.sin_family = pj_AF_INET(); addr.sin_port = pj_htons(PORT); if (pj_sock_bind(ssock, &addr, sizeof(addr))) goto on_error; @@ -640,11 +658,11 @@ static int bench_test(int bufsize, int inactive_sock_count) 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; + 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]); + 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; @@ -656,7 +674,7 @@ static int bench_test(int bufsize, int inactive_sock_count) goto on_error; } rc = pj_ioqueue_register_sock(pool, ioque, inactive_sock[i], - NULL, &test_cb, &key); + NULL, &test_cb, &keys[i]); if (rc != PJ_SUCCESS) { pj_sock_close(inactive_sock[i]); inactive_sock[i] = PJ_INVALID_SOCKET; @@ -665,7 +683,7 @@ static int bench_test(int bufsize, int inactive_sock_count) goto on_error; } bytes = bufsize; - rc = pj_ioqueue_recv(key, &inactive_read_op[i], recv_buf, &bytes, 0); + 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; @@ -735,7 +753,11 @@ static int bench_test(int bufsize, int inactive_sock_count) TRACE__((THIS_FILE, " waiting for key = %p", skey)); do { pj_time_val timeout = { 1, 0 }; +#ifdef PJ_SYMBIAN + rc = pj_symbianos_poll(-1, 1000); +#else rc = pj_ioqueue_poll(ioque, &timeout); +#endif TRACE__((THIS_FILE, " poll rc=%d", rc)); } while (rc >= 0 && callback_read_key != skey); @@ -760,7 +782,11 @@ static int bench_test(int bufsize, int inactive_sock_count) // Poll until all events are exhausted, before we start the next loop. do { pj_time_val timeout = { 0, 10 }; +#ifdef PJ_SYMBIAN + rc = pj_symbianos_poll(-1, 100); +#else rc = pj_ioqueue_poll(ioque, &timeout); +#endif } while (rc>0); rc = 0; @@ -784,11 +810,11 @@ static int bench_test(int bufsize, int inactive_sock_count) // Cleaning up. for (i=inactive_sock_count-1; i>=0; --i) { - pj_sock_close(inactive_sock[i]); + pj_ioqueue_unregister(keys[i]); } - pj_sock_close(ssock); - pj_sock_close(csock); + pj_ioqueue_unregister(skey); + pj_ioqueue_unregister(ckey); pj_ioqueue_destroy(ioque); diff --git a/pjlib/src/pjlib-test/ioq_unreg.c b/pjlib/src/pjlib-test/ioq_unreg.c index 791befc7..33e86270 100644 --- a/pjlib/src/pjlib-test/ioq_unreg.c +++ b/pjlib/src/pjlib-test/ioq_unreg.c @@ -159,7 +159,7 @@ static int perform_unreg_test(pj_ioqueue_t *ioqueue, * will return from the poll early. */ if (other_socket) { - status = app_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, 56127, &osd.sock); + status = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, 56127, &osd.sock); if (status != PJ_SUCCESS) { app_perror("Error creating other socket", status); return -12; @@ -200,7 +200,7 @@ static int perform_unreg_test(pj_ioqueue_t *ioqueue, } /* Create pair of client/server sockets */ - status = app_socketpair(PJ_AF_INET, PJ_SOCK_DGRAM, 0, + status = app_socketpair(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &sock_data.sock, &sock_data.csock); if (status != PJ_SUCCESS) { app_perror("app_socketpair error", status); diff --git a/pjlib/src/pjlib-test/main.c b/pjlib/src/pjlib-test/main.c index 2670ba7d..60dc319b 100644 --- a/pjlib/src/pjlib-test/main.c +++ b/pjlib/src/pjlib-test/main.c @@ -81,9 +81,9 @@ int main(int argc, char *argv[]) pj_str_t type = pj_str(argv[--argc]); if (pj_stricmp2(&type, "tcp")==0) - param_echo_sock_type = PJ_SOCK_STREAM; + param_echo_sock_type = pj_SOCK_STREAM(); else if (pj_stricmp2(&type, "udp")==0) - param_echo_sock_type = PJ_SOCK_DGRAM; + param_echo_sock_type = pj_SOCK_DGRAM(); else { PJ_LOG(3,("", "error: unknown socket type %s", type.ptr)); return 1; diff --git a/pjlib/src/pjlib-test/select.c b/pjlib/src/pjlib-test/select.c index 949d1463..c3c3f8fc 100644 --- a/pjlib/src/pjlib-test/select.c +++ b/pjlib/src/pjlib-test/select.c @@ -112,12 +112,12 @@ int select_test() PJ_LOG(3, (THIS_FILE, "...Testing simple UDP select()")); // Create two UDP sockets. - rc = pj_sock_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, &udp1); + rc = pj_sock_socket( pj_AF_INET(), pj_SOCK_DGRAM(), 0, &udp1); if (rc != PJ_SUCCESS) { app_perror("...error: unable to create socket", rc); status=-10; goto on_return; } - rc = pj_sock_socket( PJ_AF_INET, PJ_SOCK_DGRAM, 0, &udp2); + rc = pj_sock_socket( pj_AF_INET(), pj_SOCK_DGRAM(), 0, &udp2); if (udp2 == PJ_INVALID_SOCKET) { app_perror("...error: unable to create socket", rc); status=-20; goto on_return; @@ -125,7 +125,7 @@ int select_test() // Bind one of the UDP socket. pj_bzero(&udp_addr, sizeof(udp_addr)); - udp_addr.sin_family = PJ_AF_INET; + udp_addr.sin_family = pj_AF_INET(); udp_addr.sin_port = UDP_PORT; udp_addr.sin_addr = pj_inet_addr(pj_cstr(&s, "127.0.0.1")); diff --git a/pjlib/src/pjlib-test/sock.c b/pjlib/src/pjlib-test/sock.c index 9011a706..5e583e42 100644 --- a/pjlib/src/pjlib-test/sock.c +++ b/pjlib/src/pjlib-test/sock.c @@ -77,12 +77,7 @@ static int format_test(void) char zero[64]; pj_sockaddr_in addr2; const pj_str_t *hostname; -#if defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0 - /* Symbian IP address is saved in host order */ - unsigned char A[] = {1, 0, 0, 127}; -#else - unsigned char A[] = {127, 0, 0, 1}; -#endif + const unsigned char A[] = {127, 0, 0, 1}; PJ_LOG(3,("test", "...format_test()")); @@ -136,16 +131,16 @@ static int simple_sock_test(void) int i; pj_status_t rc = PJ_SUCCESS; - types[0] = PJ_SOCK_STREAM; - types[1] = PJ_SOCK_DGRAM; + types[0] = pj_SOCK_STREAM(); + types[1] = pj_SOCK_DGRAM(); PJ_LOG(3,("test", "...simple_sock_test()")); for (i=0; i<(int)(sizeof(types)/sizeof(types[0])); ++i) { - rc = pj_sock_socket(PJ_AF_INET, types[i], 0, &sock); + rc = pj_sock_socket(pj_AF_INET(), types[i], 0, &sock); if (rc != PJ_SUCCESS) { - app_perror("...error: unable to create socket type %d", rc); + app_perror("...error: unable to create socket", rc); break; } else { rc = pj_sock_close(sock); @@ -237,7 +232,7 @@ static int send_recv_test(int sock_type, rc = -156; goto on_error; } if (received != DATA_LEN-total_received) { - if (sock_type != PJ_SOCK_STREAM) { + if (sock_type != pj_SOCK_STREAM()) { PJ_LOG(3,("", "...error: expecting %u bytes, got %u bytes", DATA_LEN-total_received, received)); rc = -157; goto on_error; @@ -295,7 +290,7 @@ static int send_recv_test(int sock_type, rc = -173; goto on_error; } if (received != BIG_DATA_LEN-total_received) { - if (sock_type != PJ_SOCK_STREAM) { + if (sock_type != pj_SOCK_STREAM()) { PJ_LOG(3,("", "...error: expecting %u bytes, got %u bytes", BIG_DATA_LEN-total_received, received)); rc = -176; goto on_error; @@ -325,19 +320,19 @@ static int udp_test(void) PJ_LOG(3,("test", "...udp_test()")); - rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &ss); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &ss); if (rc != 0) { app_perror("...error: unable to create socket", rc); return -100; } - rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &cs); + rc = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &cs); if (rc != 0) return -110; /* Bind server socket. */ pj_bzero(&dstaddr, sizeof(dstaddr)); - dstaddr.sin_family = PJ_AF_INET; + dstaddr.sin_family = pj_AF_INET(); dstaddr.sin_port = pj_htons(UDP_PORT); dstaddr.sin_addr = pj_inet_addr(pj_cstr(&s, ADDRESS)); @@ -348,7 +343,7 @@ static int udp_test(void) /* Bind client socket. */ pj_bzero(&srcaddr, sizeof(srcaddr)); - srcaddr.sin_family = PJ_AF_INET; + srcaddr.sin_family = pj_AF_INET(); srcaddr.sin_port = pj_htons(UDP_PORT-1); srcaddr.sin_addr = pj_inet_addr(pj_cstr(&s, ADDRESS)); @@ -358,13 +353,13 @@ static int udp_test(void) } /* Test send/recv, with sendto */ - rc = send_recv_test(PJ_SOCK_DGRAM, ss, cs, &dstaddr, NULL, + rc = send_recv_test(pj_SOCK_DGRAM(), ss, cs, &dstaddr, NULL, sizeof(dstaddr)); if (rc != 0) goto on_error; /* Test send/recv, with sendto and recvfrom */ - rc = send_recv_test(PJ_SOCK_DGRAM, ss, cs, &dstaddr, + rc = send_recv_test(pj_SOCK_DGRAM(), ss, cs, &dstaddr, &srcaddr, sizeof(dstaddr)); if (rc != 0) goto on_error; @@ -382,12 +377,12 @@ static int udp_test(void) } /* Test send/recv with send() */ - rc = send_recv_test(PJ_SOCK_DGRAM, ss, cs, NULL, NULL, 0); + rc = send_recv_test(pj_SOCK_DGRAM(), ss, cs, NULL, NULL, 0); if (rc != 0) goto on_error; /* Test send/recv with send() and recvfrom */ - rc = send_recv_test(PJ_SOCK_DGRAM, ss, cs, NULL, &srcaddr, + rc = send_recv_test(pj_SOCK_DGRAM(), ss, cs, NULL, &srcaddr, sizeof(srcaddr)); if (rc != 0) goto on_error; @@ -420,14 +415,14 @@ static int tcp_test(void) PJ_LOG(3,("test", "...tcp_test()")); - rc = app_socketpair(PJ_AF_INET, PJ_SOCK_STREAM, 0, &ss, &cs); + rc = app_socketpair(pj_AF_INET(), pj_SOCK_STREAM(), 0, &ss, &cs); if (rc != PJ_SUCCESS) { app_perror("...error: app_socketpair():", rc); return -2000; } /* Test send/recv with send() and recv() */ - retval = send_recv_test(PJ_SOCK_STREAM, ss, cs, NULL, NULL, 0); + retval = send_recv_test(pj_SOCK_STREAM(), ss, cs, NULL, NULL, 0); rc = pj_sock_close(cs); if (rc != PJ_SUCCESS) { diff --git a/pjlib/src/pjlib-test/sock_perf.c b/pjlib/src/pjlib-test/sock_perf.c index a5420af7..41548ea6 100644 --- a/pjlib/src/pjlib-test/sock_perf.c +++ b/pjlib/src/pjlib-test/sock_perf.c @@ -62,7 +62,7 @@ static int sock_producer_consumer(int sock_type, return -10; /* Create producer-consumer pair. */ - rc = app_socketpair(PJ_AF_INET, sock_type, 0, &consumer, &producer); + rc = app_socketpair(pj_AF_INET(), sock_type, 0, &consumer, &producer); if (rc != PJ_SUCCESS) { app_perror("...error: create socket pair", rc); return -20; @@ -105,7 +105,7 @@ static int sock_producer_consumer(int sock_type, return -73; } if ((pj_size_t)part_received != buf_size-received) { - if (sock_type != PJ_SOCK_STREAM) { + if (sock_type != pj_SOCK_STREAM()) { PJ_LOG(3,("", "...error: expecting %u bytes, got %u bytes", buf_size-received, part_received)); return -76; @@ -165,13 +165,13 @@ int sock_perf_test(void) */ #if !defined(PJ_SYMBIAN) || PJ_SYMBIAN==0 /* Benchmarking UDP */ - rc = sock_producer_consumer(PJ_SOCK_DGRAM, 512, LOOP, &bandwidth); + rc = sock_producer_consumer(pj_SOCK_DGRAM(), 512, LOOP, &bandwidth); if (rc != 0) return rc; PJ_LOG(3,("", "....bandwidth UDP = %d KB/s", bandwidth)); #endif /* Benchmarking TCP */ - rc = sock_producer_consumer(PJ_SOCK_STREAM, 512, LOOP, &bandwidth); + rc = sock_producer_consumer(pj_SOCK_STREAM(), 512, LOOP, &bandwidth); if (rc != 0) return rc; PJ_LOG(3,("", "....bandwidth TCP = %d KB/s", bandwidth)); diff --git a/pjlib/src/pjlib-test/test.c b/pjlib/src/pjlib-test/test.c index 5c783970..0202a3da 100644 --- a/pjlib/src/pjlib-test/test.c +++ b/pjlib/src/pjlib-test/test.c @@ -64,7 +64,7 @@ int test_inner(void) } //pj_dump_config(); - pj_caching_pool_init( &caching_pool, &pj_pool_factory_default_policy, 0 ); + pj_caching_pool_init( &caching_pool, NULL, 0 ); #if INCLUDE_ERRNO_TEST DO_TEST( errno_test() ); @@ -165,7 +165,7 @@ int test_inner(void) #elif INCLUDE_ECHO_CLIENT if (param_echo_sock_type == 0) - param_echo_sock_type = PJ_SOCK_DGRAM; + param_echo_sock_type = pj_SOCK_DGRAM(); echo_client( param_echo_sock_type, param_echo_server, @@ -191,10 +191,15 @@ on_return: return 0; } +#include <pj/sock.h> + int test_main(void) { + int i; PJ_USE_EXCEPTION; + i = pj_AF_INET(); + PJ_TRY { return test_inner(); } diff --git a/pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c b/pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c index d2d2246a..231facc6 100644 --- a/pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c +++ b/pjlib/src/pjlib-test/udp_echo_srv_ioqueue.c @@ -176,7 +176,7 @@ int udp_echo_srv_ioqueue(void) return -20; } - rc = app_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, + 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); diff --git a/pjlib/src/pjlib-test/udp_echo_srv_sync.c b/pjlib/src/pjlib-test/udp_echo_srv_sync.c index 8c0ef2b7..37a9e04c 100644 --- a/pjlib/src/pjlib-test/udp_echo_srv_sync.c +++ b/pjlib/src/pjlib-test/udp_echo_srv_sync.c @@ -77,7 +77,7 @@ int echo_srv_sync(void) return -6; } - rc = app_socket(PJ_AF_INET, PJ_SOCK_DGRAM,0, ECHO_SERVER_START_PORT, &sock); + rc = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(),0, ECHO_SERVER_START_PORT, &sock); if (rc != PJ_SUCCESS) { app_perror("...socket error", rc); return -10; diff --git a/pjlib/src/pjlib-test/util.c b/pjlib/src/pjlib-test/util.c index a38c0764..4f68b25b 100644 --- a/pjlib/src/pjlib-test/util.c +++ b/pjlib/src/pjlib-test/util.c @@ -53,7 +53,7 @@ pj_status_t app_socket(int family, int type, int proto, int port, return rc; #if PJ_HAS_TCP - if (type == PJ_SOCK_STREAM) { + if (type == pj_SOCK_STREAM()) { rc = pj_sock_listen(sock, 5); if (rc != PJ_SUCCESS) return rc; @@ -86,7 +86,7 @@ pj_status_t app_socketpair(int family, int type, int protocol, /* Retry bind */ pj_bzero(&addr, sizeof(addr)); - addr.sin_family = PJ_AF_INET; + addr.sin_family = pj_AF_INET(); for (i=0; i<5; ++i) { addr.sin_port = pj_htons(port++); rc = pj_sock_bind(sock[SERVER], &addr, sizeof(addr)); @@ -99,7 +99,7 @@ pj_status_t app_socketpair(int family, int type, int protocol, /* For TCP, listen the socket. */ #if PJ_HAS_TCP - if (type == PJ_SOCK_STREAM) { + if (type == pj_SOCK_STREAM()) { rc = pj_sock_listen(sock[SERVER], PJ_SOMAXCONN); if (rc != PJ_SUCCESS) goto on_error; @@ -114,7 +114,7 @@ pj_status_t app_socketpair(int family, int type, int protocol, /* For TCP, must accept(), and get the new socket. */ #if PJ_HAS_TCP - if (type == PJ_SOCK_STREAM) { + if (type == pj_SOCK_STREAM()) { pj_sock_t newserver; rc = pj_sock_accept(sock[SERVER], &newserver, NULL, NULL); |