Skip to content

Commit

Permalink
extmod/modwebrepl: Fix logic to handle a put of file of size 0.
Browse files Browse the repository at this point in the history
Fixes issue #4499.
  • Loading branch information
dpgeorge committed Feb 28, 2019
1 parent ed1a88e commit 9b2a97a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions extmod/modwebrepl.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ STATIC mp_obj_t webrepl_make_new(const mp_obj_type_t *type, size_t n_args, size_
return o;
}

STATIC void check_file_op_finished(mp_obj_webrepl_t *self) {
if (self->data_to_recv == 0) {
mp_stream_close(self->cur_file);
self->hdr_to_recv = sizeof(struct webrepl_file);
DEBUG_printf("webrepl: Finished file operation %d\n", self->hdr.type);
write_webrepl_resp(self->sock, 0);
}
}

STATIC int write_file_chunk(mp_obj_webrepl_t *self) {
const mp_stream_p_t *file_stream = mp_get_stream(self->cur_file);
byte readbuf[2 + 256];
Expand Down Expand Up @@ -160,6 +169,7 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {

if (self->hdr.type == PUT_FILE) {
self->data_to_recv = self->hdr.size;
check_file_op_finished(self);
} else if (self->hdr.type == GET_FILE) {
self->data_to_recv = 1;
}
Expand Down Expand Up @@ -266,12 +276,7 @@ STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
}
}

if (self->data_to_recv == 0) {
mp_stream_close(self->cur_file);
self->hdr_to_recv = sizeof(struct webrepl_file);
DEBUG_printf("webrepl: Finished file operation %d\n", self->hdr.type);
write_webrepl_resp(self->sock, 0);
}
check_file_op_finished(self);

#ifdef MICROPY_PY_WEBREPL_DELAY
// Some platforms may have broken drivers and easily gets
Expand Down

0 comments on commit 9b2a97a

Please sign in to comment.