Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Revision:
121:68217ccb8cd1
Parent:
115:4eb3c7e945cf
--- a/util/SmartRestSocket.cpp	Wed May 20 13:17:19 2015 +0000
+++ b/util/SmartRestSocket.cpp	Wed May 20 14:30:26 2015 +0000
@@ -16,11 +16,7 @@
                         snprintf(cachedIP, sizeof(cachedIP), "%u.%u.%u.%u", c[3], c[2], c[1], c[0]);
                 }
                 n = TCPSocketConnection::connect(cachedIP, srPort);
-                if (n >= 0) {
-                        if (timeout == -1)
-                            Socket::set_blocking(true);
-                        else
-                            Socket::set_blocking(false, timeout);
+                if (n == 0) {
                         break;
                 } else {
                         cachedIP[0] = 0;
@@ -32,8 +28,10 @@
 int SmartRestSocket::sendOnly(char *buf, int size)
 {
         int l = connect();
-        if (l < 0)
+        if (l < 0) {
+                close();
                 return -3;
+        }
         l = send(buf, size);
         close();
         if (l < 0) {
@@ -46,17 +44,19 @@
 int SmartRestSocket::sendAndReceive(char *buf, int size, int maxSize)
 {
         int l = connect();
-        if (l < 0)
+        if (l < 0) {
+                close();
                 return -3;
+        }
         l = send(buf, size);
         if (l < 0) {
                 close();
                 return -2;
         } else {
                 l = receive(buf, maxSize);
+                close();
                 if (l >= 0 && l < maxSize)
                         buf[l] = 0;
-                close();
                 return l;
         }
 }
\ No newline at end of file