extmod/moduwebsocket: Refactor websocket
to uwebsocket
.
As mentioned in #4450, `websocket` was experimental with a single intended user, `webrepl`. Therefore, we'll make this change without a weak link `websocket` -> `uwebsocket`.
This commit is contained in:
parent
d1acca3c71
commit
bc4f8b438b
@ -30,9 +30,9 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "py/stream.h"
|
||||
#include "extmod/modwebsocket.h"
|
||||
#include "extmod/moduwebsocket.h"
|
||||
|
||||
#if MICROPY_PY_WEBSOCKET
|
||||
#if MICROPY_PY_UWEBSOCKET
|
||||
|
||||
enum { FRAME_HEADER, FRAME_OPT, PAYLOAD, CONTROL };
|
||||
|
||||
@ -299,16 +299,16 @@ STATIC const mp_obj_type_t websocket_type = {
|
||||
.locals_dict = (void*)&websocket_locals_dict,
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t websocket_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_websocket) },
|
||||
STATIC const mp_rom_map_elem_t uwebsocket_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uwebsocket) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&websocket_type) },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(websocket_module_globals, websocket_module_globals_table);
|
||||
STATIC MP_DEFINE_CONST_DICT(uwebsocket_module_globals, uwebsocket_module_globals_table);
|
||||
|
||||
const mp_obj_module_t mp_module_websocket = {
|
||||
const mp_obj_module_t mp_module_uwebsocket = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&websocket_module_globals,
|
||||
.globals = (mp_obj_dict_t*)&uwebsocket_module_globals,
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_WEBSOCKET
|
||||
#endif // MICROPY_PY_UWEBSOCKET
|
10
extmod/moduwebsocket.h
Normal file
10
extmod/moduwebsocket.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H
|
||||
#define MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H
|
||||
|
||||
#define FRAME_OPCODE_MASK 0x0f
|
||||
enum {
|
||||
FRAME_CONT, FRAME_TXT, FRAME_BIN,
|
||||
FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG
|
||||
};
|
||||
|
||||
#endif // MICROPY_INCLUDED_EXTMOD_MODUWEBSOCKET_H
|
@ -34,7 +34,7 @@
|
||||
#ifdef MICROPY_PY_WEBREPL_DELAY
|
||||
#include "py/mphal.h"
|
||||
#endif
|
||||
#include "extmod/modwebsocket.h"
|
||||
#include "extmod/moduwebsocket.h"
|
||||
|
||||
#if MICROPY_PY_WEBREPL
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
#ifndef MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
|
||||
#define MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
|
||||
|
||||
#define FRAME_OPCODE_MASK 0x0f
|
||||
enum {
|
||||
FRAME_CONT, FRAME_TXT, FRAME_BIN,
|
||||
FRAME_CLOSE = 0x8, FRAME_PING, FRAME_PONG
|
||||
};
|
||||
|
||||
#endif // MICROPY_INCLUDED_EXTMOD_MODWEBSOCKET_H
|
@ -146,7 +146,7 @@
|
||||
#define MICROPY_PY_USSL (1)
|
||||
#define MICROPY_SSL_MBEDTLS (1)
|
||||
#define MICROPY_PY_USSL_FINALISER (1)
|
||||
#define MICROPY_PY_WEBSOCKET (1)
|
||||
#define MICROPY_PY_UWEBSOCKET (1)
|
||||
#define MICROPY_PY_WEBREPL (1)
|
||||
#define MICROPY_PY_FRAMEBUF (1)
|
||||
#define MICROPY_PY_USOCKET_EVENTS (MICROPY_PY_WEBREPL)
|
||||
|
@ -2,7 +2,7 @@
|
||||
import socket
|
||||
import uos
|
||||
import network
|
||||
import websocket
|
||||
import uwebsocket
|
||||
import websocket_helper
|
||||
import _webrepl
|
||||
|
||||
@ -40,7 +40,7 @@ def accept_conn(listen_sock):
|
||||
print("\nWebREPL connection from:", remote_addr)
|
||||
client_s = cl
|
||||
websocket_helper.server_handshake(cl)
|
||||
ws = websocket.websocket(cl, True)
|
||||
ws = uwebsocket.websocket(cl, True)
|
||||
ws = _webrepl._webrepl(ws)
|
||||
cl.setblocking(False)
|
||||
# notify REPL on socket incoming data
|
||||
|
@ -87,7 +87,7 @@
|
||||
#define MICROPY_PY_MACHINE_I2C (1)
|
||||
#define MICROPY_PY_MACHINE_SPI (1)
|
||||
#define MICROPY_PY_MACHINE_SPI_MAKE_NEW machine_hspi_make_new
|
||||
#define MICROPY_PY_WEBSOCKET (1)
|
||||
#define MICROPY_PY_UWEBSOCKET (1)
|
||||
#define MICROPY_PY_WEBREPL (1)
|
||||
#define MICROPY_PY_WEBREPL_DELAY (20)
|
||||
#define MICROPY_PY_FRAMEBUF (1)
|
||||
|
@ -136,7 +136,7 @@
|
||||
#ifndef MICROPY_PY_USELECT_POSIX
|
||||
#define MICROPY_PY_USELECT_POSIX (1)
|
||||
#endif
|
||||
#define MICROPY_PY_WEBSOCKET (1)
|
||||
#define MICROPY_PY_UWEBSOCKET (1)
|
||||
#define MICROPY_PY_MACHINE (1)
|
||||
#define MICROPY_PY_MACHINE_PULSE (1)
|
||||
#define MICROPY_MACHINE_MEM_GET_READ_ADDR mod_machine_mem_get_addr
|
||||
|
@ -118,7 +118,7 @@ extern const mp_obj_module_t mp_module_ussl;
|
||||
extern const mp_obj_module_t mp_module_utimeq;
|
||||
extern const mp_obj_module_t mp_module_machine;
|
||||
extern const mp_obj_module_t mp_module_lwip;
|
||||
extern const mp_obj_module_t mp_module_websocket;
|
||||
extern const mp_obj_module_t mp_module_uwebsocket;
|
||||
extern const mp_obj_module_t mp_module_webrepl;
|
||||
extern const mp_obj_module_t mp_module_framebuf;
|
||||
extern const mp_obj_module_t mp_module_btree;
|
||||
|
@ -1316,8 +1316,8 @@ typedef double mp_float_t;
|
||||
#define MICROPY_PY_USSL_FINALISER (0)
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_PY_WEBSOCKET
|
||||
#define MICROPY_PY_WEBSOCKET (0)
|
||||
#ifndef MICROPY_PY_UWEBSOCKET
|
||||
#define MICROPY_PY_UWEBSOCKET (0)
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_PY_FRAMEBUF
|
||||
|
@ -211,8 +211,8 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
|
||||
#if MICROPY_PY_LWIP
|
||||
{ MP_ROM_QSTR(MP_QSTR_lwip), MP_ROM_PTR(&mp_module_lwip) },
|
||||
#endif
|
||||
#if MICROPY_PY_WEBSOCKET
|
||||
{ MP_ROM_QSTR(MP_QSTR_websocket), MP_ROM_PTR(&mp_module_websocket) },
|
||||
#if MICROPY_PY_UWEBSOCKET
|
||||
{ MP_ROM_QSTR(MP_QSTR_uwebsocket), MP_ROM_PTR(&mp_module_uwebsocket) },
|
||||
#endif
|
||||
#if MICROPY_PY_WEBREPL
|
||||
{ MP_ROM_QSTR(MP_QSTR__webrepl), MP_ROM_PTR(&mp_module_webrepl) },
|
||||
|
2
py/py.mk
2
py/py.mk
@ -256,7 +256,7 @@ PY_EXTMOD_O_BASENAME = \
|
||||
extmod/modussl_mbedtls.o \
|
||||
extmod/modurandom.o \
|
||||
extmod/moduselect.o \
|
||||
extmod/modwebsocket.o \
|
||||
extmod/moduwebsocket.o \
|
||||
extmod/modwebrepl.o \
|
||||
extmod/modframebuf.o \
|
||||
extmod/vfs.o \
|
||||
|
@ -1,20 +1,20 @@
|
||||
try:
|
||||
import uio
|
||||
import uerrno
|
||||
import websocket
|
||||
import uwebsocket
|
||||
except ImportError:
|
||||
print("SKIP")
|
||||
raise SystemExit
|
||||
|
||||
# put raw data in the stream and do a websocket read
|
||||
def ws_read(msg, sz):
|
||||
ws = websocket.websocket(uio.BytesIO(msg))
|
||||
ws = uwebsocket.websocket(uio.BytesIO(msg))
|
||||
return ws.read(sz)
|
||||
|
||||
# do a websocket write and then return the raw data from the stream
|
||||
def ws_write(msg, sz):
|
||||
s = uio.BytesIO()
|
||||
ws = websocket.websocket(s)
|
||||
ws = uwebsocket.websocket(s)
|
||||
ws.write(msg)
|
||||
s.seek(0)
|
||||
return s.read(sz)
|
||||
@ -36,7 +36,7 @@ print(ws_read(b"\x81\x84maskmask", 4))
|
||||
|
||||
# close control frame
|
||||
s = uio.BytesIO(b'\x88\x00') # FRAME_CLOSE
|
||||
ws = websocket.websocket(s)
|
||||
ws = uwebsocket.websocket(s)
|
||||
print(ws.read(1))
|
||||
s.seek(2)
|
||||
print(s.read(4))
|
||||
@ -46,11 +46,11 @@ print(ws_read(b"\x89\x00\x81\x04ping", 4)) # FRAME_PING
|
||||
print(ws_read(b"\x8a\x00\x81\x04pong", 4)) # FRAME_PONG
|
||||
|
||||
# close method
|
||||
ws = websocket.websocket(uio.BytesIO())
|
||||
ws = uwebsocket.websocket(uio.BytesIO())
|
||||
ws.close()
|
||||
|
||||
# ioctl
|
||||
ws = websocket.websocket(uio.BytesIO())
|
||||
ws = uwebsocket.websocket(uio.BytesIO())
|
||||
print(ws.ioctl(8)) # GET_DATA_OPTS
|
||||
print(ws.ioctl(9, 2)) # SET_DATA_OPTS
|
||||
print(ws.ioctl(9))
|
||||
|
Loading…
Reference in New Issue
Block a user