Prepended qDebug output with connection id for easier debugging
This commit is contained in:
parent
87982a4227
commit
8e14e0c15b
@ -29,9 +29,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
|||||||
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
||||||
|
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
#include <QString>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
|
#include <QThreadStorage>
|
||||||
|
#include <QtGlobal>
|
||||||
#include <qendian.h>
|
#include <qendian.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static QThreadStorage<QString*> connId;
|
||||||
|
|
||||||
RpcConnection::RpcConnection(int socketDescriptor,
|
RpcConnection::RpcConnection(int socketDescriptor,
|
||||||
::google::protobuf::Service *service)
|
::google::protobuf::Service *service)
|
||||||
: socketDescriptor(socketDescriptor),
|
: socketDescriptor(socketDescriptor),
|
||||||
@ -64,6 +72,7 @@ RpcConnection::~RpcConnection()
|
|||||||
|
|
||||||
void RpcConnection::start()
|
void RpcConnection::start()
|
||||||
{
|
{
|
||||||
|
QString id = QString("[%1:%2] ");
|
||||||
clientSock = new QTcpSocket;
|
clientSock = new QTcpSocket;
|
||||||
if (!clientSock->setSocketDescriptor(socketDescriptor)) {
|
if (!clientSock->setSocketDescriptor(socketDescriptor)) {
|
||||||
qWarning("Unable to initialize TCP socket for incoming connection");
|
qWarning("Unable to initialize TCP socket for incoming connection");
|
||||||
@ -71,6 +80,9 @@ void RpcConnection::start()
|
|||||||
}
|
}
|
||||||
qDebug("clientSock Thread = %p", clientSock->thread());
|
qDebug("clientSock Thread = %p", clientSock->thread());
|
||||||
|
|
||||||
|
connId.setLocalData(new QString(id.arg(clientSock->peerAddress().toString())
|
||||||
|
.arg(clientSock->peerPort())));
|
||||||
|
|
||||||
qDebug("accepting new connection from %s: %d",
|
qDebug("accepting new connection from %s: %d",
|
||||||
clientSock->peerAddress().toString().toAscii().constData(),
|
clientSock->peerAddress().toString().toAscii().constData(),
|
||||||
clientSock->peerPort());
|
clientSock->peerPort());
|
||||||
@ -150,7 +162,7 @@ void RpcConnection::sendRpcReply(PbRpcController *controller)
|
|||||||
{
|
{
|
||||||
qDebug("Server(%s): sending %d bytes to client <----",
|
qDebug("Server(%s): sending %d bytes to client <----",
|
||||||
__FUNCTION__, len + PB_HDR_SIZE);
|
__FUNCTION__, len + PB_HDR_SIZE);
|
||||||
BUFDUMP(msg, len + 8);
|
BUFDUMP(msg, 8);
|
||||||
qDebug("method = %d\nreq = \n%s---->",
|
qDebug("method = %d\nreq = \n%s---->",
|
||||||
pendingMethodId, response->DebugString().c_str());
|
pendingMethodId, response->DebugString().c_str());
|
||||||
}
|
}
|
||||||
@ -289,3 +301,15 @@ _error_exit2:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RpcConnection::connIdMsgHandler(QtMsgType type, const char* msg)
|
||||||
|
{
|
||||||
|
if (connId.hasLocalData()) {
|
||||||
|
QString newMsg(*connId.localData());
|
||||||
|
newMsg.append(msg);
|
||||||
|
newMsg.replace(QChar('\n'), QString("\n").append(*connId.localData()));
|
||||||
|
msg = qPrintable(newMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "%s\n", msg);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
@ -42,6 +42,7 @@ class RpcConnection : public QObject
|
|||||||
public:
|
public:
|
||||||
RpcConnection(int socketDescriptor, ::google::protobuf::Service *service);
|
RpcConnection(int socketDescriptor, ::google::protobuf::Service *service);
|
||||||
virtual ~RpcConnection();
|
virtual ~RpcConnection();
|
||||||
|
static void connIdMsgHandler(QtMsgType type, const char* msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sendRpcReply(PbRpcController *controller);
|
void sendRpcReply(PbRpcController *controller);
|
||||||
|
@ -34,6 +34,8 @@ protected:
|
|||||||
RpcServer::RpcServer()
|
RpcServer::RpcServer()
|
||||||
{
|
{
|
||||||
service = NULL;
|
service = NULL;
|
||||||
|
|
||||||
|
qInstallMsgHandler(RpcConnection::connIdMsgHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
RpcServer::~RpcServer()
|
RpcServer::~RpcServer()
|
||||||
|
Loading…
Reference in New Issue
Block a user