Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: operation/PollThread.cpp
- Revision:
- 122:3e4a1ed4bad5
- Parent:
- 116:5de54f09f754
- Child:
- 123:311fa85af2b3
diff -r 68217ccb8cd1 -r 3e4a1ed4bad5 operation/PollThread.cpp --- a/operation/PollThread.cpp Wed May 20 14:30:26 2015 +0000 +++ b/operation/PollThread.cpp Wed May 27 09:22:24 2015 +0000 @@ -9,7 +9,7 @@ l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2); sock.setBlocking(3000); l = sock.sendAndReceive(buf, l, sizeof(buf)); - if (l < 0) + if (l <= 0) return false; size_t i = 0; for (const char* p = skipHTTPHeader(buf); isalnum(*p); ++p, ++i) { @@ -24,17 +24,21 @@ int l = snprintf(buf2, sizeof(buf2), "81,%s,%s\r\n", bayeuxId, chn); l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2); sock.setBlocking(3000); - l = sock.sendOnly(buf, l); - return l>=0; + l = sock.sendAndReceive(buf, l, sizeof(buf)); + if (l <= 0) return false; + const char *p = skipHTTPHeader(buf); + if (p == NULL) return false; + for (; *p && !isgraph(*p); ++p); + return *p == 0; } bool PollThread::connect() { int l = snprintf(buf2, sizeof(buf2), "83,%s\r\n", bayeuxId); l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2); - sock.setBlocking(-1); + sock.setBlocking(300000); // Timeout after an hour l = sock.sendAndReceive(buf, l, sizeof(buf)); - return l>=0; + return l>0; } void PollThread::threadFunc()