Commit 48a42b72 by ss.dai

去掉soket状态检测

parent 0a48c0b8
...@@ -31,6 +31,9 @@ void RefundControl::run() ...@@ -31,6 +31,9 @@ void RefundControl::run()
{ {
QLOG_WARN() << QString("tcp server listen failed on port[%1]").arg(m_port); QLOG_WARN() << QString("tcp server listen failed on port[%1]").arg(m_port);
return; return;
}else
{
QLOG_INFO() << QString("tcp server listened on port[%1]").arg(m_port);
} }
m_bContinue = true; m_bContinue = true;
...@@ -41,29 +44,32 @@ void RefundControl::run() ...@@ -41,29 +44,32 @@ void RefundControl::run()
QJsonDocument jsonDoc; QJsonDocument jsonDoc;
while(m_bContinue) while(m_bContinue)
{ {
QLOG_INFO() << "waiting new connection....";
if(!m_tcpServer->waitForNewConnection(60000)) if(!m_tcpServer->waitForNewConnection(60000))
{ {
continue; continue;
} }
if(QAbstractSocket::UnknownSocketError != m_tcpServer->serverError())
{
continue;
}
QLOG_INFO() << "onNewConnecion....."; 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 error;
QString orderId, reason; int version, reqtype; QString orderId, reason; int version, reqtype;
m_tcpSocket = m_tcpServer->nextPendingConnection(); m_tcpSocket = m_tcpServer->nextPendingConnection();
if(!m_tcpSocket->waitForReadyRead()) if(!m_tcpSocket->waitForReadyRead())
{ {
QLOG_INFO() << "read failed";
m_tcpSocket->close(); m_tcpSocket->close();
continue; continue;
} }
recvData = m_tcpSocket->readAll(); recvData = m_tcpSocket->readAll();
QLOG_INFO() << QString("recv data.[%1]").arg(QString(recvData)); 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) if(jsonError.error == QJsonParseError::NoError)
{ {
QJsonObject jsonObject = jsonDoc.object(); QJsonObject jsonObject = jsonDoc.object();
...@@ -89,11 +95,11 @@ void RefundControl::run() ...@@ -89,11 +95,11 @@ void RefundControl::run()
.arg(QString(QJsonDocument(httpRecvJson).toJson(QJsonDocument::Compact).replace("\"",""))); .arg(QString(QJsonDocument(httpRecvJson).toJson(QJsonDocument::Compact).replace("\"","")));
if(httpResult) if(httpResult)
{ {
if(100 == httpRecvJson["status"].toInt()) if(100 == httpRecvJson["statusCode"].toInt())
{ {
replyData = QString("{\"ver\":1, \"order_id\":\"%1\", \"statusCode\":100, \"msg\":\"\"}").arg(orderId); replyData = QString("{\"ver\":1, \"order_id\":\"%1\", \"statusCode\":100, \"msg\":\"\"}").arg(orderId);
m_tcpSocket->write(replyData.toUtf8()); m_tcpSocket->write(replyData.toUtf8());
m_tcpSocket->waitForBytesWritten(); m_tcpSocket->waitForBytesWritten(5000);
m_tcpSocket->close(); m_tcpSocket->close();
continue; continue;
}else }else
...@@ -120,7 +126,7 @@ void RefundControl::run() ...@@ -120,7 +126,7 @@ void RefundControl::run()
// 发生错误 // 发生错误
replyData = QString("{\"ver\":1, \"order_id\":\"%1\", \"statusCode\":101, \"msg\":\"%2\"}").arg(orderId).arg(error); replyData = QString("{\"ver\":1, \"order_id\":\"%1\", \"statusCode\":101, \"msg\":\"%2\"}").arg(orderId).arg(error);
m_tcpSocket->write(replyData.toUtf8()); m_tcpSocket->write(replyData.toUtf8());
m_tcpSocket->waitForBytesWritten(); m_tcpSocket->waitForBytesWritten(5000);
m_tcpSocket->close(); m_tcpSocket->close();
continue; 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