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.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: operation/PollThread.cpp
- Revision:
- 130:dc9e37d4bc05
- Parent:
- 127:871e6eb0fa76
- Child:
- 135:c4009ecaf5c0
--- a/operation/PollThread.cpp Wed Jun 03 09:51:47 2015 +0000
+++ b/operation/PollThread.cpp Mon Jun 29 11:14:27 2015 +0000
@@ -3,18 +3,13 @@
#include "PollThread.h"
#include "logging.h"
-static size_t _volSend = 0;
-static size_t _volRecv = 0;
-
bool PollThread::handshake()
{
int l = snprintf(buf2, sizeof(buf2), "%s", "80\r\n");
l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2);
sock.setBlocking(3000);
- _volSend += l;
l = sock.sendAndReceive(buf, l, sizeof(buf));
if (l <= 0) return false;
- _volRecv += l;
const char* p = skipHTTPHeader(buf);
if (p == NULL) return false;
size_t i = 0;
@@ -30,10 +25,8 @@
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);
- _volSend += l;
l = sock.sendAndReceive(buf, l, sizeof(buf));
if (l <= 0) return false;
- _volRecv += l;
const char *p = skipHTTPHeader(buf);
if (p == NULL) return false;
for (; *p && !isgraph(*p); ++p);
@@ -45,11 +38,36 @@
int l = snprintf(buf2, sizeof(buf2), "83,%s\r\n", bayeuxId);
l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2);
sock.setBlocking(610000); // Timeout after 10m:10s
- _volSend += l;
- aInfo("[SEND] poll: %d\n", _volSend);
- l = sock.sendAndReceive(buf, l, sizeof(buf));
- _volRecv += l;
- aInfo("[RECV] poll: %d\n", _volRecv);
+// sock.setBlocking(-1);
+// l = sock.sendAndReceive(buf, l, sizeof(buf));
+ int c = sock.connect();
+ if (c < 0) {
+ sock.close();
+ return false;
+ }
+ c = sock.send(buf, l);
+ if (c < 0) {
+ sock.close();
+ return false;
+ }
+ // Avoid heartbeat message overflows the buffer
+ l = 0;
+ for (unsigned short i = 0; i < 200; ++i) {
+ int l2 = sock.receive(buf+l, sizeof(buf)-l);
+ printf("l2: %d\n", l2);
+ if (l2 > 0) {
+ printf("poll: %.*s\n", l2, buf+l);
+ l += l2;
+ } else if (!sock.is_connected()) {
+ break;
+ } else {
+ l = l2;
+ break;
+ }
+ }
+ if (l >= 0)
+ buf[l] = 0;
+ sock.close();
return l>0;
}

Cumulocity