diff options
| author | Paul Sokolovsky | 2016-04-11 01:21:34 +0300 |
|---|---|---|
| committer | Paul Sokolovsky | 2016-04-11 01:21:34 +0300 |
| commit | 7063210014a7ef82afaabaf0f18ffa0cd7efd61f (patch) | |
| tree | 2272355d746ae028d927e410ec8381f76a1dee95 | |
| parent | 1cc81ed449fe51c787d002e786cd5afe5c632f97 (diff) | |
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.
| -rw-r--r-- | extmod/modlwip.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c index 84383516f..1ebcd8923 100644 --- a/extmod/modlwip.c +++ b/extmod/modlwip.c @@ -288,9 +288,19 @@ STATIC err_t _lwip_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) { return ERR_OK; } +// By default, a child socket of listen socket is created with recv +// handler which discards incoming pbuf's. We don't want to do that, +// so set this handler which requests lwIP to keep pbuf's and deliver +// them later. We cannot cache pbufs in child socket on Python side, +// until it is created in accept(). +STATIC err_t _lwip_tcp_recv_unaccepted(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) { + return ERR_BUF; +} + // Callback for incoming tcp connections. STATIC err_t _lwip_tcp_accept(void *arg, struct tcp_pcb *newpcb, err_t err) { lwip_socket_obj_t *socket = (lwip_socket_obj_t*)arg; + tcp_recv(newpcb, _lwip_tcp_recv_unaccepted); if (socket->incoming.connection != NULL) { // We need to handle this better. This single-level structure makes the |
