yap yee king / WiflyInterface

Fork of WiflyInterface by mbed official

Revision:
10:e19f4c58a137
Parent:
4:0bcec6272784
--- a/Socket/TCPSocketServer.cpp	Tue Jan 28 11:00:48 2014 +0200
+++ b/Socket/TCPSocketServer.cpp	Fri Dec 16 02:50:56 2016 +0000
@@ -87,4 +87,34 @@
             }
         }
     }
+}
+
+int TCPSocketServer::acceptWithTimeout(TCPSocketConnection& connection, int timeout) {
+    int nb_available = 0, pos = 0;
+    char c;
+    string str;
+    bool o_find = false;
+    time_t currTime = time(NULL);
+    while (1) {
+        while(!wifi->readable() && time(NULL)-currTime<=timeout);
+        if (time(NULL)-currTime>timeout) {
+            wifi->flush();
+            return -1;
+        }
+        nb_available = wifi->readable();
+        for (int i = 0; i < nb_available; i++) {
+            c = wifi->getc();
+            if (c == '*') {
+                o_find = true;
+            }
+            if (o_find && c != '\r' && c != '\n') {
+                str += c;
+                pos = str.find("*OPEN*");
+                if (pos != string::npos) {
+                    wifi->flush();
+                    return 0;
+                }
+            }
+        }
+    }
 }
\ No newline at end of file