Index: pjproject/trunk/pjlib/include/pj/activesock.h
===================================================================
--- pjproject/trunk/pjlib/include/pj/activesock.h	(revision 2186)
+++ pjproject/trunk/pjlib/include/pj/activesock.h	(revision 2187)
@@ -357,4 +357,24 @@
 
 /**
+ * Same as #pj_activesock_start_read(), except that the application
+ * supplies the buffers for the read operation so that the acive socket
+ * does not have to allocate the buffers.
+ *
+ * @param asock	    The active socket.
+ * @param pool	    Pool used to allocate buffers for incoming data.
+ * @param buff_size The size of each buffer, in bytes.
+ * @param readbuf   Array of packet buffers, each has buff_size size.
+ * @param flags	    Flags to be given to pj_ioqueue_recv().
+ *
+ * @return	    PJ_SUCCESS if the operation has been successful,
+ *		    or the appropriate error code on failure.
+ */
+PJ_DECL(pj_status_t) pj_activesock_start_read2(pj_activesock_t *asock,
+					       pj_pool_t *pool,
+					       unsigned buff_size,
+					       void *readbuf[],
+					       pj_uint32_t flags);
+
+/**
  * Same as pj_activesock_start_read(), except that this function is used
  * only for datagram sockets, and it will trigger \a on_data_recvfrom()
@@ -373,4 +393,24 @@
 						  unsigned buff_size,
 						  pj_uint32_t flags);
+
+/**
+ * Same as #pj_activesock_start_recvfrom() except that the recvfrom() 
+ * operation takes the buffer from the argument rather than creating
+ * new ones.
+ *
+ * @param asock	    The active socket.
+ * @param pool	    Pool used to allocate buffers for incoming data.
+ * @param buff_size The size of each buffer, in bytes.
+ * @param readbuf   Array of packet buffers, each has buff_size size.
+ * @param flags	    Flags to be given to pj_ioqueue_recvfrom().
+ *
+ * @return	    PJ_SUCCESS if the operation has been successful,
+ *		    or the appropriate error code on failure.
+ */
+PJ_DECL(pj_status_t) pj_activesock_start_recvfrom2(pj_activesock_t *asock,
+						   pj_pool_t *pool,
+						   unsigned buff_size,
+						   void *readbuf[],
+						   pj_uint32_t flags);
 
 /**
Index: pjproject/trunk/pjlib/src/pj/activesock.c
===================================================================
--- pjproject/trunk/pjlib/src/pj/activesock.c	(revision 2186)
+++ pjproject/trunk/pjlib/src/pj/activesock.c	(revision 2187)
@@ -18,4 +18,5 @@
  */
 #include <pj/activesock.h>
+#include <pj/compat/socket.h>
 #include <pj/assert.h>
 #include <pj/errno.h>
@@ -242,4 +243,26 @@
 					     pj_uint32_t flags)
 {
+    void **readbuf;
+    unsigned i;
+
+    PJ_ASSERT_RETURN(asock && pool && buff_size, PJ_EINVAL);
+
+    readbuf = (void**) pj_pool_calloc(pool, asock->async_count, 
+				      sizeof(void*));
+
+    for (i=0; i<asock->async_count; ++i) {
+	readbuf[i] = pj_pool_alloc(pool, buff_size);
+    }
+
+    return pj_activesock_start_read2(asock, pool, buff_size, readbuf, flags);
+}
+
+
+PJ_DEF(pj_status_t) pj_activesock_start_read2( pj_activesock_t *asock,
+					       pj_pool_t *pool,
+					       unsigned buff_size,
+					       void *readbuf[],
+					       pj_uint32_t flags)
+{
     unsigned i;
     pj_status_t status;
@@ -259,5 +282,5 @@
 	pj_ssize_t size_to_read;
 
-	r->pkt = (pj_uint8_t*)pj_pool_alloc(pool, buff_size);
+	r->pkt = (pj_uint8_t*)readbuf[i];
 	r->max_size = size_to_read = buff_size;
 
@@ -278,4 +301,27 @@
 						 unsigned buff_size,
 						 pj_uint32_t flags)
+{
+    void **readbuf;
+    unsigned i;
+
+    PJ_ASSERT_RETURN(asock && pool && buff_size, PJ_EINVAL);
+
+    readbuf = (void**) pj_pool_calloc(pool, asock->async_count, 
+				      sizeof(void*));
+
+    for (i=0; i<asock->async_count; ++i) {
+	readbuf[i] = pj_pool_alloc(pool, buff_size);
+    }
+
+    return pj_activesock_start_recvfrom2(asock, pool, buff_size, 
+					 readbuf, flags);
+}
+
+
+PJ_DEF(pj_status_t) pj_activesock_start_recvfrom2( pj_activesock_t *asock,
+						   pj_pool_t *pool,
+						   unsigned buff_size,
+						   void *readbuf[],
+						   pj_uint32_t flags)
 {
     unsigned i;
@@ -295,5 +341,5 @@
 	pj_ssize_t size_to_read;
 
-	r->pkt = (pj_uint8_t*) pj_pool_alloc(pool, buff_size);
+	r->pkt = (pj_uint8_t*) readbuf[i];
 	r->max_size = size_to_read = buff_size;
 	r->src_addr_len = sizeof(r->src_addr);
@@ -372,6 +418,9 @@
 	    }
 
-	} else if (bytes_read <= 0) {
-
+	} else if (bytes_read <= 0 &&
+		   -bytes_read != PJ_STATUS_FROM_OS(OSERR_EWOULDBLOCK) &&
+		   -bytes_read != PJ_STATUS_FROM_OS(OSERR_EINPROGRESS) && 
+		   -bytes_read != PJ_STATUS_FROM_OS(OSERR_ECONNRESET)) 
+	{
 	    pj_size_t remainder;
 	    pj_bool_t ret;
