]> gitweb.hamatoma.de Git - crepublib/commitdiff
dirtool tcp
authorhama <hama@siduction.net>
Thu, 19 Mar 2015 22:41:56 +0000 (23:41 +0100)
committerhama <hama@siduction.net>
Thu, 19 Mar 2015 22:41:56 +0000 (23:41 +0100)
base/ReThread.cpp
net/ReTCP.cpp
os/ReDirTools.cpp

index 95706a90e160b2cd5a830343cf526bb0fe2a0b0e..b7f638a02b459e94b99d7f67e0717484e1832411 100644 (file)
@@ -108,12 +108,12 @@ bool ReThread::prepareToRun(int id, ReLogger* masterLogger,
  */\r
 void ReThread::runAndFinish() {\r
        run();\r
+       m_isStopped = true;\r
 #if defined __linux__\r
        pthread_exit(NULL);\r
 #elif defined __WIN32__\r
        // Nothing to do\r
 #endif\r
-       m_isStopped = true;\r
 }\r
 \r
 /**\r
index 6374762b48fc46c215828fc0827d4d1f027a3163..cd938e73078921e6940e88e0a829b465b6acec48 100644 (file)
@@ -12,7 +12,7 @@ enum LOCATION_DIRTOOL {
        LC_LISTEN_FOR_ALL_1 = LC_TCP + 1, // 50501\r
        LC_LISTEN_FOR_ALL_2,    // 50502\r
        LC_LISTEN_FOR_ALL_3,    // 50503\r
-       LC_LISTEN_FOR_ALL_4,    // 50504\r
+       LC_RECEIVE_5,                   // 50504\r
        LC_LISTEN_FOR_ALL_5,    // 50505\r
        LC_LISTEN_FOR_ALL_6,    // 50506\r
        LC_WRITE_1,                     // 50507\r
@@ -28,7 +28,9 @@ enum LOCATION_DIRTOOL {
        LC_CONNECT_3,                   // 50517\r
        LC_TCP_CONNECTION_1,    // 50518\r
        LC_WRITE_2,                             // 50519\r
-       LC_RECEIVE_5,                   // 50520\r
+       LC_SERVER_CONNECTION_RUN_1,     // 50520\r
+       LC_SERVER_CONNECTION_RUN_2,     // 50521\r
+       LC_SERVER_CONNECTION_RUN_3,     // 50522\r
 };\r
 \r
 #if defined __WIN32__\r
@@ -290,9 +292,12 @@ void ReTCPConnection::receive(ReByteBuffer& command, ReByteBuffer& data) {
                                    LC_RECEIVE_4, i18n("too few bytes read: $1/$2 [$3]")).arg(\r
                                    readBytes).arg(received).arg(m_peerName).end();\r
                        } else {\r
-                               m_loggerOwner->logger()->sayF(LOG_DEBUG | CAT_NETWORK, LC_RECEIVE_5,\r
-                                       i18n("received: $1 bytes in $2 round(s) [$3]: $4")).arg(length).arg(rounds).arg(\r
-                                       m_peerName).arg(ReByteBuffer().appendDump(data.str(), data.length(), 80).str()).end();\r
+                               m_loggerOwner->logger()->sayF(LOG_DEBUG | CAT_NETWORK,\r
+                                   LC_RECEIVE_5,\r
+                                   i18n("received: $1 bytes in $2 round(s) [$3]: $4")).arg(\r
+                                   length).arg(rounds).arg(m_peerName).arg(\r
+                                   ReByteBuffer().appendDump(data.str(), data.length(), 80).str())\r
+                                   .end();\r
                        }\r
                        command.setLength(0);\r
                        if (readBytes >= 8) {\r
@@ -317,11 +322,11 @@ void ReTCPConnection::send(const char* command, const char* data, int length) {
        ++m_noSent;\r
        m_toSend.setLength(0);\r
        int flags = 0x7b;\r
+       // add command length:\r
        int rest = length + 8;\r
-       m_toSend.appendInt(length | (flags << 24), "%08x");\r
+       m_toSend.appendInt(rest | (flags << 24), "%08x");\r
        m_toSend.appendFix(command, -1, 8, 8, NULL);\r
        m_toSend.append(data, length);\r
-       rest += 8;\r
        int sent = 0;\r
        const char* buf = m_toSend.str();\r
        int rounds = 0;\r
@@ -338,8 +343,9 @@ void ReTCPConnection::send(const char* command, const char* data, int length) {
        }\r
        if (rest == 0)\r
                m_loggerOwner->logger()->sayF(LOG_DEBUG | CAT_NETWORK, LC_WRITE_2,\r
-                           i18n("sent: $1 bytes in $2 round(s): $3 $4")).arg(length).arg(rounds)\r
-                               .arg(command).arg(ReByteBuffer().appendDump(data, length, 80).str()).end();\r
+                   i18n("sent: $1 bytes in $2 round(s): $3 $4")).arg(length).arg(\r
+                   rounds).arg(command).arg(\r
+                   ReByteBuffer().appendDump(data, length, 80).str()).end();\r
 }\r
 \r
 /**\r
@@ -369,6 +375,9 @@ ReTCPServerConnection::~ReTCPServerConnection() {
 void ReTCPServerConnection::run() {\r
        ReByteBuffer command;\r
        ReNetCommandHandler::ProcessingState rc = ReNetCommandHandler::PS_UNDEF;\r
+       m_loggerOwner->logger()->sayF(LOG_INFO | CAT_NETWORK,\r
+           LC_SERVER_CONNECTION_RUN_1, i18n("new connection to $1"))\r
+           .arg(m_name).end();\r
        do {\r
                receive(command, m_received);\r
                rc = m_server->handler().handleNetCommand(command, m_received, this);\r
@@ -377,10 +386,16 @@ void ReTCPServerConnection::run() {
                            i18n("unknown command: $1 length: $2")).arg(command).arg(\r
                            m_received.length()).end();\r
                }\r
-       } while (rc != ReNetCommandHandler::PS_STOP && ! m_shouldStop);\r
-       if (rc != ReNetCommandHandler::PS_STOP)\r
-               m_pool->setShouldStop();\r
+       } while (rc != ReNetCommandHandler::PS_STOP && !m_shouldStop);\r
+       m_pool->setShouldStop();\r
        close();\r
+       if (rc == ReNetCommandHandler::PS_STOP)\r
+               m_loggerOwner->logger()->sayF(LOG_INFO | CAT_NETWORK,\r
+                       LC_SERVER_CONNECTION_RUN_2, i18n("stop signal received from $1"))\r
+                       .arg(m_name).end();\r
+       else\r
+               m_loggerOwner->logger()->say(LOG_INFO | CAT_NETWORK,\r
+                       LC_SERVER_CONNECTION_RUN_3, i18n("stop order received"));\r
        m_id = -1;\r
 }\r
 \r
@@ -509,9 +524,7 @@ bool ReTCPServer::listenForAll() {
                        socklen_t lengthAddr = sizeof(struct sockaddr_in);\r
                        while ((clientSocket = accept(m_handleSocket,\r
                            (struct sockaddr *) &addrClient, &lengthAddr)) != 0) {\r
-                               if (! pool.shouldStop()) {\r
-                                       m_logger->sayF(LOG_INFO | CAT_NETWORK, LC_LISTEN_FOR_ALL_4,\r
-                                           i18n("accepted: $1")).arg(m_port).end();\r
+                               if (!pool.shouldStop()) {\r
                                        if (m_countConnections >= m_maxConnections) {\r
                                                // close the connection at once:\r
                                                m_logger->sayF(LOG_WARNING | CAT_NETWORK,\r
@@ -523,7 +536,6 @@ bool ReTCPServer::listenForAll() {
                                        } else {\r
                                                ReTCPServerConnection* connection = createConnection(\r
                                                    nextId++, clientSocket, addrClient);\r
-\r
                                                if (!pool.startThread(connection)) {\r
                                                        m_logger->sayF(LOG_ERROR | CAT_PROCESS,\r
                                                            LC_LISTEN_FOR_ALL_6,\r
@@ -531,6 +543,8 @@ bool ReTCPServer::listenForAll() {
                                                            getLastOSError()).end();\r
                                                        reCloseSocket(clientSocket);\r
                                                        clientSocket = -1;\r
+                                               } else {\r
+\r
                                                }\r
                                        }\r
                                }\r
index 553c9b4f2a62d9adc2a0247e0663e7edd682ba28..b054fae989a5a1ea2fb4390f9cf633490a20cc95 100644 (file)
@@ -144,8 +144,8 @@ const char* s_tcpUsage[] = {
     "   <direction>: 'upload', 'download' or 'mixed'",\r
     NULL };\r
 const char* s_tcpExamples[] = { "dirtool tcp -p 5555 server",\r
-    "dirtool tcp -p 5555 client localhost 10000 10",\r
-    "dirtool tcp -p 5555 --buffer-size=1024 client 192.168.7.3 10 25",\r
+    "dirtool tcp -p 5555 client localhost download 10000 10",\r
+    "dirtool tcp -p 5555 --buffer-size=1024 client 192.168.7.3 upload 10 25",\r
     NULL };\r
 \r
 const char* s_touchUsage[] =\r
@@ -2405,7 +2405,6 @@ void ReDirTCP::doIt() {
                            tolower(direction.at(0)) == 'u');\r
        } else\r
                help("unknown subcommand: $1", command.str());\r
-\r
 }\r
 void ReDirTCP::runMixedClient(const char* ip, int port, int rounds,\r
     int interval, int bufferSize) {\r
@@ -2419,9 +2418,9 @@ void ReDirTCP::runOneThreadClient(const char* ip, int port, int rounds,
                const char* command = upload ? "strlen" : "filldata";\r
                ReByteBuffer message;\r
                if (upload)\r
-                       message.appendInt(bufferSize);\r
-               else\r
                        message.appendChar('x', bufferSize);\r
+               else\r
+                       message.appendInt(bufferSize);\r
                time_t lastPrint = start;\r
                int64_t size = 0;\r
                int duration = 0;\r
@@ -2634,6 +2633,7 @@ int ReDirTools::main(int argc, char* orgArgv[]) {
                testAll();\r
        } else\r
                tools.usage("unknown command: ", argv[1]);\r
+       ReTCPServer::globalClose();\r
        return 0;\r
 }\r
 \r