From 6e3fe903d9f63714c3c5611c3c6476f6254163dc Mon Sep 17 00:00:00 2001 From: gardners Date: Wed, 21 Mar 2012 03:27:47 +1030 Subject: [PATCH] Improved shutdown behaviour to properly handle client mode (don't delete server socket if you are a client). Also added main MDP ping loop of sending packets. Reading returned packets not yet implemented. Server handling of MDP_TX packets also not yet implemented. --- commandline.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- dna.c | 8 ++++++-- overlay_mdp.c | 11 +++++++++++ serval.h | 2 ++ 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/commandline.c b/commandline.c index 3298592d..22664e75 100644 --- a/commandline.c +++ b/commandline.c @@ -383,7 +383,52 @@ int app_mdp_ping(int argc,char **argv,struct command_line_option *o) return -1; } - return WHY("MDP ping not implemented (we don't send the packet)"); + /* First sequence number in the echo frames */ + unsigned int firstSeq=random(); + unsigned int sequence_number=firstSeq; + + while(1) { + int i; + /* Now send the ping packets */ + mdp.packetTypeAndFlags=MDP_TX; + /* Set destination to broadcast */ + for(i=0;i0) { + fprintf(stderr,"Frames ready for reception.\n"); + } + now=overlay_gettime_ms(); + if (servalShutdown) { + /* XXX Report final statistics before going */ + return 0; + } + } + timeout=now+1000; + } + + return 0; } int app_server_set(int argc,char **argv,struct command_line_option *o) diff --git a/dna.c b/dna.c index 01607f06..bf5686a5 100644 --- a/dna.c +++ b/dna.c @@ -305,8 +305,12 @@ void servalShutdownCleanly() unlink(filename); snprintf(filename,1024,"%s/serval.pid",instancepath); unlink(filename); - snprintf(filename,1024,"%s/mdp.socket",instancepath); - unlink(filename); + if (mdp_client_socket==-1) { + snprintf(filename,1024,"%s/mdp.socket",instancepath); + unlink(filename); + } else { + overlay_mdp_client_done(); + } exit(0); } diff --git a/overlay_mdp.c b/overlay_mdp.c index 6d410d57..95f6cfd5 100644 --- a/overlay_mdp.c +++ b/overlay_mdp.c @@ -422,3 +422,14 @@ int overlay_mdp_client_done() mdp_client_socket=-1; return 0; } + +int overlay_mdp_client_poll(long long timeout_ms) +{ + if (timeout_ms<0) timeout_ms=0; + printf("waiting for %lldms on client socket.\n",timeout_ms); + struct pollfd fds[1]; + int fdcount=1; + fds[0].fd=mdp_client_socket; fds[0].events=POLLIN; + + return poll(fds,fdcount,timeout_ms); +} diff --git a/serval.h b/serval.h index 59b08ebe..0c5d1409 100644 --- a/serval.h +++ b/serval.h @@ -1040,3 +1040,5 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int flags,int timeout_ms); int setVerbosity(char *optarg); int overlay_mdp_client_init(); int overlay_mdp_client_done(); +int overlay_mdp_client_poll(long long timeout_ms); +extern int mdp_client_socket;