Skip to content

Commit f41e1f1

Browse files
committed
extmod/modwebrepl: Keep reading data when there's something to read.
EAGAIN should be returned only if underlying socket returned it. Wrap existing read function into external loop to process all data available.
1 parent 6514ff6 commit f41e1f1

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

extmod/modwebrepl.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,17 @@ STATIC void handle_op(mp_obj_webrepl_t *self) {
144144
}
145145
}
146146

147+
STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode);
148+
147149
STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
150+
mp_uint_t out_sz;
151+
do {
152+
out_sz = _webrepl_read(self_in, buf, size, errcode);
153+
} while (out_sz == -2);
154+
return out_sz;
155+
}
156+
157+
STATIC mp_uint_t _webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
148158
// We know that os.dupterm always calls with size = 1
149159
assert(size == 1);
150160
mp_obj_webrepl_t *self = self_in;
@@ -171,17 +181,15 @@ STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *
171181
}
172182
self->hdr_to_recv -= hdr_sz;
173183
if (self->hdr_to_recv != 0) {
174-
*errcode = EAGAIN;
175-
return MP_STREAM_ERROR;
184+
return -2;
176185
}
177186
}
178187

179188
DEBUG_printf("webrepl: op: %d, file: %s, chunk @%x, sz=%d\n", self->hdr.type, self->hdr.fname, (uint32_t)self->hdr.offset, self->hdr.size);
180189

181190
handle_op(self);
182191

183-
*errcode = EAGAIN;
184-
return MP_STREAM_ERROR;
192+
return -2;
185193
}
186194

187195
if (self->data_to_recv != 0) {
@@ -213,8 +221,7 @@ STATIC mp_uint_t webrepl_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *
213221
}
214222
}
215223

216-
*errcode = EAGAIN;
217-
return MP_STREAM_ERROR;
224+
return -2;
218225
}
219226

220227
STATIC mp_uint_t webrepl_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) {

0 commit comments

Comments
 (0)