mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-14 19:03:20 +00:00
Merge pull request #2357 from cesanta/tcpip-conn-init
improved tcp connection initiation
This commit is contained in:
2 files changed
+4
-4
No files matched your search
+2
-2
@@ -4502,13 +4502,13 @@ static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) {
|
|||||||
#if 0
|
#if 0
|
||||||
MG_INFO(("%lu %hhu %d", c ? c->id : 0, pkt->tcp->flags, (int) pkt->pay.len));
|
MG_INFO(("%lu %hhu %d", c ? c->id : 0, pkt->tcp->flags, (int) pkt->pay.len));
|
||||||
#endif
|
#endif
|
||||||
if (c != NULL && c->is_connecting && pkt->tcp->flags & (TH_SYN | TH_ACK)) {
|
if (c != NULL && c->is_connecting && pkt->tcp->flags == (TH_SYN | TH_ACK)) {
|
||||||
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq) + 1;
|
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq) + 1;
|
||||||
tx_tcp_pkt(ifp, pkt, TH_ACK, pkt->tcp->ack, NULL, 0);
|
tx_tcp_pkt(ifp, pkt, TH_ACK, pkt->tcp->ack, NULL, 0);
|
||||||
c->is_connecting = 0; // Client connected
|
c->is_connecting = 0; // Client connected
|
||||||
settmout(c, MIP_TTYPE_KEEPALIVE);
|
settmout(c, MIP_TTYPE_KEEPALIVE);
|
||||||
mg_call(c, MG_EV_CONNECT, NULL); // Let user know
|
mg_call(c, MG_EV_CONNECT, NULL); // Let user know
|
||||||
} else if (c != NULL && c->is_connecting) {
|
} else if (c != NULL && c->is_connecting && pkt->tcp->flags != TH_ACK) {
|
||||||
// mg_hexdump(pkt->raw.ptr, pkt->raw.len);
|
// mg_hexdump(pkt->raw.ptr, pkt->raw.len);
|
||||||
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
|
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
|
||||||
} else if (c != NULL && pkt->tcp->flags & TH_RST) {
|
} else if (c != NULL && pkt->tcp->flags & TH_RST) {
|
||||||
|
|||||||
+2
-2
@@ -677,13 +677,13 @@ static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) {
|
|||||||
#if 0
|
#if 0
|
||||||
MG_INFO(("%lu %hhu %d", c ? c->id : 0, pkt->tcp->flags, (int) pkt->pay.len));
|
MG_INFO(("%lu %hhu %d", c ? c->id : 0, pkt->tcp->flags, (int) pkt->pay.len));
|
||||||
#endif
|
#endif
|
||||||
if (c != NULL && c->is_connecting && pkt->tcp->flags & (TH_SYN | TH_ACK)) {
|
if (c != NULL && c->is_connecting && pkt->tcp->flags == (TH_SYN | TH_ACK)) {
|
||||||
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq) + 1;
|
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq) + 1;
|
||||||
tx_tcp_pkt(ifp, pkt, TH_ACK, pkt->tcp->ack, NULL, 0);
|
tx_tcp_pkt(ifp, pkt, TH_ACK, pkt->tcp->ack, NULL, 0);
|
||||||
c->is_connecting = 0; // Client connected
|
c->is_connecting = 0; // Client connected
|
||||||
settmout(c, MIP_TTYPE_KEEPALIVE);
|
settmout(c, MIP_TTYPE_KEEPALIVE);
|
||||||
mg_call(c, MG_EV_CONNECT, NULL); // Let user know
|
mg_call(c, MG_EV_CONNECT, NULL); // Let user know
|
||||||
} else if (c != NULL && c->is_connecting) {
|
} else if (c != NULL && c->is_connecting && pkt->tcp->flags != TH_ACK) {
|
||||||
// mg_hexdump(pkt->raw.ptr, pkt->raw.len);
|
// mg_hexdump(pkt->raw.ptr, pkt->raw.len);
|
||||||
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
|
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
|
||||||
} else if (c != NULL && pkt->tcp->flags & TH_RST) {
|
} else if (c != NULL && pkt->tcp->flags & TH_RST) {
|
||||||
|
|||||||
Reference in new issue
Block a user