Misc Symbian fixes, looks good

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1248 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjlib/src/pj/ioqueue_symbian.cpp b/pjlib/src/pj/ioqueue_symbian.cpp
index 6768cc0..73f0f04 100644
--- a/pjlib/src/pj/ioqueue_symbian.cpp
+++ b/pjlib/src/pj/ioqueue_symbian.cpp
@@ -648,6 +648,10 @@
 				     pj_ssize_t *length,
 				     pj_uint32_t flags )
 {
+    // If socket has reader, delete it.
+    if (key->cbObj->get_pj_socket()->Reader())
+    	key->cbObj->get_pj_socket()->DestroyReader();
+    
     // Clear flag
     flags &= ~PJ_IOQUEUE_ALWAYS_ASYNC;
     return key->cbObj->StartRead(op_key, buffer, length, flags, NULL, NULL);
@@ -667,6 +671,10 @@
 					 pj_sockaddr_t *addr,
 					 int *addrlen)
 {
+    // If socket has reader, delete it.
+    if (key->cbObj->get_pj_socket()->Reader())
+    	key->cbObj->get_pj_socket()->DestroyReader();
+    
     if (key->cbObj->IsActive())
 	return PJ_EBUSY;
 
diff --git a/pjlib/src/pj/os_core_symbian.cpp b/pjlib/src/pj/os_core_symbian.cpp
index a55b548..742fe5a 100644
--- a/pjlib/src/pj/os_core_symbian.cpp
+++ b/pjlib/src/pj/os_core_symbian.cpp
@@ -421,6 +421,11 @@
 PJ_DEF(pj_status_t) pj_thread_sleep(unsigned msec)
 {
     User::After(msec*1000);
+    
+    TInt aError;
+    while (CActiveScheduler::RunIfReady(aError, EPriorityMuchLess))
+    	;
+    
     return PJ_SUCCESS;
 }
 
diff --git a/pjlib/src/pj/os_symbian.h b/pjlib/src/pj/os_symbian.h
index 929070b..a197787 100644
--- a/pjlib/src/pj/os_symbian.h
+++ b/pjlib/src/pj/os_symbian.h
@@ -86,6 +86,9 @@
     // Create socket reader.
     CPjSocketReader *CreateReader(unsigned max_len=CPjSocket::MAX_LEN);
 
+    // Delete socket reader when it's not wanted.
+    void DestroyReader();
+    
 private:
     RSocket	     sock_;	    // Must not be reference, or otherwise
 				    // it may point to local variable!
@@ -187,11 +190,6 @@
 {
 public:
     //
-    // Construct PjSymbianOS instance.
-    //
-    static PjSymbianOS *NewL();
-
-    //
     // Get the singleton instance of PjSymbianOS
     //
     static PjSymbianOS *Instance();
diff --git a/pjlib/src/pj/sock_symbian.cpp b/pjlib/src/pj/sock_symbian.cpp
index 8d2ab07..ae691ba 100644
--- a/pjlib/src/pj/sock_symbian.cpp
+++ b/pjlib/src/pj/sock_symbian.cpp
@@ -66,12 +66,7 @@
 
 CPjSocket::~CPjSocket()
 {
-    if (sockReader_) {
-	if (sockReader_->IsActive())
-	    sockReader_->Cancel();
-	delete sockReader_;
-	sockReader_ = NULL;
-    }
+    DestroyReader();
     sock_.Close();
 }
 
@@ -83,6 +78,17 @@
     return sockReader_ = CPjSocketReader::NewL(*this, max_len);
 }
 
+// Delete socket reader when it's not wanted.
+void CPjSocket::DestroyReader() 
+{
+    if (sockReader_) {
+	if (sockReader_->IsActive())
+	    sockReader_->Cancel();
+	delete sockReader_;
+	sockReader_ = NULL;
+    }
+}
+
 
 /////////////////////////////////////////////////////////////////////////////
 //
@@ -163,7 +169,6 @@
 {
     void (*old_cb)(void *key) = readCb_;
     void *old_key = key_;
-    bool is_active = IsActive();
 
     readCb_ = NULL;
     key_ = NULL;
diff --git a/pjlib/src/pj/timer_symbian.cpp b/pjlib/src/pj/timer_symbian.cpp
index 398f772..eaf4f9e 100644
--- a/pjlib/src/pj/timer_symbian.cpp
+++ b/pjlib/src/pj/timer_symbian.cpp
@@ -88,7 +88,11 @@
     rtimer_.CreateLocal();
     CActiveScheduler::Add(this);
     
-    rtimer_.After(iStatus, PJ_TIME_VAL_MSEC(*delay) * 1000);
+    pj_int32_t interval = PJ_TIME_VAL_MSEC(*delay) * 1000;
+    if (interval < 0) {
+    	interval = 0;
+    }
+    rtimer_.After(iStatus, interval);
     SetActive();
 }