Commit c0145e03 authored by Johny Mattsson's avatar Johny Mattsson Committed by Arnim Läuger
Browse files

Fix net module losing TCP data. (#2825)

The netbuf_data() function only returns data from the first pbuf in the
chain. We need to use netbuf_first() and netbuf_next() to walk the
pbuf chain and act on each in turn.
parent fead54e7
...@@ -1105,17 +1105,15 @@ static void lrecv_cb (lua_State *L, lnet_userdata *ud) { ...@@ -1105,17 +1105,15 @@ static void lrecv_cb (lua_State *L, lnet_userdata *ud) {
uint16_t len; uint16_t len;
err_t err = netconn_recv(ud->netconn, &p); err_t err = netconn_recv(ud->netconn, &p);
if (err != ERR_OK) { if (err != ERR_OK || !p) {
lwip_lua_checkerr(L, err); lwip_lua_checkerr(L, err);
return; return;
} }
if (p) { netbuf_first(p);
do {
netbuf_data(p, (void **)&payload, &len); netbuf_data(p, (void **)&payload, &len);
} else {
len = 0;
}
if (len > 0 && ud->client.cb_receive_ref != LUA_NOREF){ if (ud->client.cb_receive_ref != LUA_NOREF){
lua_rawgeti(L, LUA_REGISTRYINDEX, ud->client.cb_receive_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, ud->client.cb_receive_ref);
int num_args = 2; int num_args = 2;
lua_rawgeti(L, LUA_REGISTRYINDEX, ud->self_ref); lua_rawgeti(L, LUA_REGISTRYINDEX, ud->self_ref);
...@@ -1131,6 +1129,7 @@ static void lrecv_cb (lua_State *L, lnet_userdata *ud) { ...@@ -1131,6 +1129,7 @@ static void lrecv_cb (lua_State *L, lnet_userdata *ud) {
} }
lua_call(L, num_args, 0); lua_call(L, num_args, 0);
} }
} while (netbuf_next(p) != -1);
if (p) { if (p) {
netbuf_delete(p); netbuf_delete(p);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment