summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/main.cpp b/main.cpp
index 9c1241e..4156126 100644
--- a/main.cpp
+++ b/main.cpp
@@ -49,6 +49,7 @@ int opt_add_node = 0;
int opt_delete_node = 0;
int opt_update_node = 0;
int opt_command = 0;
+int opt_timeout = 0;
char* command_command;
char* node_get_addr;
@@ -66,7 +67,7 @@ int timeout = TIMEOUT;
const char* cmd_stats = "stats";
const char* cmd_stats_reset = "stats reset";
-const char* cmd_node_list = "node list";
+const char* cmd_node_list = "node stats";
const char* cmd_node_config = "node config";
const char* cmd_node_update = "node update";
const char* cmd_node_delete = "node delete";
@@ -215,8 +216,15 @@ void runCmd(const char *command) {
char receiveMessage[MAX_RECEIVED_BYTES];
struct timeval tv;
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
+
+ if (opt_timeout) {
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ } else {
+ // set initial timeout to 5 seconds
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ }
receiveStream.str("");
receiveStream.clear();
@@ -238,6 +246,10 @@ void runCmd(const char *command) {
return;
}
+ // Lower timeout for subsequent reads
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+
sendto(sockfd, command, strlen(command), 0, (struct sockaddr *) &servaddr, sizeof(servaddr));
while (1) {
@@ -246,6 +258,13 @@ void runCmd(const char *command) {
/*printf("timeout\n");*/
break;
}
+
+ // Lower timeout for subsequent reads
+ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
+ printError("setsockopt error\n");
+ return;
+ }
+
receiveStream << std::string(receiveMessage, receiveBytes);
}
}
@@ -459,6 +478,7 @@ void parseOptions(int argc, char** argv) {
break;
}
case 't': {
+ opt_timeout = 1;
timeout = atoi(optarg);
break;
}