NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

Files at this revision

API Documentation at this revision

Comitter:
Christopher Haster
Date:
Wed Apr 20 20:38:00 2016 -0500
Parent:
117:ff83eb6a1ab9
Child:
119:4f8b720d512a
Child:
120:6eb542426f15
Commit message:
Fix for timeout issue with WFI

Changed in this revision

Socket.cpp Show annotated file Show diff for this revision Revisions of this file
Socket.h Show annotated file Show diff for this revision Revisions of this file
TCPServer.cpp Show annotated file Show diff for this revision Revisions of this file
TCPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
UDPSocket.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Socket.cpp	Wed Apr 20 19:48:17 2016 -0500
+++ b/Socket.cpp	Wed Apr 20 20:38:00 2016 -0500
@@ -109,6 +109,10 @@
 
 }
 
+void Socket::wakeup()
+{
+}
+
 void Socket::thunk(void *data)
 {
     Socket *self = (Socket *)data;
--- a/Socket.h	Wed Apr 20 19:48:17 2016 -0500
+++ b/Socket.h	Wed Apr 20 20:38:00 2016 -0500
@@ -169,6 +169,7 @@
     int open(NetworkStack *iface, nsapi_protocol_t proto);
 
     static void thunk(void *);
+    static void wakeup();
 
     NetworkStack *_iface;
     void *_socket;
--- a/TCPServer.cpp	Wed Apr 20 19:48:17 2016 -0500
+++ b/TCPServer.cpp	Wed Apr 20 20:38:00 2016 -0500
@@ -44,6 +44,10 @@
 {
     mbed::Timer timer;
     timer.start();
+    mbed::Timeout timeout;
+    if (_timeout >= 0) {
+        timeout.attach_us(&Socket::wakeup, _timeout * 1000);
+    }
 
     if (connection->_socket) {
         connection->close();
@@ -61,7 +65,7 @@
         }
 
         if (err != NSAPI_ERROR_WOULD_BLOCK
-            || (_timeout >= 0 && timer.read_ms() > _timeout)) {
+            || (_timeout >= 0 && timer.read_ms() >= _timeout)) {
             return err;
         }
 
--- a/TCPSocket.cpp	Wed Apr 20 19:48:17 2016 -0500
+++ b/TCPSocket.cpp	Wed Apr 20 20:38:00 2016 -0500
@@ -54,6 +54,10 @@
 {
     mbed::Timer timer;
     timer.start();
+    mbed::Timeout timeout;
+    if (_timeout >= 0) {
+        timeout.attach_us(&Socket::wakeup, _timeout * 1000);
+    }
 
     while (true) {
         if (!_socket) {
@@ -62,7 +66,7 @@
 
         int sent = _iface->socket_send(_socket, data, size);
         if (sent != NSAPI_ERROR_WOULD_BLOCK
-            || (_timeout >= 0 && timer.read_ms() > _timeout)) {
+            || (_timeout >= 0 && timer.read_ms() >= _timeout)) {
             return sent;
         }
 
@@ -74,6 +78,10 @@
 {
     mbed::Timer timer;
     timer.start();
+    mbed::Timeout timeout;
+    if (_timeout >= 0) {
+        timeout.attach_us(&Socket::wakeup, _timeout * 1000);
+    }
 
     while (true) {
         if (!_socket) {
@@ -82,7 +90,7 @@
     
         int recv = _iface->socket_recv(_socket, data, size);
         if (recv != NSAPI_ERROR_WOULD_BLOCK
-            || (_timeout >= 0 && timer.read_ms() > _timeout)) {
+            || (_timeout >= 0 && timer.read_ms() >= _timeout)) {
             return recv;
         }
 
--- a/UDPSocket.cpp	Wed Apr 20 19:48:17 2016 -0500
+++ b/UDPSocket.cpp	Wed Apr 20 20:38:00 2016 -0500
@@ -45,6 +45,10 @@
 {
     mbed::Timer timer;
     timer.start();
+    mbed::Timeout timeout;
+    if (_timeout >= 0) {
+        timeout.attach_us(&Socket::wakeup, _timeout * 1000);
+    }
 
     while (true) {
         if (!_socket) {
@@ -53,7 +57,7 @@
     
         int sent = _iface->socket_sendto(_socket, address, data, size);
         if (sent != NSAPI_ERROR_WOULD_BLOCK
-            || (_timeout >= 0 && timer.read_ms() > _timeout)) {
+            || (_timeout >= 0 && timer.read_ms() >= _timeout)) {
             return sent;
         }
 
@@ -65,6 +69,10 @@
 {
     mbed::Timer timer;
     timer.start();
+    mbed::Timeout timeout;
+    if (_timeout >= 0) {
+        timeout.attach_us(&Socket::wakeup, _timeout * 1000);
+    }
 
     while (true) {
         if (!_socket) {
@@ -73,7 +81,7 @@
     
         int recv = _iface->socket_recvfrom(_socket, address, buffer, size);
         if (recv != NSAPI_ERROR_WOULD_BLOCK
-            || (_timeout >= 0 && timer.read_ms() > _timeout)) {
+            || (_timeout >= 0 && timer.read_ms() >= _timeout)) {
             return recv;
         }