8000 8.0.x 7694 backport by dhalbert · Pull Request #7698 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

8.0.x 7694 backport #7698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ports/espressif/common-hal/socketpool/Socket.c
8000
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
uint64_t start_ticks = supervisor_ticks_ms64();

// Allow timeouts and interrupts
while (newsoc == -1 &&
!timed_out &&
!mp_hal_is_interrupted()) {
while (newsoc == -1 && !timed_out) {
if (self->timeout_ms != (uint)-1 && self->timeout_ms != 0) {
timed_out = supervisor_ticks_ms64() - start_ticks >= self->timeout_ms;
}
Expand All @@ -267,9 +265,6 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
}
}

// New client socket will not be non-blocking by default, so make it non-blocking.
lwip_fcntl(newsoc, F_SETFL, O_NONBLOCK);

if (!timed_out) {
// harmless on failure but avoiding memcpy is faster
memcpy((void *)ip, (void *)&accept_addr.sin_addr.s_addr, sizeof(accept_addr.sin_addr.s_addr));
Expand All @@ -280,6 +275,10 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
if (newsoc < 0) {
return -MP_EBADF;
}

// We got a socket. New client socket will not be non-blocking by default, so make it non-blocking.
lwip_fcntl(newsoc, F_SETFL, O_NONBLOCK);

if (!register_open_socket(newsoc)) {
lwip_close(newsoc);
return -MP_EBADF;
Expand Down
7 changes: 7 additions & 0 deletions supervisor/shared/web_workflow/websocket.c
46B6
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ typedef struct {
// interrupt character.
STATIC ringbuf_t _incoming_ringbuf;
STATIC uint8_t _buf[16];
// make sure background is not called recursively
STATIC bool in_web_background = false;

static _websocket cp_serial;

Expand Down Expand Up @@ -244,6 +246,10 @@ void websocket_background(void) {
if (!websocket_connected()) {
return;
}
if (in_web_background) {
return;
}
in_web_background = true;
uint8_t c;
while (ringbuf_num_empty(&_incoming_ringbuf) > 0 &&
_read_next_payload_byte(&c)) {
Expand All @@ -253,4 +259,5 @@ void websocket_background(void) {
}
ringbuf_put(&_incoming_ringbuf, c);
}
in_web_background = false;
}
0