Commit 48a42b72 by ss.dai

去掉soket状态检测

parent 0a48c0b8
......@@ -31,6 +31,9 @@ void RefundControl::run()
{
QLOG_WARN() << QString("tcp server listen failed on port[%1]").arg(m_port);
return;
}else
{
QLOG_INFO() << QString("tcp server listened on port[%1]").arg(m_port);
}
m_bContinue = true;
......@@ -41,29 +44,32 @@ void RefundControl::run()
QJsonDocument jsonDoc;
while(m_bContinue)
{
QLOG_INFO() << "waiting new connection....";
if(!m_tcpServer->waitForNewConnection(60000))
{
continue;
}
if(QAbstractSocket::UnknownSocketError != m_tcpServer->serverError())
{
continue;
}
QLOG_INFO() << "onNewConnecion.....";
// if(QAbstractSocket::UnknownSocketError != m_tcpServer->serverError())
// {
// QLOG_INFO() << QString("0socket error %1").arg(m_tcpServer->serverError().errorString());
// continue;
// }
// QLOG_INFO() << QString("1socket error %1").arg(m_tcpServer->serverError().errorString());
QString error;
QString orderId, reason; int version, reqtype;
m_tcpSocket = m_tcpServer->nextPendingConnection();
if(!m_tcpSocket->waitForReadyRead())
{
QLOG_INFO() << "read failed";
m_tcpSocket->close();
continue;
}
recvData = m_tcpSocket->readAll();
QLOG_INFO() << QString("recv data.[%1]").arg(QString(recvData));
jsonDoc = QJsonDocument::fromJson(recvData, &jsonError);
jsonDoc = QJsonDocument::fromJson(QString::fromUtf8(recvData).toUtf8(), &jsonError);
if(jsonError.error == QJsonParseError::NoError)
{
QJsonObject jsonObject = jsonDoc.object();
......@@ -89,11 +95,11 @@ void RefundControl::run()
.arg(QString(QJsonDocument(httpRecvJson).toJson(QJsonDocument::Compact).replace("\"","")));
if(httpResult)
{
if(100 == httpRecvJson["status"].toInt())
if(100 == httpRecvJson["statusCode"].toInt())
{
replyData = QString("{\"ver\":1, \"order_id\":\"%1\", \"statusCode\":100, \"msg\":\"\"}").arg(orderId);
m_tcpSocket->write(replyData.toUtf8());
m_tcpSocket->waitForBytesWritten();
m_tcpSocket->waitForBytesWritten(5000);
m_tcpSocket->close();
continue;
}else
......@@ -120,7 +126,7 @@ void RefundControl::run()
// 发生错误
replyData = QString("{\"ver\":1, \"order_id\":\"%1\", \"statusCode\":101, \"msg\":\"%2\"}").arg(orderId).arg(error);
m_tcpSocket->write(replyData.toUtf8());
m_tcpSocket->waitForBytesWritten();
m_tcpSocket->waitForBytesWritten(5000);
m_tcpSocket->close();
continue;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment