diff --git a/src/socketpair.cpp b/src/socketpair.cpp index 9361313..f4a9a4d 100644 --- a/src/socketpair.cpp +++ b/src/socketpair.cpp @@ -1,6 +1,7 @@ #include "socketpair.h" -#include #include +#include +#include SocketPair::SocketPair(QObject *parent) : QObject(parent) @@ -14,6 +15,9 @@ bool SocketPair::create() connect(dataCheck, SIGNAL(timeout()), this, SLOT(readServerData())); connect(&server, SIGNAL(newConnection()), this, SLOT(newConnection()), Qt::QueuedConnection); + connect(&server, SIGNAL(acceptError()), this, SLOT(logServerError())); + connect(&clientConnection, SIGNAL(error()), this, SLOT(logClientConnectionError())); + int tries = 5; while (tries) { if (!server.isListening()) { @@ -40,6 +44,12 @@ bool SocketPair::create() void SocketPair::newConnection() { serverConnection = server.nextPendingConnection(); + if(serverConnection != nullptr) { + connect(serverConnection, SIGNAL(error()), this, SLOT(logServerConnectionError())); + } else { + qFatal("%s:%d:%s, server.nextPendingConnection() was NULL.", __FILE__, + __LINE__, __func__); + } serverConnection->setSocketOption( QAbstractSocket::LowDelayOption, 1 ); serverConnection->setSocketOption( QAbstractSocket::KeepAliveOption, 1 ); @@ -81,3 +91,24 @@ QTcpSocket* SocketPair::output() { return serverConnection; } + +void SocketPair::logServerError(QAbstractSocket::SocketError socketError) { + qCritical("%s:%d:%s, server.serverError() is: '%d', and server.errorString() " + "is: '%s', and socketError is: '%d'", __FILE__, __LINE__, __func__, + server.serverError(), qUtf8Printable(server.errorString()), + socketError); +} + +void SocketPair::logServerConnectionError(QAbstractSocket::SocketError socketError) { + qCritical("%s:%d:%s, serverConnection->error() is: '%d', and " + "serverConnection->errorString() is: '%s', and socketError is: '%d'", + __FILE__, __LINE__, __func__, serverConnection->error(), + qUtf8Printable(serverConnection->errorString()), socketError); +} + +void SocketPair::logClientConnectionError(QAbstractSocket::SocketError socketError) { + qCritical("%s:%d:%s, clientConnection.error() is: '%d', and " + "clientConnection.errorString() is: '%s', and socketError is: '%d'", + __FILE__, __LINE__, __func__, clientConnection.error(), + qUtf8Printable(clientConnection.errorString()), socketError); +} diff --git a/src/socketpair.h b/src/socketpair.h index 5d1e331..ef58a5a 100644 --- a/src/socketpair.h +++ b/src/socketpair.h @@ -34,6 +34,12 @@ public slots: QTcpSocket *serverConnection; QTcpSocket clientConnection; QTcpServer server; + +private slots: + void logServerError(QAbstractSocket::SocketError); + void logServerConnectionError(QAbstractSocket::SocketError); + void logClientConnectionError(QAbstractSocket::SocketError); + }; #endif // SOCKETPAIR_H