Skip to content

Commit b20ec88

Browse files
nickzoicdpgeorge
authored andcommitted
esp32/modsocket.c: remove MSG_PEEK workaround on select ioctl.
1 parent c7830f6 commit b20ec88

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

esp32/modsocket.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -359,35 +359,32 @@ STATIC mp_uint_t socket_stream_write(mp_obj_t self_in, const void *buf, mp_uint_
359359
STATIC mp_uint_t socket_stream_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
360360
socket_obj_t * socket = self_in;
361361
if (request == MP_STREAM_POLL) {
362-
char buf[1];
363-
mp_uint_t ret = 0;
364-
if (arg & MP_STREAM_POLL_RD) {
365-
int r = lwip_recvfrom_r(socket->fd, buf, 1, MSG_DONTWAIT | MSG_PEEK, NULL, NULL);
366-
if (r > 0) ret |= MP_STREAM_POLL_RD;
367-
}
368-
if (arg & (MP_STREAM_POLL_WR | MP_STREAM_POLL_HUP)) {
369-
fd_set wfds; FD_ZERO(&wfds);
370-
fd_set efds; FD_ZERO(&efds);
371-
struct timeval timeout = { .tv_sec = 0, .tv_usec = 0 };
372-
if (arg & MP_STREAM_POLL_WR) FD_SET(socket->fd, &wfds);
373-
if (arg & MP_STREAM_POLL_HUP) FD_SET(socket->fd, &efds);
374-
int r = select((socket->fd)+1, NULL, &wfds, &efds, &timeout);
375-
if (r < 0) {
376-
*errcode = MP_EIO;
377-
return MP_STREAM_ERROR;
378-
}
379-
if (FD_ISSET(socket->fd, &wfds)) ret |= MP_STREAM_POLL_WR;
380-
if (FD_ISSET(socket->fd, &efds)) ret |= MP_STREAM_POLL_HUP;
362+
363+
fd_set rfds; FD_ZERO(&rfds);
364+
fd_set wfds; FD_ZERO(&wfds);
365+
fd_set efds; FD_ZERO(&efds);
366+
struct timeval timeout = { .tv_sec = 0, .tv_usec = 0 };
367+
if (arg & MP_STREAM_POLL_RD) FD_SET(socket->fd, &rfds);
368+
if (arg & MP_STREAM_POLL_WR) FD_SET(socket->fd, &wfds);
369+
if (arg & MP_STREAM_POLL_HUP) FD_SET(socket->fd, &efds);
370+
371+
int r = select((socket->fd)+1, &rfds, &wfds, &efds, &timeout);
372+
if (r < 0) {
373+
*errcode = MP_EIO;
374+
return MP_STREAM_ERROR;
381375
}
376+
377+
mp_uint_t ret = 0;
378+
if (FD_ISSET(socket->fd, &rfds)) ret |= MP_STREAM_POLL_RD;
379+
if (FD_ISSET(socket->fd, &wfds)) ret |= MP_STREAM_POLL_WR;
380+
if (FD_ISSET(socket->fd, &efds)) ret |= MP_STREAM_POLL_HUP;
382381
return ret;
383382
}
384383

385384
*errcode = MP_EINVAL;
386385
return MP_STREAM_ERROR;
387386
}
388387

389-
// XXX TODO missing methods ...
390-
391388
STATIC const mp_map_elem_t socket_locals_dict_table[] = {
392389
{ MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&socket_close_obj },
393390
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&socket_close_obj },

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