socketpool: add read & write stream protocol support
This commit is contained in:
parent
7fbdd7fb69
commit
d0c51a497a
1 changed files with 22 additions and 0 deletions
|
|
@ -423,6 +423,26 @@ STATIC const mp_rom_map_elem_t socketpool_socket_locals_dict_table[] = {
|
|||
|
||||
STATIC MP_DEFINE_CONST_DICT(socketpool_socket_locals_dict, socketpool_socket_locals_dict_table);
|
||||
|
||||
STATIC mp_uint_t socket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errorcode) {
|
||||
socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t ret = socketpool_socket_recv_into(self, buf, size);
|
||||
if (ret < 0) {
|
||||
*errorcode = -ret;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t socket_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errorcode) {
|
||||
socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_int_t ret = socketpool_socket_send(self, buf, size);
|
||||
if (ret < 0) {
|
||||
*errorcode = -ret;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
STATIC mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg, int *errcode) {
|
||||
socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mp_uint_t ret;
|
||||
|
|
@ -443,6 +463,8 @@ STATIC mp_uint_t socket_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_t arg
|
|||
}
|
||||
|
||||
STATIC const mp_stream_p_t socket_stream_p = {
|
||||
.read = socket_read,
|
||||
.write = socket_write,
|
||||
.ioctl = socket_ioctl,
|
||||
.is_text = false,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue