This commit is contained in:
blueloveTH 2025-01-20 20:57:24 +08:00
parent 24bc430290
commit 85545376ed
2 changed files with 14 additions and 0 deletions

View File

@ -176,6 +176,16 @@ static bool libhv_HttpServer_ws_set_ping_interval(int argc, py_Ref argv) {
return true; return true;
} }
static bool libhv_HttpServer_ws_close(int argc, py_Ref argv) {
PY_CHECK_ARGC(2);
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
PY_CHECK_ARG_TYPE(1, tp_int);
py_i64 channel = py_toint(py_arg(1));
int code = reinterpret_cast<hv::WebSocketChannel*>(channel)->close();
py_newint(py_retval(), code);
return true;
}
static bool libhv_HttpServer_ws_send(int argc, py_Ref argv) { static bool libhv_HttpServer_ws_send(int argc, py_Ref argv) {
PY_CHECK_ARGC(3); PY_CHECK_ARGC(3);
libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0)); libhv_HttpServer* self = (libhv_HttpServer*)py_touserdata(py_arg(0));
@ -245,6 +255,7 @@ py_Type libhv_register_HttpServer(py_GlobalRef mod) {
py_bindmethod(type, "dispatch", libhv_HttpServer_dispatch); py_bindmethod(type, "dispatch", libhv_HttpServer_dispatch);
py_bindmethod(type, "ws_set_ping_interval", libhv_HttpServer_ws_set_ping_interval); py_bindmethod(type, "ws_set_ping_interval", libhv_HttpServer_ws_set_ping_interval);
py_bindmethod(type, "ws_close", libhv_HttpServer_ws_close);
py_bindmethod(type, "ws_send", libhv_HttpServer_ws_send); py_bindmethod(type, "ws_send", libhv_HttpServer_ws_send);
py_bindmethod(type, "ws_recv", libhv_HttpServer_ws_recv); py_bindmethod(type, "ws_recv", libhv_HttpServer_ws_recv);
return type; return type;

View File

@ -64,6 +64,9 @@ class HttpServer:
def ws_set_ping_interval(self, milliseconds: int, /) -> None: def ws_set_ping_interval(self, milliseconds: int, /) -> None:
"""Set WebSocket ping interval in milliseconds.""" """Set WebSocket ping interval in milliseconds."""
def ws_close(self, channel: WsChannelId, /) -> ErrorCode:
"""Close WebSocket channel."""
def ws_send(self, channel: WsChannelId, data: str, /) -> int: def ws_send(self, channel: WsChannelId, data: str, /) -> int:
"""Send WebSocket message through `channel`.""" """Send WebSocket message through `channel`."""