15 #include <QNetworkInterface>
54 if (!protocol.isEmpty())
55 postfix = QString(
"[%1]").arg(protocol);
56 return QString(
"%1:%2%3").arg(name).arg(port).arg(postfix);
68 qRegisterMetaType<boost::function<void()> >(
"boost::function<void()>");
69 qRegisterMetaType<CX_SOCKETCONNECTION_STATE>(
"CX_SOCKETCONNECTION_STATE");
76 connect(
mSocket, &QTcpSocket::connected,
this, &SocketConnection::internalConnected);
77 connect(
mSocket, &QTcpSocket::disconnected,
this, &SocketConnection::internalDisconnected);
78 connect(
mSocket, &QTcpSocket::readyRead,
this, &SocketConnection::internalDataAvailable);
82 void (QTcpSocket::* errorOverloaded)(QAbstractSocket::SocketError) = &QTcpSocket::error;
84 connect(
mSocket, errorOverloaded,
this, &SocketConnection::internalError);
163 qint64 writtenBytes =
mSocket->write(data, maxSize);
164 if(writtenBytes != maxSize)
169 void SocketConnection::internalConnected()
175 void SocketConnection::internalDisconnected()
181 void SocketConnection::internalError(QAbstractSocket::SocketError socketError)
183 CX_LOG_ERROR() << QString(
"[%1] Socket error [code=%2]: %3")
185 .arg(QString::number(socketError))
191 void SocketConnection::internalDataAvailable()
204 return mSocket->state() == QAbstractSocket::ConnectedState;
209 bool enoughBytes =
mSocket->bytesAvailable() >= bytes;
220 char* charPointer =
reinterpret_cast<char*
>(packPointer);
221 int r =
mSocket->read(charPointer, packSize);
224 CX_LOG_ERROR() <<
"Error when receiving data from socket.";