Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit ed500e4

Browse files
committed
extmod/modwebrepl: Make GET_FILE operation non-blocking.
In the sense that while GET_FILE transfers its data, REPL still works. This is done by requiring client to send 1-byte block before WebREPL server transfers next block of data.
1 parent c16612e commit ed500e4

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

extmod/modwebrepl.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,7 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
151151
if (self->hdr.type == PUT_FILE) {
152152
self->data_to_recv = self->hdr.size;
153153
} else if (self->hdr.type == GET_FILE) {
154-
// TODO: It's not ideal that we block connection while sending file
155-
// and don't process any input.
156-
while (1) {
157-
mp_uint_t out_sz = write_file_chunk(self);
158-
assert(out_sz != MP_STREAM_ERROR);
159-
if (out_sz == 0) {
160-
break;
161-
}
162-
}
163-
164-
write_webrepl_resp(self->sock, 0);
165-
self->hdr_to_recv = sizeof(struct webrepl_file);
154+
self->data_to_recv = 1;
166155
}
167156
}
168157

@@ -250,17 +239,27 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
250239
buf_sz += sz;
251240
}
252241

253-
DEBUG_printf("webrepl: Writing %lu bytes to file\n", buf_sz);
254-
int err;
255-
mp_uint_t res = mp_stream_write_exactly(self->cur_file, filebuf, buf_sz, &err);
256-
if (err != 0 || res != buf_sz) {
257-
assert(0);
242+
if (self->hdr.type == PUT_FILE) {
243+
DEBUG_printf("webrepl: Writing %lu bytes to file\n", buf_sz);
244+
int err;
245+
mp_uint_t res = mp_stream_write_exactly(self->cur_file, filebuf, buf_sz, &err);
246+
if (err != 0 || res != buf_sz) {
247+
assert(0);
248+
}
249+
} else if (self->hdr.type == GET_FILE) {
250+
assert(buf_sz == 1);
251+
assert(self->data_to_recv == 0);
252+
assert(filebuf[0] == 0);
253+
mp_uint_t out_sz = write_file_chunk(self);
254+
if (out_sz != 0) {
255+
self->data_to_recv = 1;
256+
}
258257
}
259258

260259
if (self->data_to_recv == 0) {
261260
mp_stream_close(self->cur_file);
262261
self->hdr_to_recv = sizeof(struct webrepl_file);
263-
DEBUG_printf("webrepl: Finished writing file\n");
262+
DEBUG_printf("webrepl: Finished file operation %d\n", self->hdr.type);
264263
write_webrepl_resp(self->sock, 0);
265264
}
266265

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