This commit is contained in:
c-cube 2025-06-23 14:14:36 +00:00
parent 64c3218cf3
commit e7d9a829e8
2 changed files with 7 additions and 3 deletions

View file

@ -0,0 +1,2 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>With_lock (tiny_httpd.Tiny_httpd_ws.With_lock)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.0.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../../index.html">Index</a> &#x00BB; <a href="../../index.html">tiny_httpd</a> &#x00BB; <a href="../index.html">Tiny_httpd_ws</a> &#x00BB; With_lock</nav><header class="odoc-preamble"><h1>Module <code><span>Tiny_httpd_ws.With_lock</span></code></h1><p>Synchronization primitive used to allow both the reader to reply to &quot;ping&quot;, and the handler to send messages, without stepping on each other's toes.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> NEXT_RELEASE</li></ul></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span><span> = </span><span>{</span></code><ol><li id="type-t.with_lock" class="def record field anchored"><a href="#type-t.with_lock" class="anchor"></a><code><span>with_lock : 'a. <span><span>(<span>unit <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>)</span> <span class="arrow">&#45;&gt;</span></span> <span class="type-var">'a</span>;</span></code></li></ol><code><span>}</span></code></div><div class="spec-doc"><p>A primitive to run the callback in a critical section where others cannot run at the same time.</p><p>The default is a mutex, but that works poorly with thread pools so it's possible to use a semaphore or a cooperative mutex instead.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-builder"><a href="#type-builder" class="anchor"></a><code><span><span class="keyword">type</span> builder</span><span> = <span>unit <span class="arrow">&#45;&gt;</span></span> <a href="#type-t">t</a></span></code></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-default_builder"><a href="#val-default_builder" class="anchor"></a><code><span><span class="keyword">val</span> default_builder : <a href="#type-builder">builder</a></span></code></div><div class="spec-doc"><p>Lock using <code>Mutex</code>.</p></div></div></div></body></html>

View file

@ -1,18 +1,20 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Tiny_httpd_ws (tiny_httpd.Tiny_httpd_ws)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.0.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">Index</a> &#x00BB; <a href="../index.html">tiny_httpd</a> &#x00BB; Tiny_httpd_ws</nav><header class="odoc-preamble"><h1>Module <code><span>Tiny_httpd_ws</span></code></h1><p>Websockets for Tiny_httpd.</p><p>This sub-library (<code>tiny_httpd.ws</code>) exports a small implementation for a websocket server. It has no additional dependencies.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-handler"><a href="#type-handler" class="anchor"></a><code><span><span class="keyword">type</span> handler</span><span> = <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Tiny_httpd_ws (tiny_httpd.Tiny_httpd_ws)</title><meta charset="utf-8"/><link rel="stylesheet" href="../../_odoc-theme/odoc.css"/><meta name="generator" content="odoc 3.0.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> <a href="../../index.html">Index</a> &#x00BB; <a href="../index.html">tiny_httpd</a> &#x00BB; Tiny_httpd_ws</nav><header class="odoc-preamble"><h1>Module <code><span>Tiny_httpd_ws</span></code></h1><p>Websockets for Tiny_httpd.</p><p>This sub-library (<code>tiny_httpd.ws</code>) exports a small implementation for a websocket server. It has no additional dependencies.</p></header><div class="odoc-content"><div class="odoc-spec"><div class="spec module anchored" id="module-With_lock"><a href="#module-With_lock" class="anchor"></a><code><span><span class="keyword">module</span> <a href="With_lock/index.html">With_lock</a></span><span> : <span class="keyword">sig</span> ... <span class="keyword">end</span></span></code></div><div class="spec-doc"><p>Synchronization primitive used to allow both the reader to reply to &quot;ping&quot;, and the handler to send messages, without stepping on each other's toes.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-handler"><a href="#type-handler" class="anchor"></a><code><span><span class="keyword">type</span> handler</span><span> =
<span><span>unit <a href="../Tiny_httpd_core/Request/index.html#type-t">Tiny_httpd_core.Request.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>unit <a href="../Tiny_httpd_core/Request/index.html#type-t">Tiny_httpd_core.Request.t</a></span> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Tiny_httpd_core/IO/Input/class-type-t/index.html">Tiny_httpd_core.IO.Input.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Tiny_httpd_core/IO/Input/class-type-t/index.html">Tiny_httpd_core.IO.Input.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Tiny_httpd_core/IO/Output/class-type-t/index.html">Tiny_httpd_core.IO.Output.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Tiny_httpd_core/IO/Output/class-type-t/index.html">Tiny_httpd_core.IO.Output.t</a> <span class="arrow">&#45;&gt;</span></span>
unit</span></code></div><div class="spec-doc"><p>Websocket handler</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-upgrade"><a href="#val-upgrade" class="anchor"></a><code><span><span class="keyword">val</span> upgrade : unit</span></code></div><div class="spec-doc"><p>Websocket handler</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-upgrade"><a href="#val-upgrade" class="anchor"></a><code><span><span class="keyword">val</span> upgrade :
<span><span class="optlabel">?with_lock</span>:<a href="With_lock/index.html#type-t">With_lock.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Tiny_httpd_core/IO/Input/class-type-t/index.html">Tiny_httpd_core.IO.Input.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Tiny_httpd_core/IO/Input/class-type-t/index.html">Tiny_httpd_core.IO.Input.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Tiny_httpd_core/IO/Output/class-type-t/index.html">Tiny_httpd_core.IO.Output.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Tiny_httpd_core/IO/Output/class-type-t/index.html">Tiny_httpd_core.IO.Output.t</a> <span class="arrow">&#45;&gt;</span></span>
<a href="../Tiny_httpd_core/IO/Input/class-type-t/index.html">Tiny_httpd_core.IO.Input.t</a> * <a href="../Tiny_httpd_core/IO/Output/class-type-t/index.html">Tiny_httpd_core.IO.Output.t</a></span></code></div><div class="spec-doc"><p>Upgrade a byte stream to the websocket framing protocol.</p></div></div><div class="odoc-spec"><div class="spec exception anchored" id="exception-Close_connection"><a href="#exception-Close_connection" class="anchor"></a><code><span><span class="keyword">exception</span> </span><span><span class="exception">Close_connection</span></span></code></div><div class="spec-doc"><p>Exception that can be raised from IOs inside the handler, when the connection is closed from underneath.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_route_handler"><a href="#val-add_route_handler" class="anchor"></a><code><span><span class="keyword">val</span> add_route_handler : <a href="../Tiny_httpd_core/IO/Input/class-type-t/index.html">Tiny_httpd_core.IO.Input.t</a> * <a href="../Tiny_httpd_core/IO/Output/class-type-t/index.html">Tiny_httpd_core.IO.Output.t</a></span></code></div><div class="spec-doc"><p>Upgrade a byte stream to the websocket framing protocol.</p><ul class="at-tags"><li class="parameter"><span class="at-tag">parameter</span> <span class="value">with_lock</span> <p>if provided, use this to prevent reader and writer to compete on sending frames. since NEXT_RELEASE.</p></li></ul></div></div><div class="odoc-spec"><div class="spec exception anchored" id="exception-Close_connection"><a href="#exception-Close_connection" class="anchor"></a><code><span><span class="keyword">exception</span> </span><span><span class="exception">Close_connection</span></span></code></div><div class="spec-doc"><p>Exception that can be raised from IOs inside the handler, when the connection is closed from underneath.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-add_route_handler"><a href="#val-add_route_handler" class="anchor"></a><code><span><span class="keyword">val</span> add_route_handler :
<span><span class="optlabel">?accept</span>:<span>(<span><span>unit <a href="../Tiny_httpd_core/Request/index.html#type-t">Tiny_httpd_core.Request.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(unit, int * string)</span> <a href="../../ocaml/Stdlib/index.html#type-result">result</a></span>)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="optlabel">?accept</span>:<span>(<span><span>unit <a href="../Tiny_httpd_core/Request/index.html#type-t">Tiny_httpd_core.Request.t</a></span> <span class="arrow">&#45;&gt;</span></span> <span><span>(unit, int * string)</span> <a href="../../ocaml/Stdlib/index.html#type-result">result</a></span>)</span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?accept_ws_protocol</span>:<span>(<span>string <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="optlabel">?accept_ws_protocol</span>:<span>(<span>string <span class="arrow">&#45;&gt;</span></span> bool)</span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?middlewares</span>:<span><a href="../Tiny_httpd_core/Server/Head_middleware/index.html#type-t">Tiny_httpd_core.Server.Head_middleware.t</a> list</span> <span class="arrow">&#45;&gt;</span></span> <span><span class="optlabel">?middlewares</span>:<span><a href="../Tiny_httpd_core/Server/Head_middleware/index.html#type-t">Tiny_httpd_core.Server.Head_middleware.t</a> list</span> <span class="arrow">&#45;&gt;</span></span>
<span><span class="optlabel">?with_lock</span>:<a href="With_lock/index.html#type-builder">With_lock.builder</a> <span class="arrow">&#45;&gt;</span></span>
<span><a href="../Tiny_httpd_core/Server/index.html#type-t">Tiny_httpd_core.Server.t</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="../Tiny_httpd_core/Server/index.html#type-t">Tiny_httpd_core.Server.t</a> <span class="arrow">&#45;&gt;</span></span>
<span><span><span>(<a href="../Tiny_httpd_core/Server/index.html#type-upgrade_handler">Tiny_httpd_core.Server.upgrade_handler</a>, <span><span><span>(<a href="../Tiny_httpd_core/Server/index.html#type-upgrade_handler">Tiny_httpd_core.Server.upgrade_handler</a>,
<a href="../Tiny_httpd_core/Server/index.html#type-upgrade_handler">Tiny_httpd_core.Server.upgrade_handler</a>)</span> <a href="../Tiny_httpd_core/Server/index.html#type-upgrade_handler">Tiny_httpd_core.Server.upgrade_handler</a>)</span>
<a href="../Tiny_httpd_core/Route/index.html#type-t">Tiny_httpd_core.Route.t</a></span> <span class="arrow">&#45;&gt;</span></span> <a href="../Tiny_httpd_core/Route/index.html#type-t">Tiny_httpd_core.Route.t</a></span> <span class="arrow">&#45;&gt;</span></span>
<span><a href="#type-handler">handler</a> <span class="arrow">&#45;&gt;</span></span> <span><a href="#type-handler">handler</a> <span class="arrow">&#45;&gt;</span></span>
unit</span></code></div><div class="spec-doc"><p>Add a route handler for a websocket endpoint.</p><ul class="at-tags"><li class="parameter"><span class="at-tag">parameter</span> <span class="value">accept_ws_protocol</span> <p>decides whether this endpoint accepts the websocket protocol sent by the client. Default accepts everything.</p></li></ul></div></div></div></body></html> unit</span></code></div><div class="spec-doc"><p>Add a route handler for a websocket endpoint.</p><ul class="at-tags"><li class="parameter"><span class="at-tag">parameter</span> <span class="value">accept_ws_protocol</span> <p>decides whether this endpoint accepts the websocket protocol sent by the client. Default accepts everything.</p></li></ul><ul class="at-tags"><li class="parameter"><span class="at-tag">parameter</span> <span class="value">with_lock</span> <p>if provided, use this to synchronize writes between the frame reader (replies &quot;pong&quot; to &quot;ping&quot;) and the handler emitting writes. since NEXT_RELEASE.</p></li></ul></div></div></div></body></html>