Cleaning up drivers/Cpp, Cpp/Lifxtest, virtuals, and iotrmi/C++ (revisiting the C...
[iot2.git] / iotjava / iotrmi / C++ / IoTSocketServer.hpp
index 47400f92fc69c2b1287ed70aa77d333883c82aec..f82bbf122ff013a2a935978732e07e88269e7916 100644 (file)
 
 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;
 }