Ticket #354: build PJLIB as dynamic libraries (.DSO) in Symbian

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1405 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/addr_resolv_sock.c b/pjlib/src/pj/addr_resolv_sock.c
index 9e64378..408eae1 100644
--- a/pjlib/src/pj/addr_resolv_sock.c
+++ b/pjlib/src/pj/addr_resolv_sock.c
@@ -83,7 +83,7 @@
 	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 95da5cd..ea3c766 100644
--- a/pjlib/src/pj/addr_resolv_symbian.cpp
+++ b/pjlib/src/pj/addr_resolv_symbian.cpp
@@ -76,7 +76,7 @@
     // 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 @@
 
 
 /* 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_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 f7273a4..a11f3b4 100644
--- a/pjlib/src/pj/errno.c
+++ b/pjlib/src/pj/errno.c
@@ -101,7 +101,7 @@
 #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 08bf907..54a2375 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 @@
     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 @@
     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 @@
     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 @@
     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 6d340ce..1bdfef8 100644
--- a/pjlib/src/pj/file_io_ansi.c
+++ b/pjlib/src/pj/file_io_ansi.c
@@ -109,11 +109,13 @@
     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 8fd1be7..fdd1afe 100644
--- a/pjlib/src/pj/ioqueue_common_abs.c
+++ b/pjlib/src/pj/ioqueue_common_abs.c
@@ -100,10 +100,10 @@
      * 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 @@
         /* 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 @@
         /* 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 e200d64..48612d2 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 8d17878..3e8253e 100644
--- a/pjlib/src/pj/ioqueue_winnt.c
+++ b/pjlib/src/pj/ioqueue_winnt.c
@@ -1106,7 +1106,7 @@
      */
     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 518854c..59e8956 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_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 @@
 	(*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_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 a3ec3c0..f13365a 100644
--- a/pjlib/src/pj/os_core_symbian.cpp
+++ b/pjlib/src/pj/os_core_symbian.cpp
@@ -260,8 +260,6 @@
 }
 
 
-PJ_DECL(void) pj_shutdown(void);
-
 /*
  * pj_init(void).
  * Init PJLIB!
@@ -333,6 +331,94 @@
     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 a197787..abfa7f0 100644
--- a/pjlib/src/pj/os_symbian.h
+++ b/pjlib/src/pj/os_symbian.h
@@ -220,7 +220,7 @@
 			       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 5fffe94..331116b 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 @@
 /**
  * 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 01c303d..295d6b9 100644
--- a/pjlib/src/pj/pool_caching.c
+++ b/pjlib/src/pj/pool_caching.c
@@ -65,6 +65,10 @@
     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 439fa4c..7dc4044 100644
--- a/pjlib/src/pj/pool_policy_kmalloc.c
+++ b/pjlib/src/pj/pool_policy_kmalloc.c
@@ -56,3 +56,8 @@
     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 d7e8ad1..38db7fd 100644
--- a/pjlib/src/pj/pool_policy_malloc.c
+++ b/pjlib/src/pj/pool_policy_malloc.c
@@ -86,7 +86,7 @@
     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 @@
     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 82374ad..4277166 100644
--- a/pjlib/src/pj/pool_policy_new.cpp
+++ b/pjlib/src/pj/pool_policy_new.cpp
@@ -77,19 +77,19 @@
     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 0000000..4431f59
--- /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 3896091..7c7680a 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_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 @@
 
     /* 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 030d6fc..1581b4c 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 d13391e..4f7448b 100644
--- a/pjlib/src/pjlib-test/echo_clt.c
+++ b/pjlib/src/pjlib-test/echo_clt.c
@@ -65,7 +65,7 @@
     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 e15fe1b..92d4540 100644
--- a/pjlib/src/pjlib-test/ioq_perf.c
+++ b/pjlib/src/pjlib-test/ioq_perf.c
@@ -275,7 +275,7 @@
 
         /* 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         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 fc280de..c6e117d 100644
--- a/pjlib/src/pjlib-test/ioq_tcp.c
+++ b/pjlib/src/pjlib-test/ioq_tcp.c
@@ -50,6 +50,7 @@
                              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 @@
     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 @@
     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 @@
 	callback_accept_key = key;
 	callback_accept_op = op_key;
 	callback_accept_status = status;
+	callback_call_count++;
     }
 }
 
@@ -103,6 +107,7 @@
 {
     callback_connect_key = key;
     callback_connect_status = status;
+    callback_call_count++;
 }
 
 static pj_ioqueue_callback test_cb = 
@@ -168,7 +173,12 @@
     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 @@
     // 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 @@
     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 @@
     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 @@
     // 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 @@
     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 @@
     // 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 @@
     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 @@
  */
 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 @@
     }
 
     // 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 @@
     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 @@
     // 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 @@
     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 @@
     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 @@
     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 @@
     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 @@
 	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 @@
 	// 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 @@
 	    }
 
 	    // 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 @@
 		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 e6f4c0f..1bbe494 100644
--- a/pjlib/src/pjlib-test/ioq_udp.c
+++ b/pjlib/src/pjlib-test/ioq_udp.c
@@ -133,7 +133,7 @@
     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 @@
 
     // 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 @@
     // 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 @@
 	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 @@
 	    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 @@
     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 @@
     }
 
     /* 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 @@
 
     /* 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 @@
     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 @@
     /* 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 @@
     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 @@
     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 @@
 
     // 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 @@
     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 @@
 	    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 @@
 	    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 @@
 	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 @@
 	// 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 @@
 
     // 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 791befc..33e8627 100644
--- a/pjlib/src/pjlib-test/ioq_unreg.c
+++ b/pjlib/src/pjlib-test/ioq_unreg.c
@@ -159,7 +159,7 @@
      * 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 @@
     }
 
     /* 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 2670ba7..60dc319 100644
--- a/pjlib/src/pjlib-test/main.c
+++ b/pjlib/src/pjlib-test/main.c
@@ -81,9 +81,9 @@
             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 949d146..c3c3f8f 100644
--- a/pjlib/src/pjlib-test/select.c
+++ b/pjlib/src/pjlib-test/select.c
@@ -112,12 +112,12 @@
     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 @@
 
     // 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 9011a70..5e583e4 100644
--- a/pjlib/src/pjlib-test/sock.c
+++ b/pjlib/src/pjlib-test/sock.c
@@ -77,12 +77,7 @@
     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 @@
     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 @@
                 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 @@
             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 @@
 
     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 @@
 
     /* 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 @@
     }
 	    
     /* 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 @@
     }
 
     /* 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 @@
 
     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 a5420af..41548ea 100644
--- a/pjlib/src/pjlib-test/sock_perf.c
+++ b/pjlib/src/pjlib-test/sock_perf.c
@@ -62,7 +62,7 @@
         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 @@
                 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 @@
      */    
 #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 5c78397..0202a3d 100644
--- a/pjlib/src/pjlib-test/test.c
+++ b/pjlib/src/pjlib-test/test.c
@@ -64,7 +64,7 @@
     }
     
     //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 @@
 
 #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 @@
     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 d2d2246..231facc 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 @@
         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 8c0ef2b..37a9e04 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 @@
         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 a38c076..4f68b25 100644
--- a/pjlib/src/pjlib-test/util.c
+++ b/pjlib/src/pjlib-test/util.c
@@ -53,7 +53,7 @@
         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 @@
 
     /* 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 @@
 
     /* 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 @@
 
     /* 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);