From 6e2299833680fe13a7eb1a6c78de0228d769cb0d Mon Sep 17 00:00:00 2001 From: harry Date: Sun, 24 Mar 2024 21:29:41 -0400 Subject: [PATCH] Increased netplay tcp OS level send/receive buffer sizes. --- src/drivers/Qt/NetPlay.cpp | 28 ++++++++++++++++++++++++---- src/drivers/Qt/NetPlay.h | 2 ++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/drivers/Qt/NetPlay.cpp b/src/drivers/Qt/NetPlay.cpp index b4a20f15..026fc3ff 100644 --- a/src/drivers/Qt/NetPlay.cpp +++ b/src/drivers/Qt/NetPlay.cpp @@ -262,6 +262,8 @@ void NetPlayServer::processPendingConnections(void) clientList.push_back(client); + connect( newSock, SIGNAL(readyRead(void)), client, SLOT(serverReadyRead(void)) ); + newSock = nextPendingConnection(); printf("Added Client: %p %zu\n", client, clientList.size() ); @@ -1104,6 +1106,9 @@ void NetPlayClient::setSocket(QTcpSocket *s) if (sock != nullptr) { + sock->setSocketOption( QAbstractSocket::SendBufferSizeSocketOption, static_cast(recvMsgBufSize) ); + sock->setSocketOption( QAbstractSocket::ReceiveBufferSizeSocketOption, static_cast(recvMsgBufSize) ); + connect(sock, SIGNAL(connected(void)) , this, SLOT(onConnect(void))); connect(sock, SIGNAL(disconnected(void)), this, SLOT(onDisconnect(void))); } @@ -1114,8 +1119,11 @@ QTcpSocket* NetPlayClient::createSocket(void) if (sock == nullptr) { sock = new QTcpSocket(this); - //sock->setReadBufferSize( recvMsgBufSize ); + sock->setSocketOption( QAbstractSocket::SendBufferSizeSocketOption, static_cast(recvMsgBufSize) ); + sock->setSocketOption( QAbstractSocket::ReceiveBufferSizeSocketOption, static_cast(recvMsgBufSize) ); + + connect(sock, SIGNAL(readyRead(void)) , this, SLOT(clientReadyRead(void)) ); connect(sock, SIGNAL(connected(void)) , this, SLOT(onConnect(void))); connect(sock, SIGNAL(disconnected(void)), this, SLOT(onDisconnect(void))); connect(sock, SIGNAL(errorOccurred(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError))); @@ -1345,7 +1353,7 @@ int NetPlayClient::readMessages( void (*msgCallback)( void *userData, void *msgB int bytesAvailable = sock->bytesAvailable(); readReq = bytesAvailable > 0; - printf("Read Bytes Available: %lu %i %i\n", ts.toMilliSeconds(), bytesAvailable, recvMsgBytesLeft); + //printf("Read Bytes Available: %lu %i %i\n", ts.toMilliSeconds(), bytesAvailable, recvMsgBytesLeft); while (readReq) { @@ -1366,7 +1374,7 @@ int NetPlayClient::readMessages( void (*msgCallback)( void *userData, void *msgB recvMsgBytesLeft -= dataRead; recvMsgByteIndex += dataRead; } - printf(" Data: Id: %u Size: %zu Read: %i\n", recvMsgId, readSize, dataRead ); + //printf(" Data: Id: %u Size: %zu Read: %i\n", recvMsgId, readSize, dataRead ); if (recvMsgBytesLeft > 0) { @@ -1401,7 +1409,7 @@ int NetPlayClient::readMessages( void (*msgCallback)( void *userData, void *msgB { printf("Error: Message size too large: %08X\n", recvMsgId); } - printf("HDR: Id: %u Size: %u\n", netPlayByteSwap(hdr->msgId), netPlayByteSwap(hdr->msgSize) ); + //printf("HDR: Id: %u Size: %u\n", netPlayByteSwap(hdr->msgId), netPlayByteSwap(hdr->msgSize) ); recvMsgByteIndex = sizeof(netPlayMsgHdr); @@ -1565,6 +1573,18 @@ void NetPlayClient::clientProcessMessage( void *msgBuf, size_t msgSize ) } } //----------------------------------------------------------------------------- +void NetPlayClient::serverReadyRead() +{ + //printf("Server Ready Read\n"); + readMessages( serverMessageCallback, this ); +} +//----------------------------------------------------------------------------- +void NetPlayClient::clientReadyRead() +{ + //printf("Client Ready Read\n"); + readMessages( clientMessageCallback, this ); +} +//----------------------------------------------------------------------------- //--- NetPlayHostDialog //----------------------------------------------------------------------------- NetPlayHostDialog* NetPlayHostDialog::instance = nullptr; diff --git a/src/drivers/Qt/NetPlay.h b/src/drivers/Qt/NetPlay.h index 42f66077..e892a0c1 100644 --- a/src/drivers/Qt/NetPlay.h +++ b/src/drivers/Qt/NetPlay.h @@ -320,6 +320,8 @@ class NetPlayClient : public QObject void onSocketError(QAbstractSocket::SocketError); void onRomLoad(void); void onRomUnload(void); + void serverReadyRead(void); + void clientReadyRead(void); };