8000 extmod/modlwip: Fix for loss of data in unaccepted incoming sockets. · cwalther/circuitpython@7063210 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7063210

Browse files
committed
extmod/modlwip: Fix for loss of data in unaccepted incoming sockets.
When lwIP creates a incoming connection socket of a listen socket, it sets its recv callback to one which discards incoming data. We set proper callback only in accept() call, when we allocate Python-level socket where we can queue incoming data. So, in lwIP accept callback be sure to set recv callback to one which tells lwIP to not discard incoming data.
1 parent 1cc81ed commit 7063210

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

extmod/modlwip.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,19 @@ STATIC err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) {
288288
return ERR_OK;
289289
}
290290

291+
// By default, a child socket of listen socket is created with recv
292+
// handler which discards incoming pbuf's. We don't want to do that,
293+
// so set this handler which requests lwIP to keep pbuf's and deliver
294+
// them later. We cannot cache pbufs in child socket on Python side,
295+
// until it is created in accept().
296+
STATIC err_t _lwip_tcp_recv_unaccepted(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) {
297+
return ERR_BUF;
298+
}
299+
291300
// Callback for incoming tcp connections.
292301
STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) {
293302
lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg;
303+
tcp_recv(newpcb, _lwip_tcp_recv_unaccepted);
294304

295305
if (socket->incoming.connection != NULL) {
296306
// We need to handle this better. This single-level structure makes the

0 commit comments

Comments
 (0)
0