43
43
FRAME_CLOSE = 0x8 , FRAME_PING , FRAME_PONG
44
44
};
45
45
46
- enum { BLOCKING_WRITE = 1 };
46
+ enum { BLOCKING_WRITE = 0x80 };
47
47
48
48
typedef struct _mp_obj_websocket_t {
49
49
mp_obj_base_t base ;
@@ -69,7 +69,7 @@ STATIC mp_obj_t websocket_make_new(const mp_obj_type_t *type, size_t n_args, siz
69
69
o -> to_recv = 2 ;
70
70
o -> mask_pos = 0 ;
71
71
o -> buf_pos = 0 ;
72
- o -> opts = 0 ;
72
+ o -> opts = FRAME_TXT ;
73
73
if (n_args > 1 && args [1 ] == mp_const_true ) {
74
74
o -> opts |= BLOCKING_WRITE ;
75
75
}
@@ -185,7 +185,7 @@ STATIC mp_uint_t websocket_read(mp_obj_t self_in, void *buf, mp_uint_t size, int
185
185
STATIC mp_uint_t websocket_write (mp_obj_t self_in , const void * buf , mp_uint_t size , int * errcode ) {
186
186
mp_obj_websocket_t * self = self_in ;
187
187
assert (size < 126 );
188
- byte header [] = {0x81 , size };
188
+ byte header [] = {0x80 | ( self -> opts & FRAME_OPCODE_MASK ) , size };
189
189
190
190
mp_obj_t dest [3 ];
191
191
if (self -> opts & BLOCKING_WRITE ) {
@@ -212,6 +212,11 @@ STATIC mp_uint_t websocket_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t
212
212
switch (request ) {
213
213
case MP_STREAM_GET_DATA_OPTS :
214
214
return self -> ws_flags & FRAME_OPCODE_MASK ;
215
+ case MP_STREAM_SET_DATA_OPTS : {
216
+ int cur = self -> opts & FRAME_OPCODE_MASK ;
217
+ self -> opts = (self -> opts & ~FRAME_OPCODE_MASK ) | (arg & FRAME_OPCODE_MASK );
218
+ return cur ;
219
+ }
215
220
default :
216
221
* errcode = EINVAL ;
217
222
return MP_STREAM_ERROR ;
0 commit comments