From 88a3e9aa0e2c31bf573884f0ccc7099ac977a71b Mon Sep 17 00:00:00 2001 From: Young-Flash <71162630+Young-Flash@users.noreply.github.com> Date: Mon, 26 Sep 2022 21:45:04 +0800 Subject: [PATCH] add unix domain socket support for websocket (#1486) --- src/App.h | 12 ++++++++++++ src/HttpContext.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/App.h b/src/App.h index cd7e927..95ed065 100644 --- a/src/App.h +++ b/src/App.h @@ -533,6 +533,18 @@ public: return std::move(*this); } + /* options, callback, path to unix domain socket */ + TemplatedApp &&listen(int options, MoveOnlyFunction &&handler, std::string path) { + handler(httpContext ? httpContext->listen(path.c_str(), options) : nullptr); + return std::move(*this); + } + + /* callback, path to unix domain socket */ + TemplatedApp &&listen(MoveOnlyFunction &&handler, std::string path) { + handler(httpContext ? httpContext->listen(path.c_str(), 0) : nullptr); + return std::move(*this); + } + TemplatedApp &&run() { uWS::run(); return std::move(*this); diff --git a/src/HttpContext.h b/src/HttpContext.h index 0f8384b..db87486 100644 --- a/src/HttpContext.h +++ b/src/HttpContext.h @@ -445,6 +445,11 @@ public: us_listen_socket_t *listen(const char *host, int port, int options) { return us_socket_context_listen(SSL, getSocketContext(), host, port, options, sizeof(HttpResponseData)); } + + /* Listen to unix domain socket using this HttpContext */ + us_listen_socket_t *listen(const char *path, int options) { + return us_socket_context_listen_unix(SSL, getSocketContext(), path, options, sizeof(HttpResponseData)); + } }; }