#include "base/rebase.hpp"\r
#include "math/remath.hpp"\r
#include "os/reos.hpp"\r
+#include "net/renet.hpp"\r
\r
enum LOCATION_DIRTOOL {\r
LC_COPY_FILE_1 = LC_DIRTOOLS + 1, // 50101\r
LC_COMPARE_DIR_1, // 50122\r
LC_DELETE_1, // 50123\r
};\r
-const char* ReDirTools::m_version = "2015.03.04";\r
+const char* ReDirTools::m_version = "2015.03.09";\r
ReLogger* ReDirTools::m_logger = NULL;\r
\r
static const char* s_helpSummary[] = { "dirtool or dt <command> <opts>",\r
"dirtool sync --type=r --max-size=1G usr etc /media/backup",\r
NULL };\r
\r
+const char* s_tcpUsage[] =\r
+ { "<command>: tcp [<opts>] <subcommand> [<param> ...]",\r
+ " test tool for network test",\r
+ "<subcommand>:",\r
+ " server",\r
+ " client <ip> [<rounds> [<print_interval>]]",\r
+ " <ip>: URL of the server",\r
+ " <rounds>: number of messages to send",\r
+ NULL };\r
+const char* s_tcpExamples[] = {\r
+ "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
+ NULL };\r
+\r
+\r
const char* s_touchUsage[] =\r
{ "<command>: touch [<opts>] <dir_or_file1> [<dir_or_file2> ...]",\r
" sets the filetimes (modification and/or access time) of the selected files",\r
}\r
}\r
\r
+/**\r
+ * Constructor.\r
+ *\r
+ * @param logger logger for error handling\r
+ */\r
+ReDirTCP::ReDirTCP(ReLogger* logger) :\r
+ ReTool(s_tcpUsage, s_tcpExamples, 1, 0, 0, true, logger) {\r
+ m_hasStandardArgs = false;\r
+ m_programArgs.addInt("size", i18n("size of the message to send/receive (in KiByte)"),\r
+ 'b', "--buffer-size", 64);\r
+ m_programArgs.addInt("port", i18n("port of the server/client"),\r
+ 'p', "--port", 58111);\r
+}\r
+\r
+/**\r
+ * Lists the metadata of the specified files.\r
+ */\r
+void ReDirTCP::doIt() {\r
+ int port = m_programArgs.getInt("port");\r
+ int bufferSize = m_programArgs.getInt("size") * 1024;\r
+\r
+ const char* command = m_programArgs.getArg(0);\r
+ if (_stricmp(command, "server") == 0){\r
+ ReTCPEchoServer server(port, m_logger);\r
+ server.listenForAll();\r
+ } else if (_stricmp(command, "client") == 0){\r
+ const char* ip = m_programArgs.getArg(1);\r
+ int rounds = 10;\r
+ int interval = 5;\r
+ if (m_programArgs.getArgCount() > 2)\r
+ rounds = atoi(m_programArgs.getArg(2));\r
+ if (m_programArgs.getArgCount() > 3)\r
+ interval = atoi(m_programArgs.getArg(3));\r
+ ReTCPClient client(m_logger);\r
+ if (client.connect(ip, port)){\r
+ time_t start = time(NULL);\r
+ int64_t millisec;\r
+ ReByteBuffer message;\r
+ message.appendChar('x', bufferSize);\r
+ time_t lastPrint = start;\r
+ int64_t size = 0;\r
+ int duration = 0;\r
+ for (int ii = 0; ii < rounds; ii++){\r
+ client.send("strlen", message.str(), message.length());\r
+ size += message.length();\r
+ time_t now = time(NULL);\r
+ if (now >= lastPrint + interval){\r
+ duration = int(now - start);\r
+ printf("%2d: %9.3f MiByte %8.3f kiByte/sec\n", ii,\r
+ size / 1024.0 / 1024, (double) size / duration / 1024);\r
+ lastPrint = now;\r
+ }\r
+ }\r
+ duration = int(time(NULL) - start);\r
+ if (duration == 0)\r
+ duration = 1;\r
+ printf("%2d: %9.3f MiByte %8.3f kiByte/sec\n", rounds, size / 1024.0 / 1024,\r
+ (double) size / duration / 1024);\r
+\r
+ }\r
+ } else\r
+ help("unknown subcommand: $1", command);\r
+\r
+}\r
+\r
+\r
/**\r
* Constructor.\r
*\r
} else if (isArg("test", arg0)) {\r
void testAll();\r
testAll();\r
+ } else if (isArg("tcp", arg0)) {\r
+ ReDirTCP(m_logger).help(NULL);\r
} else if (isArg("touch", arg0)) {\r
ReDirTouch(m_logger).help(NULL);\r
} else if (isArg("which", arg0)) {\r
ReDirStatistic(m_logger).run(argc, argv);\r
else if (isArg("synchronize", arg0))\r
ReDirSync(m_logger).run(argc, argv);\r
+ else if (isArg("tcp", arg0))\r
+ ReDirTCP(m_logger).run(argc, argv);\r
else if (isArg("touch", arg0))\r
ReDirTouch(m_logger).run(argc, argv);\r
else if (isArg("which", arg0))\r