network: 解决吃子很快时网络对战时容易卡住的问题
This commit is contained in:
parent
6c2ed081d2
commit
e8a7f1c962
|
@ -152,7 +152,7 @@ void Server::sessionOpened()
|
|||
|
||||
void Server::setAction(const QString &action)
|
||||
{
|
||||
this->action = action;
|
||||
actions.push(action);
|
||||
}
|
||||
|
||||
void Server::sendAction()
|
||||
|
@ -161,6 +161,10 @@ void Server::sendAction()
|
|||
QDataStream out(&block, QIODevice::WriteOnly);
|
||||
out.setVersion(QDataStream::Qt_5_10);
|
||||
|
||||
if (!actions.empty()) {
|
||||
action = actions.front();
|
||||
}
|
||||
|
||||
out << action;
|
||||
|
||||
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
|
||||
|
@ -170,4 +174,8 @@ void Server::sendAction()
|
|||
|
||||
clientConnection->write(block);
|
||||
clientConnection->disconnectFromHost();
|
||||
|
||||
if (!actions.empty()) {
|
||||
actions.pop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QDialog>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <queue>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QLabel;
|
||||
|
@ -56,7 +57,7 @@ private:
|
|||
QTcpServer *tcpServer = nullptr;
|
||||
QNetworkSession *networkSession = nullptr;
|
||||
uint16_t port;
|
||||
QVector<QString> actions;
|
||||
std::queue<QString> actions;
|
||||
QString action;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue