extmod/modlwip: Add stream protocol read method.

This commit is contained in:
Paul Sokolovsky 2016-01-01 02:36:30 +02:00
parent f7be80398e
commit c7fb87caff

View File

@ -878,6 +878,19 @@ STATIC mp_obj_t lwip_socket_setsockopt(mp_uint_t n_args, const mp_obj_t *args) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lwip_socket_setsockopt_obj, 4, 4, lwip_socket_setsockopt);
STATIC mp_uint_t lwip_socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) {
lwip_socket_obj_t *socket = self_in;
switch (socket->type) {
case MOD_NETWORK_SOCK_STREAM:
return lwip_tcp_receive(socket, buf, size, errcode);
case MOD_NETWORK_SOCK_DGRAM:
return lwip_udp_receive(socket, buf, size, NULL, NULL, errcode);
}
// Unreachable
return MP_STREAM_ERROR;
}
STATIC const mp_map_elem_t lwip_socket_locals_dict_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)&lwip_socket_close_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_close), (mp_obj_t)&lwip_socket_close_obj },
@ -894,11 +907,17 @@ STATIC const mp_map_elem_t lwip_socket_locals_dict_table[] = {
};
STATIC MP_DEFINE_CONST_DICT(lwip_socket_locals_dict, lwip_socket_locals_dict_table);
STATIC const mp_stream_p_t lwip_socket_stream_p = {
.read = lwip_socket_read,
//.write = lwip_socket_write,
};
STATIC const mp_obj_type_t lwip_socket_type = {
{ &mp_type_type },
.name = MP_QSTR_socket,
.print = lwip_socket_print,
.make_new = lwip_socket_make_new,
.stream_p = &lwip_socket_stream_p,
.locals_dict = (mp_obj_t)&lwip_socket_locals_dict,
};