Daniele Lacamera / PicoTCP-Experimental_CDC_ECM_Branch

Fork of PicoTCP by Daniele Lacamera

Files at this revision

API Documentation at this revision

Comitter:
tass
Date:
Thu Jun 06 11:40:20 2013 +0000
Parent:
14:fe225a6f92c0
Commit message:
updated picotcp_select

Changed in this revision

Socket/TCPSocketConnection.cpp Show annotated file Show diff for this revision Revisions of this file
Socket/pico_bsd_layer.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Socket/TCPSocketConnection.cpp	Thu Jun 06 09:27:28 2013 +0000
+++ b/Socket/TCPSocketConnection.cpp	Thu Jun 06 11:40:20 2013 +0000
@@ -71,7 +71,6 @@
         TimeInterval timeout(_timeout);
         if (wait_writable(timeout) != 0)
         {
-            printf("Failed\n");
             return -1;
         }
     }
@@ -118,14 +117,13 @@
         TimeInterval timeout(_timeout);
         if (wait_readable(timeout) != 0)
         {
-            printf("Failed receiving\n");
             return -1;
         }
     }
-    
+
     int n = picotcp_read(_sock_fd, data, length);
     _is_connected = (picotcp_state(_sock_fd) == SOCK_CONNECTED);
-    
+
     return n;
 }
 
--- a/Socket/pico_bsd_layer.cpp	Thu Jun 06 09:27:28 2013 +0000
+++ b/Socket/pico_bsd_layer.cpp	Thu Jun 06 11:40:20 2013 +0000
@@ -98,7 +98,9 @@
         {
             SET_EVENT(sock->event, event);
             //printf("Locked...\n");
+            
             sock->mutex->lock();
+            
             RESET_EVENT(sock->event,event);
     
             if(! EVENT_PENDING(sock->revent,event) || EVENT_PENDING(sock->revent, PICO_SOCK_EV_ERR) || 
@@ -120,7 +122,10 @@
     if(!_sock)
     {
         if( (ev & PICO_SOCK_EV_ERR) || (ev & PICO_SOCK_EV_CLOSE) || (ev & PICO_SOCK_EV_FIN) )
+        {
+            printf("Ghost socket : %d\n",ev);
             pico_socket_close(sock);
+        }
         return;
     }
 
@@ -136,18 +141,15 @@
     }
     else
     {
-        printf("Unexpected event\n");
+        //printf("Unexpected event \n");
         // give semaphore back when -1 occurs or close requested
-        if( (ev & PICO_SOCK_EV_ERR) || (ev & PICO_SOCK_EV_CLOSE) || (ev & PICO_SOCK_EV_FIN) )
+        if( (ev & PICO_SOCK_EV_ERR) || (ev & PICO_SOCK_EV_CLOSE))
         {
-            printf("Exception\n");
+            printf("Exception %d\n",ev);
             
             _sock->state = SOCK_CLOSED;
-            if(_sock->state != SOCK_CLOSED)
-            {
-                pico_socket_close(_sock->sock);
+            pico_socket_close(_sock->sock);
                 //_sock->sock = NULL;
-            }
             _sock->mutex->unlock();
             globalLock.lock();
         }
@@ -346,7 +348,7 @@
     pico_free(_sock);
     
     
-    globalLock.unlock();
+   globalLock.unlock();
     return ret;
 }
 
@@ -495,21 +497,12 @@
     VALIDATE_NULL(_sock);
     
     // tell the dispatcher what events are you waiting for
-    if(read)
-        SET_EVENT(_sock->event,PICO_SOCK_EV_RD|PICO_SOCK_EV_CONN);
-    if(write)
-        SET_EVENT(_sock->event,PICO_SOCK_EV_WR);
-        
+    
     while (PICO_TIME_MS() < now + ms) {
         
-        if (_sock->mutex->lock(1) == false) {
-            //Thread::wait(1);
-            continue;
-        }
-             
-        if (read && EVENT_PENDING(_sock->revent,PICO_SOCK_EV_RD|PICO_SOCK_EV_CONN))
+        if (read && EVENT_PENDING(_sock->revent,PICO_SOCK_EV_RD))
         {
-            RESET_EVENT(_sock->revent,PICO_SOCK_EV_CONN|PICO_SOCK_EV_RD);
+            RESET_EVENT(_sock->revent,PICO_SOCK_EV_RD);
             ret++;
         }
         if (write && EVENT_PENDING(_sock->revent, PICO_SOCK_EV_WR))
@@ -520,15 +513,9 @@
         if (ret > 0)
             break;
         
-        
+        Thread::wait(1);
     }
     
-    if(read)
-        RESET_EVENT(_sock->event,PICO_SOCK_EV_CONN|PICO_SOCK_EV_RD);
-    if(write)
-        RESET_EVENT(_sock->event,PICO_SOCK_EV_WR);
-
-    
     return ret;
 }