Fix #1157: Fixed Symbian SSL socket to re-align the write (circular) buffer only when all pending write requests are completed, i.e: inside the write completion callback and when the buffer is empty.



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@3364 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/ssl_sock_symbian.cpp b/pjlib/src/pj/ssl_sock_symbian.cpp
index 9237ef1..9027350 100644
--- a/pjlib/src/pj/ssl_sock_symbian.cpp
+++ b/pjlib/src/pj/ssl_sock_symbian.cpp
@@ -1020,6 +1020,9 @@
 	    st->len = 0;
 	    return;
 	}
+    } else {
+        /* Buffer empty, reset the start position */
+        st->start = st->buf;
     }
 }
 
@@ -1058,25 +1061,16 @@
      * operations at any time.
      */
     
-    pj_size_t avail_len = st->max_len - st->len;
     pj_size_t needed_len = *size + sizeof(write_data_t) - 1;
     
     /* Align needed_len to be multiplication of 4 */
     needed_len = ((needed_len + 3) >> 2) << 2; 
 
-    /* Block until there is buffer slot available! */
-    while (needed_len >= avail_len) {
+    /* Block until there is buffer slot available and contiguous! */
+    while (st->start + st->len + needed_len > st->buf + st->max_len) {
 	pj_symbianos_poll(-1, -1);
-	avail_len = st->max_len - st->len;
     }
 
-    /* Ok, make sure the new data will not get wrapped */
-    if (st->start + st->len + needed_len > st->buf + st->max_len) {
-	/* Align buffer left */
-	pj_memmove(st->buf, st->start, st->len);
-	st->start = st->buf;
-    }
-    
     /* Push back the send data into the buffer */
     write_data_t *wdata = (write_data_t*)(st->start + st->len);