Skip to content

Commit

Permalink
extmod/moduwebsocket: Refactor websocket to uwebsocket.
Browse files Browse the repository at this point in the history
As mentioned in micropython#4450, `websocket` was experimental with a single intended
user, `webrepl`. Therefore, we'll make this change without a weak
link `websocket` -> `uwebsocket`.
  • Loading branch information
Jongy authored and dpgeorge committed Feb 13, 2019
1 parent d1acca3 commit bc4f8b4
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions extmod/modwebsocket.c → extmod/moduwebsocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down Expand Up @@ -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 changes: 10 additions & 0 deletions extmod/moduwebsocket.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion extmod/modwebrepl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions extmod/modwebsocket.h

This file was deleted.

2 changes: 1 addition & 1 deletion ports/esp32/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ports/esp8266/modules/webrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import socket
import uos
import network
import websocket
import uwebsocket
import websocket_helper
import _webrepl

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ports/esp8266/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ports/unix/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion py/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions py/objmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
2 changes: 1 addition & 1 deletion py/py.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
12 changes: 6 additions & 6 deletions tests/extmod/websocket_basic.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -36,7 +36,7 @@ def ws_write(msg, sz):

# 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))
Expand All @@ -46,11 +46,11 @@ def ws_write(msg, sz):
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))
Expand Down

0 comments on commit bc4f8b4

Please sign in to comment.