]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/netunit.cpp
Ticket. The MaybeSet() function call for the 'change-policy' parameter added in
[stg.git] / stglibs / srvconf.lib / netunit.cpp
index 42b301a5a515c249429901446032775352518fae..6515158727ae6ce4f141ddc44ebb0d5d4ea31e36 100644 (file)
@@ -27,7 +27,6 @@
 
 #include <algorithm> // std::min
 
 
 #include <algorithm> // std::min
 
-#include <cstdio>
 #include <cerrno>
 #include <cstring>
 #include <cassert>
 #include <cerrno>
 #include <cstring>
 #include <cassert>
 #include <sys/socket.h>
 #include <netinet/in.h>
 
 #include <sys/socket.h>
 #include <netinet/in.h>
 
+const char STG_HEADER[] = "SG04";
+const char OK_HEADER[]  = "OKHD";
+const char ERR_HEADER[] = "ERHD";
+const char OK_LOGIN[]   = "OKLG";
+const char ERR_LOGIN[]  = "ERLG";
+const char OK_LOGINS[]  = "OKLS";
+const char ERR_LOGINS[] = "ERLS";
+
 using namespace STG;
 
 namespace
 using namespace STG;
 
 namespace
@@ -57,19 +64,18 @@ struct ReadState
 
 //---------------------------------------------------------------------------
 
 
 //---------------------------------------------------------------------------
 
-#define SEND_DATA_ERROR             "Send data error!"
-#define RECV_DATA_ANSWER_ERROR      "Recv data answer error!"
-#define UNKNOWN_ERROR               "Unknown error!"
-#define CONNECT_FAILED              "Connect failed!"
-#define BIND_FAILED                 "Bind failed!"
-#define INCORRECT_LOGIN             "Incorrect login!"
-#define INCORRECT_HEADER            "Incorrect header!"
-#define SEND_LOGIN_ERROR            "Send login error!"
-#define RECV_LOGIN_ANSWER_ERROR     "Recv login answer error!"
-#define CREATE_SOCKET_ERROR         "Create socket failed!"
-#define WSASTARTUP_FAILED           "WSAStartup failed!"
-#define SEND_HEADER_ERROR           "Send header error!"
-#define RECV_HEADER_ANSWER_ERROR    "Recv header answer error!"
+const char SEND_DATA_ERROR[]          = "Error sending data.";
+const char RECV_DATA_ANSWER_ERROR[]   = "Error receiving data answer.";
+const char UNKNOWN_ERROR[]            = "Unknown error";
+const char CONNECT_FAILED[]           = "Failed to connect.";
+const char BIND_FAILED[]              = "Failed to bind.";
+const char INCORRECT_LOGIN[]          = "Incorrect login.";
+const char INCORRECT_HEADER[]         = "Incorrect header.";
+const char SEND_LOGIN_ERROR[]         = "Error sending login.";
+const char RECV_LOGIN_ANSWER_ERROR[]  = "Error receiving login answer.";
+const char CREATE_SOCKET_ERROR[]      = "Failed to create socket.";
+const char SEND_HEADER_ERROR[]        = "Error sending header.";
+const char RECV_HEADER_ANSWER_ERROR[] = "Error receiving header answer.";
 
 //---------------------------------------------------------------------------
 NETTRANSACT::NETTRANSACT(const std::string & s, uint16_t p,
 
 //---------------------------------------------------------------------------
 NETTRANSACT::NETTRANSACT(const std::string & s, uint16_t p,
@@ -233,7 +239,6 @@ char buffer[sizeof(STG_HEADER) + 1];
 
 if (!ReadAll(sock, buffer, strlen(OK_HEADER)))
     {
 
 if (!ReadAll(sock, buffer, strlen(OK_HEADER)))
     {
-    printf("Receive header answer error: '%s'\n", strerror(errno));
     errorMsg = RECV_HEADER_ANSWER_ERROR;
     return st_recv_fail;
     }
     errorMsg = RECV_HEADER_ANSWER_ERROR;
     return st_recv_fail;
     }
@@ -274,7 +279,6 @@ char buffer[sizeof(OK_LOGIN) + 1];
 
 if (!ReadAll(sock, buffer, strlen(OK_LOGIN)))
     {
 
 if (!ReadAll(sock, buffer, strlen(OK_LOGIN)))
     {
-    printf("Receive login answer error: '%s'\n", strerror(errno));
     errorMsg = RECV_LOGIN_ANSWER_ERROR;
     return st_recv_fail;
     }
     errorMsg = RECV_LOGIN_ANSWER_ERROR;
     return st_recv_fail;
     }
@@ -317,7 +321,6 @@ char buffer[sizeof(OK_LOGINS) + 1];
 
 if (!ReadAll(sock, buffer, strlen(OK_LOGINS)))
     {
 
 if (!ReadAll(sock, buffer, strlen(OK_LOGINS)))
     {
-    printf("Receive secret login answer error: '%s'\n", strerror(errno));
     errorMsg = RECV_LOGIN_ANSWER_ERROR;
     return st_recv_fail;
     }
     errorMsg = RECV_LOGIN_ANSWER_ERROR;
     return st_recv_fail;
     }
@@ -360,7 +363,6 @@ while (!state.final)
     ssize_t res = read(sock, buffer, sizeof(buffer));
     if (res < 0)
         {
     ssize_t res = read(sock, buffer, sizeof(buffer));
     if (res < 0)
         {
-        printf("Receive data error: '%s'\n", strerror(errno));
         errorMsg = RECV_DATA_ANSWER_ERROR;
         return st_recv_fail;
         }
         errorMsg = RECV_DATA_ANSWER_ERROR;
         return st_recv_fail;
         }