after polling, send ping every sec, regardless

pull/14/head
Tom Early 6 years ago
parent f7c4736176
commit 31e888f5bf

@ -217,6 +217,7 @@ void CQnetITAP::Run(const char *cfgfile)
bool is_alive = false; bool is_alive = false;
acknowledged = true; acknowledged = true;
CTimer lastdata; CTimer lastdata;
CTimer pingTimer;
while (keep_running) { while (keep_running) {
@ -226,6 +227,8 @@ void CQnetITAP::Run(const char *cfgfile)
FD_SET(ug2m, &readfds); FD_SET(ug2m, &readfds);
int maxfs = (serfd > ug2m) ? serfd : ug2m; int maxfs = (serfd > ug2m) ? serfd : ug2m;
// for the first 18 selects(), we send a poll packet every 100 ms,
// then a ping packet gets sent every second
struct timeval tv; struct timeval tv;
tv.tv_sec = (poll_counter >= 18) ? 1 : 0; tv.tv_sec = (poll_counter >= 18) ? 1 : 0;
tv.tv_usec = (poll_counter >= 18) ? 0 : 100000; tv.tv_usec = (poll_counter >= 18) ? 0 : 100000;
@ -245,16 +248,16 @@ void CQnetITAP::Run(const char *cfgfile)
break; break;
} }
if (0 == ret) {
// nothing to read, so do the polling or pinging
if (poll_counter++ < 18 ) { if (poll_counter++ < 18 ) {
const unsigned char poll[2] = { 0xffu, 0xffu }; const unsigned char poll[2] = { 0xffu, 0xffu };
SendTo(poll); SendTo(poll);
pingTimer.start();
} else { } else {
const unsigned char ping[3] = { 0x02u, 0x02u }; if (pingTimer.time() >= 1.0) {
const unsigned char ping[2] = { 0x02u, 0x02u };
SendTo(ping); SendTo(ping);
pingTimer.start();
} }
continue;
} }
// there is something to read! // there is something to read!
@ -302,7 +305,6 @@ void CQnetITAP::Run(const char *cfgfile)
} }
if (0 == memcmp(buf, "DSVT", 4)) { if (0 == memcmp(buf, "DSVT", 4)) {
lastdata.start(); // got a packet, reset the timer
//printf("read %d bytes from QnetGateway\n", (int)len); //printf("read %d bytes from QnetGateway\n", (int)len);
if (ProcessGateway(len, buf)) if (ProcessGateway(len, buf))
break; break;

Loading…
Cancel
Save

Powered by TurnKey Linux.