Subversion Repositories HomeAutomation

Rev

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

Rev 1122 Rev 1124
Line 75... Line 75...
75
            loop = receiveData();
75
            loop = receiveData();
76
        }
76
        }
77
    }
77
    }
78
    catch (SocketException *e)
78
    catch (SocketException *e)
79
    {
79
    {
-
 
80
        cout << "DEBUG: socket got an exception: " << e->getDescription() << endl;
80
        // Something bad happend and we can not continue
81
        // Something bad happend and we can not continue
81
        eventAdd(SocketEvent::TYPE_CONNECTION_DIED, e->getDescription());
82
        eventAdd(SocketEvent::TYPE_CONNECTION_DIED, e->getDescription());
82
    }
83
    }
83
 
84
 
84
    // Clean up socket if we would want to restart
85
    // Clean up socket if we would want to restart
Line 88... Line 89...
88
bool AsyncSocket::receiveData()
89
bool AsyncSocket::receiveData()
89
{
90
{
90
    char buffer[MAXBUFFER + 1];
91
    char buffer[MAXBUFFER + 1];
91
    memset(buffer, 0, MAXBUFFER + 1);
92
    memset(buffer, 0, MAXBUFFER + 1);
92
 
93
 
-
 
94
    //cout << "recv start" << endl;
93
    int status = ::recv(mySocket, buffer, MAXBUFFER, 0);
95
    int status = ::recv(mySocket, buffer, MAXBUFFER, 0);
-
 
96
    //cout << "recv end" << endl;
94
 
97
   
95
    if (status == -1)
98
    if (status == -1)
96
    {
99
    {
97
        switch (errno)
100
        switch (errno)
98
        {
101
        {
Line 402... Line 405...
402
 
405
 
403
void AsyncSocket::sendData(string data)
406
void AsyncSocket::sendData(string data)
404
{
407
{
405
    mySendMutex.lock();
408
    mySendMutex.lock();
406
 
409
 
407
    int status = ::send(mySocket, data.c_str(), data.size(), 0);
410
    int status = ::send(mySocket, data.c_str(), data.size(), MSG_NOSIGNAL);
408
//Logger::getInstance().add("Sent: \"" + data + "\" status was " + itos(status) + "\n");
411
//Logger::getInstance().add("Sent: \"" + data + "\" status was " + itos(status) + "\n");
409
    mySendMutex.unlock();
412
    mySendMutex.unlock();
410
 
413
 
411
    //Logger &log = Logger::getInstance();
414
    //Logger &log = Logger::getInstance();
412
    //log.add("Sent: \"" + data + "\" status was " + itos(status) + "\n");
415
    //log.add("Sent: \"" + data + "\" status was " + itos(status) + "\n");
Line 459... Line 462...
459
 
462
 
460
            case EOPNOTSUPP:
463
            case EOPNOTSUPP:
461
            throw new SocketException("Some bit in the flags argument is inappropriate for the socket type.");
464
            throw new SocketException("Some bit in the flags argument is inappropriate for the socket type.");
462
 
465
 
463
            case EPIPE:
466
            case EPIPE:
-
 
467
            close();
-
 
468
            stop();
464
            throw new SocketException("The local end has been shut down on a connection oriented socket. In this case the process will also receive a SIGPIPE unless MSG_NOSIGNAL is set.");
469
            //throw new SocketException("The local end has been shut down on a connection oriented socket. In this case the process will also receive a SIGPIPE unless MSG_NOSIGNAL is set.");
-
 
470
            break;
465
 
471
 
466
            default:
472
            default:
467
            throw new SocketException("Unknow exception: " + itos(errno));
473
            throw new SocketException("Unknow exception: " + itos(errno));
468
        }
474
        }
469
    }
475
    }