Skip to content

Commit 473b639

Browse files
committed
extmod/modwebrepl: GET_FILE: Send length-prefix chunk with one write().
A bit of optimization.
1 parent 3f3ccef commit 473b639

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

extmod/modwebrepl.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,20 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
124124
if (self->hdr.type == PUT_FILE) {
125125
self->data_to_recv = self->hdr.size;
126126
} else if (self->hdr.type == GET_FILE) {
127-
byte readbuf[256];
127+
byte readbuf[2 + 256];
128128
int err;
129129
// TODO: It's not ideal that we block connection while sending file
130130
// and don't process any input.
131131
while (1) {
132-
mp_uint_t out_sz = file_stream->read(self->cur_file, readbuf, sizeof(readbuf), &err);
132+
mp_uint_t out_sz = file_stream->read(self->cur_file, readbuf + 2, sizeof(readbuf) - 2, &err);
133133
assert(out_sz != MP_STREAM_ERROR);
134-
write_webrepl(self->sock, &out_sz, 2);
134+
readbuf[0] = out_sz;
135+
readbuf[1] = out_sz >> 8;
136+
DEBUG_printf("webrepl: Sending %d bytes of file\n", out_sz);
137+
write_webrepl(self->sock, readbuf, 2 + out_sz);
135138
if (out_sz == 0) {
136139
break;
137140
}
138-
DEBUG_printf("webrepl: Sending %d bytes of file\n", out_sz);
139-
write_webrepl(self->sock, readbuf, out_sz);
140141
}
141142

142143
write_webrepl_resp(self->sock, 0);

0 commit comments

Comments
 (0)