X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotrmi%2FC%2B%2B%2FIoTSocket.hpp;fp=iotjava%2Fiotrmi%2FC%2B%2B%2FIoTSocket.hpp;h=cf62ec1a2d6af143703d807a888f2254fe615013;hb=ae77f0f97f70a6d3bef0faee0b7db27fb5e2849f;hp=642882f8a63afbcd5e5cf9ee555f801f33148c51;hpb=09bf1cf8e98526878b4732bf8d3077eb2d1c16e3;p=iot2.git diff --git a/iotjava/iotrmi/C++/IoTSocket.hpp b/iotjava/iotrmi/C++/IoTSocket.hpp index 642882f..cf62ec1 100644 --- a/iotjava/iotrmi/C++/IoTSocket.hpp +++ b/iotjava/iotrmi/C++/IoTSocket.hpp @@ -17,6 +17,9 @@ #define DEBUG_ACK static const int SOCKET_BUFF_SIZE = 64000; +// Before, it was too short as we were just using 1 byte to receive the length +// Now, we allocate 4 bytes (a size of integer) to receive the message length +static const int MSG_LEN_SIZE = 4; #include #include @@ -92,7 +95,7 @@ bool IoTSocket::sendBytes(char* pVals, int _iLen) { int iLen = _iLen; size[0] = iLen; - if (send(m_iSock, size, 1, 0) == -1) { + if (send(m_iSock, size, MSG_LEN_SIZE, 0) == -1) { perror("IoTSocket: Send size error!"); return false; } @@ -125,16 +128,18 @@ char* IoTSocket::receiveBytes(char* pVals, int* len) int iTotal = 0; int iResult = 0; - char size[1]; + int size[1]; + while ((iTotal < 1) && (iResult != -1)) { - iResult = recv(m_iSock, size, 1, 0); + iResult = recv(m_iSock, size, MSG_LEN_SIZE, 0); iTotal += iResult; } if (iResult == -1) { perror("IoTSocket: Receive size error!"); return NULL; } - int iLen = (int) size[0]; + int iLen = size[0]; + // To be returned from this method... *len = iLen; pVals = new char[iLen];