Skip to content

Commit 7543dd9

Browse files
committed
CORS works and autoreload too
1 parent eeb9b78 commit 7543dd9

File tree

6 files changed

+334
-169
lines changed

6 files changed

+334
-169
lines changed

ports/espressif/common-hal/socketpool/Socket.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static const char *TAG = "socket";
4444
STATIC socketpool_socket_obj_t *open_socket_handles[CONFIG_LWIP_MAX_SOCKETS];
4545

4646
void socket_user_reset(void) {
47+
ESP_LOGW(TAG, "Reset sockets");
4748
for (size_t i = 0; i < MP_ARRAY_SIZE(open_socket_handles); i++) {
4849
if (open_socket_handles[i]) {
4950
if (open_socket_handles[i]->num > 0) {
@@ -74,16 +75,14 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, uint8_t *ip, uint32_
7475
uint64_t start_ticks = supervisor_ticks_ms64();
7576

7677
// Allow timeouts and interrupts
77-
while (newsoc == -1 &&
78-
!timed_out &&
79-
!mp_hal_is_interrupted()) {
78+
while (newsoc == -1 && !timed_out) {
8079
if (self->timeout_ms != (uint)-1 && self->timeout_ms != 0) {
8180
timed_out = supervisor_ticks_ms64() - start_ticks >= self->timeout_ms;
8281
}
8382
RUN_BACKGROUND_TASKS;
8483
newsoc = lwip_accept(self->num, (struct sockaddr *)&accept_addr, &socklen);
8584
// In non-blocking mode, fail instead of timing out
86-
if (newsoc == -1 && self->timeout_ms == 0) {
85+
if (newsoc == -1 && (self->timeout_ms == 0 || mp_hal_is_interrupted())) {
8786
if (errno != EAGAIN) {
8887
ESP_LOGE(TAG, "accept failed %d", errno);
8988
}
@@ -283,8 +282,7 @@ int socketpool_socket_recv_into(socketpool_socket_obj_t *self,
283282
uint64_t start_ticks = supervisor_ticks_ms64();
284283
received = -1;
285284
while (received == -1 &&
286-
!timed_out &&
287-
!mp_hal_is_interrupted()) {
285+
!timed_out) {
288286
if (self->timeout_ms != (uint)-1 && self->timeout_ms != 0) {
289287
timed_out = supervisor_ticks_ms64() - start_ticks >= self->timeout_ms;
290288
}
@@ -301,6 +299,14 @@ int socketpool_socket_recv_into(socketpool_socket_obj_t *self,
301299
}
302300
return -MP_EAGAIN;
303301
}
302+
// Check this after going through the loop once so it can make
303+
// progress while interrupted.
304+
if (mp_hal_is_interrupted()) {
305+
if (received == -1) {
306+
return -MP_EAGAIN;
307+
}
308+
break;
309+
}
304310
}
305311
} else {
306312
return -MP_EBADF;

ports/espressif/common-hal/wifi/__init__.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ void common_hal_wifi_init(bool user_initiated) {
168168

169169
void wifi_user_reset(void) {
170170
if (wifi_user_initiated) {
171+
ESP_LOGW(TAG, "Reset wifi");
171172
wifi_reset();
172173
}
173174
}

supervisor/shared/reload.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ enum {
4343
enum {
4444
AUTORELOAD_SUSPEND_REPL = 0x1,
4545
AUTORELOAD_SUSPEND_BLE = 0x2,
46-
AUTORELOAD_SUSPEND_USB = 0x4
46+
AUTORELOAD_SUSPEND_USB = 0x4,
47+
AUTORELOAD_SUSPEND_WEB = 0x8
4748
};
4849

4950
typedef struct {

0 commit comments

Comments
 (0)