Subversion Repositories HomeAutomation

Rev

Rev 1124 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1124 Rev 1203
Line 41... Line 41...
41
    silentClose();
41
    silentClose();
42
}
42
}
43
 
43
 
44
void AsyncSocket::run()
44
void AsyncSocket::run()
45
{
45
{
-
 
46
//cout << "AsyncSocket::run - Thread started\n";
46
    // If connection is already up then we should not connect again
47
    // If connection is already up then we should not connect again
47
    if (!isConnected())
48
    if (!isConnected())
48
    {
49
    {
49
        // If we have choosen to not use automatic reconnect do not start reconnect loop
50
        // If we have choosen to not use automatic reconnect do not start reconnect loop
50
        if (myReconnectTimeout == 0)
51
        if (myReconnectTimeout == 0)
Line 80... Line 81...
80
        cout << "DEBUG: socket got an exception: " << e->getDescription() << endl;
81
        cout << "DEBUG: socket got an exception: " << e->getDescription() << endl;
81
        // Something bad happend and we can not continue
82
        // Something bad happend and we can not continue
82
        eventAdd(SocketEvent::TYPE_CONNECTION_DIED, e->getDescription());
83
        eventAdd(SocketEvent::TYPE_CONNECTION_DIED, e->getDescription());
83
    }
84
    }
84
 
85
 
-
 
86
//cout << "AsyncSocket::run - Thread end?\n";
85
    // Clean up socket if we would want to restart
87
    // Clean up socket if we would want to restart
86
    silentClose();
88
    silentClose();
87
}
89
}
88
 
90
 
89
bool AsyncSocket::receiveData()
91
bool AsyncSocket::receiveData()
Line 323... Line 325...
323
    return false;
325
    return false;
324
}
326
}
325
 
327
 
326
void AsyncSocket::connect()
328
void AsyncSocket::connect()
327
{
329
{
-
 
330
//cout << "AsyncSocket::connect - eventAdd connecting\n";
328
    eventAdd(SocketEvent::TYPE_CONNECTING);
331
    eventAdd(SocketEvent::TYPE_CONNECTING);
329
 
332
 
330
    create();
333
    create();
331
 
334
 
332
    memset(&myAddressStruct, 0, sizeof(myAddressStruct));
335
    memset(&myAddressStruct, 0, sizeof(myAddressStruct));
Line 398... Line 401...
398
            default:
401
            default:
399
            throw new SocketException("Other errors may be generated by the underlying protocol modules. : " + itos(errno));
402
            throw new SocketException("Other errors may be generated by the underlying protocol modules. : " + itos(errno));
400
        }
403
        }
401
    }
404
    }
402
 
405
 
-
 
406
//cout << "AsyncSocket::connect - eventAdd connected\n";
403
    eventAdd(SocketEvent::TYPE_CONNECTED);
407
    eventAdd(SocketEvent::TYPE_CONNECTED);
404
}
408
}
405
 
409
 
406
void AsyncSocket::sendData(string data)
410
void AsyncSocket::sendData(string data)
407
{
411
{
-
 
412
//cout << "AsyncSocket::sendData - got data to send: ";
-
 
413
//cout << data;
-
 
414
//cout << "\n";
408
    mySendMutex.lock();
415
    mySendMutex.lock();
409
 
416
 
410
    int status = ::send(mySocket, data.c_str(), data.size(), MSG_NOSIGNAL);
417
    int status = ::send(mySocket, data.c_str(), data.size(), MSG_NOSIGNAL);
411
//Logger::getInstance().add("Sent: \"" + data + "\" status was " + itos(status) + "\n");
418
//Logger::getInstance().add("Sent: \"" + data + "\" status was " + itos(status) + "\n");
412
    mySendMutex.unlock();
419
    mySendMutex.unlock();