Index: pjproject/main/pjlib/src/pjlib-test/ioq_udp.c
===================================================================
--- pjproject/main/pjlib/src/pjlib-test/ioq_udp.c	(revision 6)
+++ pjproject/main/pjlib/src/pjlib-test/ioq_udp.c	(revision 11)
@@ -35,29 +35,41 @@
 #define TRACE_(msg)	    PJ_LOG(3,(THIS_FILE,"....." msg))
 
-static pj_ssize_t callback_read_size,
-                  callback_write_size,
-                  callback_accept_status,
-                  callback_connect_status;
-static pj_ioqueue_key_t *callback_read_key,
-                        *callback_write_key,
-                        *callback_accept_key,
-                        *callback_connect_key;
-
-static void on_ioqueue_read(pj_ioqueue_key_t *key, pj_ssize_t bytes_read)
+static pj_ssize_t            callback_read_size,
+                             callback_write_size,
+                             callback_accept_status,
+                             callback_connect_status;
+static pj_ioqueue_key_t     *callback_read_key,
+                            *callback_write_key,
+                            *callback_accept_key,
+                            *callback_connect_key;
+static pj_ioqueue_op_key_t  *callback_read_op,
+                            *callback_write_op,
+                            *callback_accept_op;
+
+static void on_ioqueue_read(pj_ioqueue_key_t *key, 
+                            pj_ioqueue_op_key_t *op_key,
+                            pj_ssize_t bytes_read)
 {
     callback_read_key = key;
+    callback_read_op = op_key;
     callback_read_size = bytes_read;
 }
 
-static void on_ioqueue_write(pj_ioqueue_key_t *key, pj_ssize_t bytes_written)
+static void on_ioqueue_write(pj_ioqueue_key_t *key, 
+                             pj_ioqueue_op_key_t *op_key,
+                             pj_ssize_t bytes_written)
 {
     callback_write_key = key;
+    callback_write_op = op_key;
     callback_write_size = bytes_written;
 }
 
-static void on_ioqueue_accept(pj_ioqueue_key_t *key, pj_sock_t sock, int status)
+static void on_ioqueue_accept(pj_ioqueue_key_t *key, 
+                              pj_ioqueue_op_key_t *op_key,
+                              pj_sock_t sock, int status)
 {
     PJ_UNUSED_ARG(sock);
     callback_accept_key = key;
+    callback_accept_op = op_key;
     callback_accept_status = status;
 }
@@ -82,27 +94,4 @@
 #  define S_ADDR s_addr
 #endif
-
-/*
- * native_format_test()
- * This is just a simple test to verify that various structures in sock.h
- * are really compatible with operating system's definitions.
- */
-static int native_format_test(void)
-{
-    pj_status_t rc;
-
-    // Test that PJ_INVALID_SOCKET is working.
-    {
-	pj_sock_t sock;
-	rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_STREAM, -1, &sock);
-	if (rc == PJ_SUCCESS)
-	    return -1020;
-    }
-
-    // Previous func will set errno var.
-    pj_set_os_error(PJ_SUCCESS);
-
-    return 0;
-}
 
 /*
@@ -120,4 +109,5 @@
     pj_ioqueue_t *ioque = NULL;
     pj_ioqueue_key_t *skey, *ckey;
+    pj_ioqueue_op_key_t read_op, write_op;
     int bufsize = BUF_MIN_SIZE;
     pj_ssize_t bytes, status = -1;
@@ -158,6 +148,5 @@
     // Create I/O Queue.
     TRACE_("create ioqueue...");
-    rc = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, 
-			   PJ_IOQUEUE_DEFAULT_THREADS, &ioque);
+    rc = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, &ioque);
     if (rc != PJ_SUCCESS) {
 	status=-20; goto on_error;
@@ -196,9 +185,11 @@
     TRACE_("start recvfrom...");
     addrlen = sizeof(addr);
-    bytes = pj_ioqueue_recvfrom(ioque, skey, recv_buf, bufsize, 0,
-			        &addr, &addrlen);
-    if (bytes < 0 && bytes != PJ_EPENDING) {
+    bytes = bufsize;
+    rc = pj_ioqueue_recvfrom(skey, &read_op, recv_buf, &bytes, 0,
+			     &addr, &addrlen);
+    if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
+        app_perror("...error: pj_ioqueue_recvfrom", rc);
 	status=-28; goto on_error;
-    } else if (bytes == PJ_EPENDING) {
+    } else if (rc == PJ_EPENDING) {
 	recv_pending = 1;
 	PJ_LOG(3, (THIS_FILE, 
@@ -212,11 +203,11 @@
     // Write must return the number of bytes.
     TRACE_("start sendto...");
-    bytes = pj_ioqueue_sendto(ioque, ckey, send_buf, bufsize, 0, &addr, 
-			      sizeof(addr));
-    if (bytes != bufsize && bytes != PJ_EPENDING) {
-	PJ_LOG(1,(THIS_FILE, 
-		  "......error: sendto returned %d", bytes));
+    bytes = bufsize;
+    rc = pj_ioqueue_sendto(ckey, &write_op, send_buf, &bytes, 0, &addr, 
+			   sizeof(addr));
+    if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
+        app_perror("...error: pj_ioqueue_sendto", rc);
 	status=-30; goto on_error;
-    } else if (bytes == PJ_EPENDING) {
+    } else if (rc == PJ_EPENDING) {
 	send_pending = 1;
 	PJ_LOG(3, (THIS_FILE, 
@@ -233,7 +224,8 @@
     callback_read_key = callback_write_key = 
         callback_accept_key = callback_connect_key = NULL;
+    callback_read_op = callback_write_op = NULL;
 
     // Poll if pending.
-    while (send_pending && recv_pending) {
+    while (send_pending || recv_pending) {
 	int rc;
 	pj_time_val timeout = { 5, 0 };
@@ -254,7 +246,9 @@
                 status=-61; goto on_error;
             }
-
             if (callback_read_key != skey) {
                 status=-65; goto on_error;
+            }
+            if (callback_read_op != &read_op) {
+                status=-66; goto on_error;
             }
 
@@ -271,7 +265,9 @@
                 status=-73; goto on_error;
             }
-
             if (callback_write_key != ckey) {
                 status=-75; goto on_error;
+            }
+            if (callback_write_op != &write_op) {
+                status=-76; goto on_error;
             }
 
@@ -327,7 +323,5 @@
     
     /* Create IOQueue */
-    rc = pj_ioqueue_create(pool, MAX,
-			   PJ_IOQUEUE_DEFAULT_THREADS,
-			   &ioqueue);
+    rc = pj_ioqueue_create(pool, MAX, &ioqueue);
     if (rc != PJ_SUCCESS || ioqueue == NULL) {
 	app_perror("...error in pj_ioqueue_create", rc);
@@ -359,5 +353,5 @@
 
     for (i=0; i<count; ++i) {
-	rc = pj_ioqueue_unregister(ioqueue, key[i]);
+	rc = pj_ioqueue_unregister(key[i]);
 	if (rc != PJ_SUCCESS) {
 	    app_perror("...error in pj_ioqueue_unregister", rc);
@@ -394,4 +388,5 @@
     pj_pool_t *pool = NULL;
     pj_sock_t *inactive_sock=NULL;
+    pj_ioqueue_op_key_t *inactive_read_op;
     char *send_buf, *recv_buf;
     pj_ioqueue_t *ioque = NULL;
@@ -430,6 +425,5 @@
 
     // Create I/O Queue.
-    rc = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, 
-			   PJ_IOQUEUE_DEFAULT_THREADS, &ioque);
+    rc = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, &ioque);
     if (rc != PJ_SUCCESS) {
 	app_perror("...error: pj_ioqueue_create()", rc);
@@ -441,7 +435,11 @@
     inactive_sock = (pj_sock_t*)pj_pool_alloc(pool, 
 				    inactive_sock_count*sizeof(pj_sock_t));
+    inactive_read_op = (pj_ioqueue_op_key_t*)pj_pool_alloc(pool,
+                              inactive_sock_count*sizeof(pj_ioqueue_op_key_t));
     memset(&addr, 0, sizeof(addr));
     addr.sin_family = PJ_AF_INET;
     for (i=0; i<inactive_sock_count; ++i) {
+        pj_ssize_t bytes;
+
 	rc = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &inactive_sock[i]);
 	if (rc != PJ_SUCCESS || inactive_sock[i] < 0) {
@@ -464,5 +462,6 @@
 	    goto on_error;
 	}
-	rc = pj_ioqueue_read(ioque, key, recv_buf, bufsize);
+        bytes = bufsize;
+	rc = pj_ioqueue_recv(key, &inactive_read_op[i], recv_buf, &bytes, 0);
 	if ( rc < 0 && rc != PJ_EPENDING) {
 	    pj_sock_close(inactive_sock[i]);
@@ -497,4 +496,5 @@
     for (i=0; i<LOOP; ++i) {
 	pj_ssize_t bytes;
+        pj_ioqueue_op_key_t read_op, write_op;
 
 	// Randomize send buffer.
@@ -502,5 +502,6 @@
 
 	// Start reading on the server side.
-	rc = pj_ioqueue_read(ioque, skey, recv_buf, bufsize);
+        bytes = bufsize;
+	rc = pj_ioqueue_recv(skey, &read_op, recv_buf, &bytes, 0);
 	if (rc < 0 && rc != PJ_EPENDING) {
 	    app_perror("...error: pj_ioqueue_read()", rc);
@@ -509,7 +510,8 @@
 
 	// Starts send on the client side.
-	bytes = pj_ioqueue_sendto(ioque, ckey, send_buf, bufsize, 0,
-					&addr, sizeof(addr));
-	if (bytes != bufsize && bytes != PJ_EPENDING) {
+        bytes = bufsize;
+	rc = pj_ioqueue_sendto(ckey, &write_op, send_buf, &bytes, 0,
+			       &addr, sizeof(addr));
+	if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
 	    app_perror("...error: pj_ioqueue_write()", bytes);
 	    rc = -1;
@@ -600,9 +602,4 @@
     int bufsize, sock_count;
 
-    PJ_LOG(3, (THIS_FILE, "...format test"));
-    if ((status = native_format_test()) != 0)
-	return status;
-    PJ_LOG(3, (THIS_FILE, "....native format test ok"));
-
     PJ_LOG(3, (THIS_FILE, "...compliance test"));
     if ((status=compliance_test()) != 0) {
