Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions capi/libuwebsockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,36 @@ extern "C"

void uws_app_listen_with_config(int ssl, uws_app_t *app, uws_app_listen_config_t config, uws_listen_handler handler, void *user_data)
{
/* branching is getting untidy */
if (ssl)
{
uWS::SSLApp *uwsApp = (uWS::SSLApp *)app;
uwsApp->listen(config.host, config.port, config.options, [handler, config, user_data](struct us_listen_socket_t *listen_socket)
{ handler((struct us_listen_socket_t *)listen_socket, config, user_data); });
if (config.fd) {
uwsApp->listen(
config.options,
[handler, config, user_data](struct us_listen_socket_t *listen_socket) {
handler((struct us_listen_socket_t *)listen_socket, config, user_data);
},
config.fd);
} else {
uwsApp->listen(config.host, config.port, config.options, [handler, config, user_data](struct us_listen_socket_t *listen_socket)
{ handler((struct us_listen_socket_t *)listen_socket, config, user_data); });
}
}
else
{
uWS::App *uwsApp = (uWS::App *)app;
uwsApp->listen(config.host, config.port, config.options, [handler, config, user_data](struct us_listen_socket_t *listen_socket)
{ handler((struct us_listen_socket_t *)listen_socket, config, user_data); });
if (config.fd) {
uwsApp->listen(
config.options,
[handler, config, user_data](struct us_listen_socket_t *listen_socket) {
handler((struct us_listen_socket_t *)listen_socket, config, user_data);
},
config.fd);
} else {
uwsApp->listen(config.host, config.port, config.options, [handler, config, user_data](struct us_listen_socket_t *listen_socket)
{ handler((struct us_listen_socket_t *)listen_socket, config, user_data); });
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion capi/libuwebsockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extern "C"

DLL_EXPORT typedef struct
{

LIBUS_SOCKET_DESCRIPTOR fd;
int port;
const char *host;
int options;
Expand Down
13 changes: 13 additions & 0 deletions src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string>
#include <charconv>
#include <string_view>
#include "libusockets.h"

namespace uWS {
/* Safari 15.0 - 15.3 has a completely broken compression implementation (client_no_context_takeover not
Expand Down Expand Up @@ -561,6 +562,18 @@ struct TemplatedApp {
handler(httpContext ? httpContext->listen(nullptr, port, options) : nullptr);
return std::move(*this);
}

/* callback, fd */
TemplatedApp &&listen(MoveOnlyFunction<void(us_listen_socket_t *)> &&handler, LIBUS_SOCKET_DESCRIPTOR fd) {
handler(httpContext ? httpContext->listen(fd, 0) : nullptr);
return std::move(*this);
}

/* options, callback, fd */
TemplatedApp &&listen(int options, MoveOnlyFunction<void(us_listen_socket_t *)> &&handler, LIBUS_SOCKET_DESCRIPTOR fd) {
handler(httpContext ? httpContext->listen(fd, options) : nullptr);
return std::move(*this);
}

/* options, callback, path to unix domain socket */
TemplatedApp &&listen(int options, MoveOnlyFunction<void(us_listen_socket_t *)> &&handler, std::string path) {
Expand Down
7 changes: 7 additions & 0 deletions src/HttpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "HttpResponseData.h"
#include "AsyncSocket.h"
#include "WebSocketData.h"
#include "libusockets.h"

#include <string_view>
#include <iostream>
Expand Down Expand Up @@ -466,6 +467,12 @@ struct HttpContext {
us_listen_socket_t *listen(const char *path, int options) {
return us_socket_context_listen_unix(SSL, getSocketContext(), path, options, sizeof(HttpResponseData<SSL>));
}

/* Attach to bound and listening socket (fd) using this HttpContext */
us_listen_socket_t *listen(LIBUS_SOCKET_DESCRIPTOR fd, int options) {
return us_socket_context_listen_direct(SSL, getSocketContext(), fd, options, sizeof(HttpResponseData<SSL>));
}

};

}
Expand Down