Add SIGINT handler to cleanup mdp sockets

This commit is contained in:
Jeremy Lakeman 2013-12-20 11:53:13 +10:30
parent 57b7d74822
commit f085ffec50
4 changed files with 20 additions and 3 deletions

View File

@ -1080,7 +1080,10 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
if (broadcast)
WARN("broadcast ping packets will not be encrypted");
for (; icount==0 || tx_count<icount; ++sequence_number) {
sigIntFlag = 0;
signal(SIGINT, sigIntHandler);
for (; sigIntFlag==0 && (icount==0 || tx_count<icount); ++sequence_number) {
// send a ping packet
{
@ -1100,7 +1103,7 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
with appropriate information as required */
time_ms_t now = gettime_ms();
time_ms_t finish = now + ((tx_count < icount || icount==0)?interval_ms:timeout_ms);
for (; !servalShutdown && now < finish; now = gettime_ms()) {
for (; sigIntFlag==0 && now < finish; now = gettime_ms()) {
time_ms_t poll_timeout_ms = finish - gettime_ms();
if (mdp_poll(mdp_sockfd, poll_timeout_ms)<=0)
@ -1163,6 +1166,8 @@ int app_mdp_ping(const struct cli_parsed *parsed, struct cli_context *context)
}
}
signal(SIGINT, SIG_DFL);
sigIntFlag = 0;
mdp_close(mdp_sockfd);
{

View File

@ -464,11 +464,15 @@ int app_msp_connection(const struct cli_parsed *parsed, struct cli_context *UNUS
}
process_msp_asap();
sigIntFlag = 0;
signal(SIGINT, sigIntHandler);
while(fd_poll()){
while(sigIntFlag==0 && fd_poll()){
;
}
ret = saw_error;
signal(SIGINT, SIG_DFL);
sigIntFlag = 0;
end:
listener=NULL;

View File

@ -483,8 +483,10 @@ int dna_return_resolution(overlay_mdp_frame *mdp, unsigned char *fromSid,
int parseDnaReply(const char *buf, size_t len, char *token, char *did, char *name, char *uri, const char **bufp);
extern int sigPipeFlag;
extern int sigIoFlag;
extern int sigIntFlag;
void sigPipeHandler(int signal);
void sigIoHandler(int signal);
void sigIntHandler(int signal);
int overlay_mdp_setup_sockets();

View File

@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
int sigPipeFlag=0;
int sigIoFlag=0;
int sigIntFlag=0;
void sigPipeHandler(int UNUSED(signal))
{
@ -33,3 +34,8 @@ void sigIoHandler(int UNUSED(signal))
sigIoFlag++;
return;
}
void sigIntHandler(int UNUSED(signal))
{
sigIntFlag++;
}