Added signal handler to terminate bxhub correctly at CTRL+C.
This commit is contained in:
parent
027b3ffd41
commit
f17107957c
@ -40,6 +40,7 @@ extern "C" {
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
};
|
||||
|
||||
#ifndef BXHUB
|
||||
@ -413,15 +414,26 @@ void send_packet(hub_client_t *client, Bit8u *buf, unsigned len)
|
||||
(struct sockaddr*) &client->sout, sizeof(client->sout));
|
||||
}
|
||||
|
||||
static hub_client_t hclient[2];
|
||||
|
||||
void intHandler(int sig)
|
||||
{
|
||||
if (sig == SIGINT) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (hclient[i].init)
|
||||
delete [] hclient[i].reply_buffer;
|
||||
close(hclient[i].so);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int CDECL main(int argc, char **argv)
|
||||
{
|
||||
hub_client_t hclient[2];
|
||||
int i, n;
|
||||
fd_set rfds;
|
||||
Bit8u buf[BUFSIZE];
|
||||
|
||||
client_count = 0;
|
||||
|
||||
if (!parse_cmdline(argc, argv))
|
||||
exit(0);
|
||||
|
||||
@ -437,6 +449,9 @@ int CDECL main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
signal(SIGINT, intHandler);
|
||||
client_count = 0;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
memset(&hclient[i], 0, sizeof(hub_client_t));
|
||||
|
||||
@ -473,6 +488,7 @@ int CDECL main(int argc, char **argv)
|
||||
} else {
|
||||
printf("TFTP support disabled\n");
|
||||
}
|
||||
printf("Press CTRL+C to quit bxhub\n");
|
||||
|
||||
while (1) {
|
||||
|
||||
@ -519,12 +535,5 @@ int CDECL main(int argc, char **argv)
|
||||
hclient[1].pending_reply_size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (hclient[0].init) delete [] hclient[0].reply_buffer;
|
||||
if (hclient[1].init) delete [] hclient[1].reply_buffer;
|
||||
|
||||
close(hclient[0].so);
|
||||
close(hclient[1].so);
|
||||
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user