Commit 998c40cb authored by Leigh B. Stoller's avatar Leigh B. Stoller

Add timeout option for use with UDP mode; sets a timeout to quit

waiting for a reply. I'm using this as part of the (30 minute hack)
widearea node keepalive support.
parent 93640db0
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
void sigcatcher(int foo); void sigcatcher(int foo);
char *getbossnode(void); char *getbossnode(void);
#ifdef UDP #ifdef UDP
void doudp(int, char **, int, struct in_addr, int, char *); void doudp(int, char **, int, struct in_addr, int, char *, int);
#endif #endif
char *usagestr = char *usagestr =
...@@ -43,6 +43,7 @@ char *usagestr = ...@@ -43,6 +43,7 @@ char *usagestr =
" -v versnum Specify a version number for tmcd\n" " -v versnum Specify a version number for tmcd\n"
" -n vnodeid Specify the vnodeid\n" " -n vnodeid Specify the vnodeid\n"
" -u Use UDP instead of TCP\n" " -u Use UDP instead of TCP\n"
" -t timeout Timeout waiting for a reply from master (UDP ONLY).\n"
"\n"; "\n";
void void
...@@ -65,12 +66,13 @@ main(int argc, char **argv) ...@@ -65,12 +66,13 @@ main(int argc, char **argv)
int version = CURRENT_VERSION; int version = CURRENT_VERSION;
char *vnodeid = NULL; char *vnodeid = NULL;
#ifdef UDP #ifdef UDP
int useudp = 0; int waitfor = 0;
int useudp = 0;
#endif #endif
portnum = TBSERVER_PORT; portnum = TBSERVER_PORT;
while ((ch = getopt(argc, argv, "v:s:p:un:")) != -1) while ((ch = getopt(argc, argv, "v:s:p:un:t:")) != -1)
switch(ch) { switch(ch) {
case 'p': case 'p':
portnum = atoi(optarg); portnum = atoi(optarg);
...@@ -85,6 +87,9 @@ main(int argc, char **argv) ...@@ -85,6 +87,9 @@ main(int argc, char **argv)
version = atoi(optarg); version = atoi(optarg);
break; break;
#ifdef UDP #ifdef UDP
case 't':
waitfor = atoi(optarg);
break;
case 'u': case 'u':
useudp = 1; useudp = 1;
break; break;
...@@ -139,7 +144,8 @@ main(int argc, char **argv) ...@@ -139,7 +144,8 @@ main(int argc, char **argv)
#ifdef UDP #ifdef UDP
if (useudp) { if (useudp) {
doudp(argc, argv, version, serverip, portnum, vnodeid); doudp(argc, argv,
version, serverip, portnum, vnodeid, waitfor);
/* /*
* Never returns. * Never returns.
*/ */
...@@ -285,7 +291,8 @@ getbossnode(void) ...@@ -285,7 +291,8 @@ getbossnode(void)
*/ */
void void
doudp(int argc, char **argv, doudp(int argc, char **argv,
int vers, struct in_addr serverip, int portnum, char *vnodeid) int vers, struct in_addr serverip, int portnum, char *vnodeid,
int waitfor)
{ {
int sock, length, n, cc; int sock, length, n, cc;
struct sockaddr_in name, client; struct sockaddr_in name, client;
...@@ -339,8 +346,12 @@ doudp(int argc, char **argv, ...@@ -339,8 +346,12 @@ doudp(int argc, char **argv,
exit(1); exit(1);
} }
if (waitfor) {
alarm(waitfor);
}
cc = recvfrom(sock, buf, sizeof(buf), 0, cc = recvfrom(sock, buf, sizeof(buf), 0,
(struct sockaddr *)&client, &length); (struct sockaddr *)&client, &length);
if (cc < 0) { if (cc < 0) {
perror("Reading from socket:"); perror("Reading from socket:");
exit(1); exit(1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment