X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=iotjava%2Fiotrmi%2FC%2B%2B%2FIoTSocketServer.hpp;h=f82bbf122ff013a2a935978732e07e88269e7916;hb=ffea2cb68e5a2e1bac041fe2279620eba8d227f8;hp=47400f92fc69c2b1287ed70aa77d333883c82aec;hpb=e9a65a3fa878d7451ceb4f5a2cb1bc9ee846e035;p=iot2.git diff --git a/iotjava/iotrmi/C++/IoTSocketServer.hpp b/iotjava/iotrmi/C++/IoTSocketServer.hpp index 47400f9..f82bbf1 100644 --- a/iotjava/iotrmi/C++/IoTSocketServer.hpp +++ b/iotjava/iotrmi/C++/IoTSocketServer.hpp @@ -20,15 +20,14 @@ class IoTSocketServer final : public IoTSocket { - public: + public: IoTSocketServer(int iPort, bool* pResult); - - bool connect(); // Accept a new connection + bool connect(); // Accept a new connection protected: - bool m_bReverse; // Am I reversing byte order or not? - int m_iListen; // Descriptor we are listening on - struct sockaddr_in m_addrMe; // My address information + bool m_bReverse; // Am I reversing byte order or not? + int m_iListen; // Descriptor we are listening on + struct sockaddr_in m_addrMe; // My address information }; @@ -37,10 +36,8 @@ IoTSocketServer::IoTSocketServer(int iPort, bool* pResult) : IoTSocket(iPort, pResult) { m_iListen = -1; - if (pResult) *pResult = false; - if ((m_iListen = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("IoTSocketServer: Socket error!"); @@ -75,12 +72,12 @@ IoTSocketServer::IoTSocketServer(int iPort, bool* pResult) : bool IoTSocketServer::connect() { socklen_t iSinSize = (socklen_t) sizeof(struct sockaddr_in); - if ((m_iSock = accept(m_iListen, (struct sockaddr *) &m_addrRemote, &iSinSize)) == -1) { perror("IoTSocketServer: Accept connection error!"); return false; } + // The client sends us an int to indicate if we should // be reversing byte order on this connection. The client // is sending 0 or 1, so a reversed 0 still looks @@ -93,6 +90,7 @@ bool IoTSocketServer::connect() iResult = recv(m_iSock, temp, 1, 0); iTotal += iResult; } + if (iResult == -1) { perror("IoTSocketServer: Receive data error!"); @@ -100,12 +98,11 @@ bool IoTSocketServer::connect() } int iVal = temp[0]; - if (iVal == 0) m_bReverse = false; else m_bReverse = true; - + return true; }