From 4ece8de4d9b71edd13bf4055f06cbf0f2ae607bc Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Fri, 30 Dec 2016 15:51:08 +1100 Subject: [PATCH] net module: hold/unhold support. As per @djphoenix's work on the ESP8266 side. --- components/modules/net.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/components/modules/net.c b/components/modules/net.c index e37286fb..d1b26faf 100644 --- a/components/modules/net.c +++ b/components/modules/net.c @@ -279,7 +279,7 @@ static err_t net_tcp_recv_cb(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, er } if (post_net_recv (ud, p, 0, 0)) - tcp_recved(tpcb, p->len); + tcp_recved(tpcb, ud->client.hold ? 0 : TCP_WND(tpcb)); return ERR_OK; } @@ -632,7 +632,10 @@ int net_hold( lua_State *L ) { lnet_userdata *ud = net_get_udata(L); if (!ud || ud->type != TYPE_TCP_CLIENT) return luaL_error(L, "invalid user data"); - ud->client.hold = 1; + if (!ud->client.hold && ud->tcp_pcb) + { + ud->client.hold = 1; + } return 0; } @@ -641,7 +644,12 @@ int net_unhold( lua_State *L ) { lnet_userdata *ud = net_get_udata(L); if (!ud || ud->type != TYPE_TCP_CLIENT) return luaL_error(L, "invalid user data"); - ud->client.hold = 0; + if (ud->client.hold && ud->tcp_pcb) + { + ud->client.hold = 0; + ud->tcp_pcb->flags |= TF_ACK_NOW; + tcp_recved(ud->tcp_pcb, TCP_WND(ud->tcp_pcb)); + } return 0; }