diff options
author | 2022-06-17 04:26:44 -0700 | |
---|---|---|
committer | 2022-06-22 06:56:47 -0700 | |
commit | 38cc869104584987d0a7f3b21be4da196bb3f390 (patch) | |
tree | 6523c2d1d90a80f704e955af335a44d8e89b80f9 /src/javascript/jsc/bindings/ScriptExecutionContext.cpp | |
parent | 5d8a99e1d4009cb4b9c7766b2af76c3df8364670 (diff) | |
download | bun-38cc869104584987d0a7f3b21be4da196bb3f390.tar.gz bun-38cc869104584987d0a7f3b21be4da196bb3f390.tar.zst bun-38cc869104584987d0a7f3b21be4da196bb3f390.zip |
WIP WebSocket
Diffstat (limited to 'src/javascript/jsc/bindings/ScriptExecutionContext.cpp')
-rw-r--r-- | src/javascript/jsc/bindings/ScriptExecutionContext.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/javascript/jsc/bindings/ScriptExecutionContext.cpp b/src/javascript/jsc/bindings/ScriptExecutionContext.cpp new file mode 100644 index 000000000..67dd30f6f --- /dev/null +++ b/src/javascript/jsc/bindings/ScriptExecutionContext.cpp @@ -0,0 +1,60 @@ + +#include "ScriptExecutionContext.h" +#include <uws/uSockets/src/libusockets.h> +#include <uws/src/Loop.h> + +extern "C" void Bun__startLoop(us_loop_t* loop); + +namespace WebCore { + +template<bool isSSL> +us_socket_context_t* webSocketContext() +{ + if constexpr (isSSL) { + if (!m_ssl_client_websockets_ctx) { + us_loop_t* loop = (us_loop_t*)uWs::Loop::get(); + us_socket_context_options_t opts; + memset(&opts, 0, sizeof(us_socket_context_t)); + this->m_ssl_client_websockets_ctx = us_create_socket_context(1, loop, sizeof(*ScriptExecutionContext), opts); + *us_socket_context_ext(m_ssl_client_websockets_ctx) = this; + WebSocketStream::registerHTTPContext(this, m_ssl_client_websockets_ctx, loop); + } + + return m_ssl_client_websockets_ctx; + } else { + if (!m_client_websockets_ctx) { + us_loop_t* loop = (us_loop_t*)uWs::Loop::get(); + us_socket_context_options_t opts; + memset(&opts, 0, sizeof(us_socket_context_t)); + this->m_client_websockets_ctx = us_create_socket_context(0, loop, sizeof(*ScriptExecutionContext), opts); + *us_socket_context_ext(m_client_websockets_ctx) = this; + SecureWebSocketStream::registerHTTPContext(this, m_client_websockets_ctx, loop); + } + + return m_client_websockets_ctx; + } +} + +template<bool isSSL, bool isServer> +uWS::WebSocketContext<isSSL, isServer, ScriptExecutionContext*>* +{ + if constexpr (isSSL) { + if (!m_connected_ssl_client_websockets_ctx) { + // should be the parent + RELEASE_ASSERT(m_ssl_client_websockets_ctx); + m_connected_client_websockets_ctx = SecureWebSocketStream::registerClientContext(this, webSocketContext<isSSL>(), loop); + } + + return m_connected_ssl_client_websockets_ctx; + } else { + if (!m_connected_client_websockets_ctx) { + // should be the parent + RELEASE_ASSERT(m_client_websockets_ctx); + m_connected_client_websockets_ctx = WebSocketStream::registerClientContext(this, webSocketContext<isSSL>(), loop); + } + + return m_connected_client_websockets_ctx; + } +} + +}
\ No newline at end of file |