@@ -49,13 +49,27 @@ int send_command(lisp_cmd_t *cmd, int length)
49
49
{
50
50
51
51
int retval ;
52
-
53
- printf ("Cmd: 0x%x, cmd->length: %d" , cmd , cmd -> length );
54
- if ((retval = sendto (dsock_fd , cmd , sizeof (lisp_cmd_t ) + cmd -> length , 0 ,
55
- (struct sockaddr * )& server_sock , sizeof (struct sockaddr_un )) < 0 )) {
52
+ int retries = 2 ;
53
+ struct timeval tv ;
54
+
55
+ tv .tv_sec = 1 ; /* 1 second timeout */
56
+ tv .tv_usec = 0 ;
57
+
58
+ setsockopt (dsock_fd , SOL_SOCKET , SO_SNDTIMEO , (char * )& tv , sizeof (struct timeval ));
59
+ while (retries ) {
60
+ if ((retval = sendto (dsock_fd , cmd , sizeof (lisp_cmd_t ) + cmd -> length , 0 ,
61
+ (struct sockaddr * )& server_sock , sizeof (struct sockaddr_un )) < 0 )) {
62
+ retries -- ;
63
+ printf ("timeout error, retrying..." );
64
+ } else {
65
+ break ;
66
+ }
67
+ }
68
+ if (!retries ) {
56
69
printf ("Failed to send message, errno %d (%s)" , errno , strerror (errno ));
57
70
exit (-1 );
58
71
}
72
+
59
73
return retval ;
60
74
}
61
75
@@ -262,6 +276,11 @@ int process_print_cache_responses(void)
262
276
char * formatted_rloc = NULL ;
263
277
struct timeval uptime ;
264
278
struct timeval expiretime ;
279
+ int retries = 2 ;
280
+ struct timeval tv ;
281
+
282
+ tv .tv_sec = 1 ; /* 1 second timeout */
283
+ tv .tv_usec = 0 ;
265
284
266
285
if (!cmd ) {
267
286
printf ("Memory allocation failure\n" );
@@ -270,15 +289,15 @@ int process_print_cache_responses(void)
270
289
271
290
printf ("LISP IP Mapping Cache\n\n" );
272
291
292
+
293
+ setsockopt (dsock_fd , SOL_SOCKET , SO_RCVTIMEO , (char * )& tv , sizeof (struct timeval ));
273
294
while (1 ) {
274
295
if ((retval = recvfrom (dsock_fd , cmd , MAX_MSG_LENGTH , 0 , (struct sockaddr * )& server_sock ,
275
296
& addr_len )) < 0 ) {
276
- perror ("recv" );
277
297
break ;
278
298
}
279
299
if (!retval ) {
280
- printf ("Peer closed connection." );
281
- break ;
300
+ return (errno );
282
301
}
283
302
map_msg = (lisp_cache_response_msg_t * )cmd -> val ;
284
303
if (cmd -> type == LispOk ) {
@@ -602,6 +621,7 @@ int send_print_command(struct gengetopt_args_info *args_info)
602
621
lisp_cmd_t * cmd ;
603
622
int cmd_length = sizeof (lisp_cmd_t ) + sizeof (lisp_lookup_msg_t );
604
623
int retval ;
624
+ int retries = 2 ;
605
625
lisp_addr_t eid_prefix ;
606
626
int eid_prefix_len ;
607
627
int eid_af ;
@@ -689,10 +709,21 @@ int send_print_command(struct gengetopt_args_info *args_info)
689
709
690
710
retval = send_command (cmd , cmd_length );
691
711
692
- if (cache ) {
693
- process_print_cache_responses ();
694
- } else {
695
- process_print_db_responses ();
712
+ while (retries ) {
713
+ if (cache ) {
714
+ retval = process_print_cache_responses ();
715
+ } else {
716
+ retval = process_print_db_responses ();
717
+ }
718
+ if (retval == ETIMEDOUT ) {
719
+ retries -- ;
720
+ continue ;
721
+ } else {
722
+ if (retval != 0 ) {
723
+ printf ("Error waiting for response from lispd: %d" , errno );
724
+ }
725
+ break ;
726
+ }
696
727
}
697
728
return retval ;
698
729
}
0 commit comments