mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Some improvements to Servatice network code (#3969)
* Some improvements to Servatice network code 1. fix crash on fuzzy connection (tcp server only) 2. ensure websockets are parent()ed to avoid leaking them 3. quick catch disconnect()ed sockets instead of waiting for a socket error to happen 4. supporto mulltiple connection pools on the websocket server; they are still bound to the same thread due to a qt5 limitation.
This commit is contained in:
parent
46fe0cd725
commit
d30691559a
4 changed files with 34 additions and 12 deletions
|
|
@ -122,6 +122,11 @@ void AbstractServerSocketInterface::catchSocketError(QAbstractSocket::SocketErro
|
|||
prepareDestroy();
|
||||
}
|
||||
|
||||
void AbstractServerSocketInterface::catchSocketDisconnected()
|
||||
{
|
||||
prepareDestroy();
|
||||
}
|
||||
|
||||
void AbstractServerSocketInterface::transmitProtocolItem(const ServerMessage &item)
|
||||
{
|
||||
outputQueueMutex.lock();
|
||||
|
|
@ -1511,6 +1516,7 @@ TcpServerSocketInterface::TcpServerSocketInterface(Servatrice *_server,
|
|||
connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()));
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
|
||||
SLOT(catchSocketError(QAbstractSocket::SocketError)));
|
||||
connect(socket, SIGNAL(disconnected()), this, SLOT(catchSocketDisconnected()));
|
||||
}
|
||||
|
||||
TcpServerSocketInterface::~TcpServerSocketInterface()
|
||||
|
|
@ -1594,7 +1600,7 @@ void TcpServerSocketInterface::readClient()
|
|||
} else
|
||||
return;
|
||||
}
|
||||
if (inputBuffer.size() < messageLength)
|
||||
if (inputBuffer.size() < messageLength || messageLength < 0)
|
||||
return;
|
||||
|
||||
CommandContainer newCommandContainer;
|
||||
|
|
@ -1679,6 +1685,7 @@ WebsocketServerSocketInterface::~WebsocketServerSocketInterface()
|
|||
void WebsocketServerSocketInterface::initConnection(void *_socket)
|
||||
{
|
||||
socket = (QWebSocket *)_socket;
|
||||
socket->setParent(this);
|
||||
address = socket->peerAddress();
|
||||
|
||||
QByteArray websocketIPHeader = settingsCache->value("server/web_socket_ip_header", "").toByteArray();
|
||||
|
|
@ -1699,6 +1706,7 @@ void WebsocketServerSocketInterface::initConnection(void *_socket)
|
|||
SLOT(binaryMessageReceived(const QByteArray &)));
|
||||
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this,
|
||||
SLOT(catchSocketError(QAbstractSocket::SocketError)));
|
||||
connect(socket, SIGNAL(disconnected()), this, SLOT(catchSocketDisconnected()));
|
||||
|
||||
// Add this object to the server's list of connections before it can receive socket events.
|
||||
// Otherwise, in case a of a socket error, it could be removed from the list before it is added.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue