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,8 +227,10 @@ 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;
// don't care about writefds and exceptfds: // don't care about writefds and exceptfds:
@ -245,16 +248,16 @@ void CQnetITAP::Run(const char *cfgfile)
break; break;
} }
if (0 == ret) { if (poll_counter++ < 18 ) {
// nothing to read, so do the polling or pinging const unsigned char poll[2] = { 0xffu, 0xffu };
if (poll_counter++ < 18) { SendTo(poll);
const unsigned char poll[2] = { 0xffu, 0xffu }; pingTimer.start();
SendTo(poll); } else {
} else { if (pingTimer.time() >= 1.0) {
const unsigned char ping[3] = { 0x02u, 0x02u }; 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.