Skip to content

Commit d7b7a35

Browse files
authored
Merge pull request micropython#3 from micropython/esp32
esp32/modsocket: Make read/write return None when in non-blocking mode.
2 parents 279922f + 62d40e8 commit d7b7a35

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

esp32/modsocket.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,14 @@ STATIC mp_uint_t socket_stream_read(mp_obj_t self_in, void *buf, mp_uint_t size,
383383
// XXX Would be nicer to use RTC to handle timeouts
384384
for (int i=0; i<=sock->retries; i++) {
385385
MP_THREAD_GIL_EXIT();
386-
int x = lwip_recvfrom_r(sock->fd, buf, size, 0, NULL, NULL);
386+
int r = lwip_recvfrom_r(sock->fd, buf, size, 0, NULL, NULL);
387387
MP_THREAD_GIL_ENTER();
388-
if (x >= 0) return x;
389-
if (x < 0 && errno != EWOULDBLOCK) { *errcode = errno; return MP_STREAM_ERROR; }
388+
if (r >= 0) return r;
389+
if (r < 0 && errno != EWOULDBLOCK) { *errcode = errno; return MP_STREAM_ERROR; }
390390
check_for_exceptions();
391391
}
392-
return 0; // causes a timeout error to be raised.
392+
*errcode = sock->retries == 0 ? MP_EWOULDBLOCK : MP_ETIMEDOUT;
393+
return MP_STREAM_ERROR;
393394
}
394395

395396
STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {
@@ -402,7 +403,8 @@ STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_
402403
if (r < 0 && errno != EWOULDBLOCK) { *errcode = errno; return MP_STREAM_ERROR; }
403404
check_for_exceptions();
404405
}
405-
return 0;
406+
*errcode = sock->retries == 0 ? MP_EWOULDBLOCK : MP_ETIMEDOUT;
407+
return MP_STREAM_ERROR;
406408
}
407409

408410
STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy