better shutdown?

pull/12/head
Tom Early 7 years ago
parent 986e200b35
commit a57c10a859

@ -1894,7 +1894,7 @@ void CQnetGateway::Process()
(void)select(max_nfds + 1, &fdset, 0, 0, &tv);
// process packets coming from remote G2 or g2_link
if (FD_ISSET(g2_sock, &fdset)) {
if (keep_running && FD_ISSET(g2_sock, &fdset)) {
SDSVT g2buf;
socklen_t fromlen = sizeof(struct sockaddr_in);
ssize_t g2buflen = recvfrom(g2_sock, g2buf.title, 56, 0, (struct sockaddr *)&fromDst4, &fromlen);
@ -1902,7 +1902,10 @@ void CQnetGateway::Process()
// save incoming port for mobile systems
if (portmap.end() == portmap.find(fromDst4.sin_addr.s_addr)) {
printf("New g2 contact at %s on port %u\n", inet_ntoa(fromDst4.sin_addr), ntohs(fromDst4.sin_port));
portmap[fromDst4.sin_addr.s_addr] = ntohs(fromDst4.sin_port);
portmap[fromDst4.sin_addr.s_addr] = ntohs(fromDst4.sin_port);FD_ISSET(g2_sock, &fdset)) {
SDSVT g2buf;
socklen_t fromlen = sizeof(struct sockaddr_in);
ssize_t g2buflen = recvfrom(g2_sock, g2buf.title, 56, 0, (struct sockaddr *)&fromDst4, &fromlen);
} else {
if (ntohs(fromDst4.sin_port) != portmap[fromDst4.sin_addr.s_addr]) {
printf("New g2 port from %s is now %u, it was %u\n", inet_ntoa(fromDst4.sin_addr), ntohs(fromDst4.sin_port), portmap[fromDst4.sin_addr.s_addr]);
@ -1913,7 +1916,7 @@ void CQnetGateway::Process()
FD_CLR(g2_sock, &fdset);
}
if (FD_ISSET(Link2Gate.GetFD(), &fdset)) {
if (keep_running && FD_ISSET(Link2Gate.GetFD(), &fdset)) {
SDSVT g2buf;
ssize_t g2buflen = Link2Gate.Read(g2buf.title, 56);
ProcessG2(g2buflen, g2buf);
@ -1922,7 +1925,7 @@ void CQnetGateway::Process()
// process packets coming from local repeater modules
for (int mod=0; mod<3; mod++) {
if (rptr.mod[mod].defined && FD_ISSET(Modem2Gate[mod].GetFD(), &fdset)) {
if (keep_running && rptr.mod[mod].defined && FD_ISSET(Modem2Gate[mod].GetFD(), &fdset)) {
ProcessModem(mod);
FD_CLR (Modem2Gate[mod].GetFD(), &fdset);
}

@ -968,7 +968,7 @@ void CQnetLink::Process()
while (keep_running) {
time(&tnow);
if ((tnow - hb) > 0) {
if (keep_running && (tnow - hb) > 0) {
/* send heartbeat to connected donglers */
send_heartbeat();
@ -1108,18 +1108,20 @@ void CQnetLink::Process()
// this could be coming from qnvoice or qngateway (connected2network or notincache)
std::ifstream voicefile(qnvoice_file.c_str(), std::ifstream::in);
if (voicefile) {
char line[FILENAME_MAX];
voicefile.getline(line, FILENAME_MAX);
// trim whitespace
char *start = line;
while (isspace(*start))
start++;
char *end = start + strlen(start) - 1;
while (isspace(*end))
*end-- = (char)0;
// anthing reasonable left?
if (strlen(start) > 2)
PlayAudioNotifyThread(start);
if (keep_running) {
char line[FILENAME_MAX];
voicefile.getline(line, FILENAME_MAX);
// trim whitespace
char *start = line;
while (isspace(*start))
start++;
char *end = start + strlen(start) - 1;
while (isspace(*end))
*end-- = (char)0;
// anthing reasonable left?
if (strlen(start) > 2)
PlayAudioNotifyThread(start);
}
//clean-up
voicefile.close();
remove(qnvoice_file.c_str());
@ -1134,7 +1136,7 @@ void CQnetLink::Process()
tv.tv_usec = 20000;
(void)select(max_nfds + 1, &fdset, 0, 0, &tv);
if (FD_ISSET(xrf_g2_sock, &fdset)) {
if (keep_running && FD_ISSET(xrf_g2_sock, &fdset)) {
socklen_t fromlen = sizeof(struct sockaddr_in);
unsigned char buf[100];
int length = recvfrom(xrf_g2_sock, buf, 100, 0, (struct sockaddr *)&fromDst4, &fromlen);
@ -1683,7 +1685,7 @@ void CQnetLink::Process()
FD_CLR (xrf_g2_sock,&fdset);
}
if (FD_ISSET(ref_g2_sock, &fdset)) {
if (keep_running && FD_ISSET(ref_g2_sock, &fdset)) {
socklen_t fromlen = sizeof(struct sockaddr_in);
unsigned char buf[100];
int length = recvfrom(ref_g2_sock, buf, 100, 0, (struct sockaddr *)&fromDst4,&fromlen);
@ -2430,7 +2432,7 @@ void CQnetLink::Process()
FD_CLR (ref_g2_sock,&fdset);
}
if (FD_ISSET(dcs_g2_sock, &fdset)) {
if (keep_running && FD_ISSET(dcs_g2_sock, &fdset)) {
socklen_t fromlen = sizeof(struct sockaddr_in);
int length = recvfrom(dcs_g2_sock, dcs_buf, 1000, 0, (struct sockaddr *)&fromDst4, &fromlen);
@ -2662,7 +2664,7 @@ void CQnetLink::Process()
FD_CLR (dcs_g2_sock,&fdset);
}
if (FD_ISSET(Gate2Link.GetFD(), &fdset)) {
if (keep_running && FD_ISSET(Gate2Link.GetFD(), &fdset)) {
SDSTR dstr;
int length = Gate2Link.Read(dstr.pkt_id, 100);
@ -3170,7 +3172,7 @@ void CQnetLink::Process()
FD_CLR (Gate2Link.GetFD(), &fdset);
}
for (int i=0; i<3; i++) {
if (notify_msg[i][0] && 0x0U == tracing[i].streamid) {
if (keep_running && notify_msg[i][0] && 0x0U == tracing[i].streamid) {
PlayAudioNotifyThread(notify_msg[i]);
notify_msg[i][0] = '\0';
}

@ -20,6 +20,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/types.h>
@ -39,6 +40,7 @@ bool CUnixDgramReader::Open(const char *path) // returns true on failure
fprintf(stderr, "CUnixDgramReader::Open: socket() failed: %s\n", strerror(errno));
return true;
}
fcntl(fd, F_SETFL, O_NONBLOCK);
struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));

Loading…
Cancel
Save

Powered by TurnKey Linux.