summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-12-30 22:49:50 +0000
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-03-09 12:31:25 +0700
commit4f64f6bfd3b2bf4fc07a5c91958a453790a40a96 (patch)
tree3f6436fd6f3ffd3e6087b02a5595ea0fe8edd7aa
parent6d2e9e70b33a2e545bcb888d80117385fcd24ae5 (diff)
downloadmicropython-4f64f6bfd3b2bf4fc07a5c91958a453790a40a96.tar.gz
micropython-4f64f6bfd3b2bf4fc07a5c91958a453790a40a96.zip
extmod/modlwip: Still process remaining incoming data of a closed socket.
It can happen that a socket gets closed while the pbuf is not completely drained by the application. It can also happen that a new pbuf comes in via the recv callback, and then a "peer closed" event comes via the same callback (pbuf=NULL) before the previous event has been handled. In both cases the socket is closed but there is remaining data. This patch makes sure such data is passed to the application.
-rw-r--r--extmod/modlwip.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/extmod/modlwip.c b/extmod/modlwip.c
index 05b6208f2a..fccde6a052 100644
--- a/extmod/modlwip.c
+++ b/extmod/modlwip.c
@@ -384,11 +384,6 @@ STATIC mp_uint_t lwip_tcp_send(lwip_socket_obj_t *socket, const byte *buf, mp_ui
// Helper function for recv/recvfrom to handle TCP packets
STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_t len, int *_errno) {
-
- if (socket->state == STATE_PEER_CLOSED) {
- return 0;
- }
-
if (socket->incoming.pbuf == NULL) {
mp_uint_t start = mp_hal_ticks_ms();
while (socket->state == STATE_CONNECTED && socket->incoming.pbuf == NULL) {
@@ -399,7 +394,10 @@ STATIC mp_uint_t lwip_tcp_receive(lwip_socket_obj_t *socket, byte *buf, mp_uint_
poll_sockets();
}
if (socket->state == STATE_PEER_CLOSED) {
- return 0;
+ if (socket->incoming.pbuf == NULL) {
+ // socket closed and no data left in buffer
+ return 0;
+ }
} else if (socket->state != STATE_CONNECTED) {
*_errno = -socket->state;
return -1;