Skip to content

Commit acf2176

Browse files
committed
Add Keep-Alive ACK
1 parent b0d0fbf commit acf2176

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

mongoose.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,6 +4869,11 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
48694869
if (pkt->pay.len == 0) return; // if no data, we're done
48704870
} else if (pkt->pay.len == 0) { // this is an ACK
48714871
if (s->fin_rcvd && s->ttype == MIP_TTYPE_FIN) s->twclosure = true;
4872+
if (mg_ntohl(pkt->tcp->seq) == s->ack - 1) { // this is a keepalive probe
4873+
MG_VERBOSE(("%lu keepalive ACK", c->id));
4874+
tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
4875+
mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
4876+
}
48724877
return; // no data to process
48734878
} else if (seq != s->ack) {
48744879
uint32_t ack = (uint32_t) (mg_htonl(pkt->tcp->seq) + pkt->pay.len);

src/net_builtin.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,11 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
703703
if (pkt->pay.len == 0) return; // if no data, we're done
704704
} else if (pkt->pay.len == 0) { // this is an ACK
705705
if (s->fin_rcvd && s->ttype == MIP_TTYPE_FIN) s->twclosure = true;
706+
if (mg_ntohl(pkt->tcp->seq) == s->ack - 1) { // this is a keepalive probe
707+
MG_VERBOSE(("%lu keepalive ACK", c->id));
708+
tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
709+
mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
710+
}
706711
return; // no data to process
707712
} else if (seq != s->ack) {
708713
uint32_t ack = (uint32_t) (mg_htonl(pkt->tcp->seq) + pkt->pay.len);

0 commit comments

Comments
 (0)