From 3e60fa8f609877015992260b998b91426410ba12 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Fri, 29 Sep 2017 06:41:22 +1000 Subject: [PATCH] Fix data loss in TCP streams. (#2097) * Fix data loss in TCP streams. * Factored out the UDP extra args handling. --- app/modules/net.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app/modules/net.c b/app/modules/net.c index 90c25d26..6be1dfae 100644 --- a/app/modules/net.c +++ b/app/modules/net.c @@ -202,20 +202,29 @@ static void net_recv_cb(lnet_userdata *ud, struct pbuf *p, ip_addr_t *addr, u16_ pbuf_free(p); return; } - lua_State *L = lua_getstate(); + int num_args = 2; - lua_rawgeti(L, LUA_REGISTRYINDEX, ud->client.cb_receive_ref); - lua_rawgeti(L, LUA_REGISTRYINDEX, ud->self_ref); - lua_pushlstring(L, p->payload, p->len); - if (ud->type == TYPE_UDP_SOCKET) { + char iptmp[16] = { 0, }; + if (ud->type == TYPE_UDP_SOCKET) + { num_args += 2; - char iptmp[16]; - bzero(iptmp, 16); ets_sprintf(iptmp, IPSTR, IP2STR(&addr->addr)); - lua_pushinteger(L, port); - lua_pushstring(L, iptmp); } - lua_call(L, num_args, 0); + + lua_State *L = lua_getstate(); + struct pbuf *pp = p; + while (pp) + { + lua_rawgeti(L, LUA_REGISTRYINDEX, ud->client.cb_receive_ref); + lua_rawgeti(L, LUA_REGISTRYINDEX, ud->self_ref); + lua_pushlstring(L, pp->payload, pp->len); + if (ud->type == TYPE_UDP_SOCKET) { + lua_pushinteger(L, port); + lua_pushstring(L, iptmp); + } + lua_call(L, num_args, 0); + pp = pp->next; + } pbuf_free(p); }