Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PicoTCP by
Diff: Socket/pico_bsd_layer.cpp
- Revision:
- 15:129f20ca4d7d
- Parent:
- 14:fe225a6f92c0
diff -r fe225a6f92c0 -r 129f20ca4d7d Socket/pico_bsd_layer.cpp
--- 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;
}
