From bc4f8b438b56cf1b4f6b44febcd0d83599cbbd68 Mon Sep 17 00:00:00 2001 From: Yonatan Goldschmidt Date: Sun, 10 Feb 2019 22:35:18 +0200 Subject: [PATCH] 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`. --- extmod/{modwebsocket.c => moduwebsocket.c} | 16 ++++++++-------- extmod/moduwebsocket.h | 10 ++++++++++ extmod/modwebrepl.c | 2 +- extmod/modwebsocket.h | 10 ---------- ports/esp32/mpconfigport.h | 2 +- ports/esp8266/modules/webrepl.py | 4 ++-- ports/esp8266/mpconfigport.h | 2 +- ports/unix/mpconfigport.h | 2 +- py/builtin.h | 2 +- py/mpconfig.h | 4 ++-- py/objmodule.c | 4 ++-- py/py.mk | 2 +- tests/extmod/websocket_basic.py | 12 ++++++------ 13 files changed, 36 insertions(+), 36 deletions(-) rename extmod/{modwebsocket.c => moduwebsocket.c} (96%) create mode 100644 extmod/moduwebsocket.h delete mode 100644 extmod/modwebsocket.h diff --git a/extmod/modwebsocket.c b/extmod/moduwebsocket.c similarity index 96% rename from extmod/modwebsocket.c rename to extmod/moduwebsocket.c index c556f2b770..eb5e20c6e3 100644 --- a/extmod/modwebsocket.c +++ b/extmod/moduwebsocket.c @@ -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 diff --git a/extmod/moduwebsocket.h b/extmod/moduwebsocket.h new file mode 100644 index 0000000000..c1ea291ed7 --- /dev/null +++ b/extmod/moduwebsocket.h @@ -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 diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c index 3c33ee1502..bf0c1654ba 100644 --- a/extmod/modwebrepl.c +++ b/extmod/modwebrepl.c @@ -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 diff --git a/extmod/modwebsocket.h b/extmod/modwebsocket.h deleted file mode 100644 index 2720147dfd..0000000000 --- a/extmod/modwebsocket.h +++ /dev/null @@ -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 diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index a70f6d3180..01b23de05f 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.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) diff --git a/ports/esp8266/modules/webrepl.py b/ports/esp8266/modules/webrepl.py index aa156d1487..bbf8bdb320 100644 --- a/ports/esp8266/modules/webrepl.py +++ b/ports/esp8266/modules/webrepl.py @@ -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 diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index b2a05e6791..c6bd4c87d8 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -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) diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index d0cc9e396e..2614af8392 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -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 diff --git a/py/builtin.h b/py/builtin.h index 2066c06173..a5e0f5f2d0 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -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; diff --git a/py/mpconfig.h b/py/mpconfig.h index 95abacafdd..47638fb0a4 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -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 diff --git a/py/objmodule.c b/py/objmodule.c index 3a00b7ddc1..9ba617707a 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -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) }, diff --git a/py/py.mk b/py/py.mk index 759c7e6ce0..a6eeaa4b87 100644 --- a/py/py.mk +++ b/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 \ diff --git a/tests/extmod/websocket_basic.py b/tests/extmod/websocket_basic.py index 9a80503a03..6cc6f0fd15 100644 --- a/tests/extmod/websocket_basic.py +++ b/tests/extmod/websocket_basic.py @@ -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))