First version of ATBUpdateCheck
This commit is contained in:
@@ -112,19 +112,23 @@ void IsmasClient::printErrorMessage(int port,
|
||||
}
|
||||
|
||||
std::optional<QString>
|
||||
IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
IsmasClient::sendRequestReceiveResponse(int port, QString const &request, bool verbose) {
|
||||
|
||||
qInfo() << "REQUEST" << request;
|
||||
if (verbose) {
|
||||
qInfo() << "REQUEST" << request;
|
||||
}
|
||||
|
||||
int sockfd;
|
||||
int r;
|
||||
errno = 0;
|
||||
// socket create and verification
|
||||
if ((sockfd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||
qCritical().noquote()
|
||||
<< "\n"
|
||||
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
||||
<< "SOCKET CREATION FAILED (" << strerror(errno) << ")";
|
||||
if (verbose) {
|
||||
qCritical().noquote()
|
||||
<< "\n"
|
||||
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
||||
<< "SOCKET CREATION FAILED (" << strerror(errno) << ")";
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -137,10 +141,12 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
servAddr.sin_port = htons(port);
|
||||
// connect the client socket to server socket
|
||||
if ((r = ::connect(sockfd, (struct sockaddr *)(&servAddr), sizeof(servAddr))) != 0) {
|
||||
qCritical().noquote()
|
||||
<< "\n"
|
||||
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
||||
<< "CONNECTION WITH SERVER FAILED (" << strerror(r) << ")";
|
||||
if (verbose) {
|
||||
qCritical().noquote()
|
||||
<< "\n"
|
||||
<< "SEND-REQUEST-RECEIVE-RESPONSE ..." << "\n"
|
||||
<< "CONNECTION WITH SERVER FAILED (" << strerror(r) << ")";
|
||||
}
|
||||
::close(sockfd);
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -155,7 +161,9 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
inet_ntop(AF_INET, &clientAddr.sin_addr, clientIP, sizeof(clientIP));
|
||||
unsigned int clientPort = ntohs(clientAddr.sin_port);
|
||||
|
||||
printDebugMessage(port, clientIP, clientPort, QString("CONNECTED TO SERVER"));
|
||||
if (verbose) {
|
||||
printDebugMessage(port, clientIP, clientPort, QString("CONNECTED TO SERVER"));
|
||||
}
|
||||
|
||||
struct timeval tv;
|
||||
tv.tv_sec = 10; /* 10 secs timeout for read and write */
|
||||
@@ -244,7 +252,9 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
// QString("CANNOT CLOSE WRITING END (") + strerror(errno) + ")");
|
||||
// }
|
||||
|
||||
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT <<<") + buf + ">>>");
|
||||
if (verbose) {
|
||||
printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT <<<") + buf + ">>>");
|
||||
}
|
||||
|
||||
loop = 0;
|
||||
bzero(buf, sizeof(buf));
|
||||
@@ -325,7 +335,9 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
response = response.mid(0, idx);
|
||||
} else
|
||||
if (response.contains("RECORD")) { // RECORD SAVED or RECORD WRITE ABORTED
|
||||
printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE");
|
||||
if (verbose) {
|
||||
printInfoMessage(port, clientIP, clientPort, QString("IGNORED '") + response + "' RESPONSE");
|
||||
}
|
||||
::close(sockfd);
|
||||
return std::nullopt;
|
||||
}
|
||||
@@ -334,8 +346,10 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) {
|
||||
QJsonDocument document(QJsonDocument::fromJson(response.toUtf8(), &parseError));
|
||||
if (parseError.error == QJsonParseError::NoError) {
|
||||
if (document.isObject()) { // done: received valid APISM response
|
||||
printInfoMessage(port, clientIP, clientPort,
|
||||
QString("VALID APISM RESPONSE .. \n") + response);
|
||||
if (verbose) {
|
||||
printInfoMessage(port, clientIP, clientPort,
|
||||
QString("VALID APISM RESPONSE .. \n") + response);
|
||||
}
|
||||
::close(sockfd);
|
||||
return response;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user