Add custom server API and runtime limits
This commit is contained in:
@@ -22,3 +22,5 @@ zip_read
|
||||
zip_extract
|
||||
gz_compress
|
||||
gz_uncompress
|
||||
server_start_http
|
||||
server_stop
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
:sig
|
||||
pid_t server_start_http(String key, String socket_fn_or_port, String call_uce_filename, String call_function = "")
|
||||
|
||||
:params
|
||||
key : runtime-wide server key
|
||||
socket_fn_or_port : TCP port number or Unix socket path to listen on
|
||||
call_uce_filename : `.uce` file containing `SERVE_HTTP` handlers
|
||||
call_function : optional named `SERVE_HTTP:name` handler
|
||||
return value : listener process PID, or `0` when it could not be started
|
||||
|
||||
:see
|
||||
>sys
|
||||
server_stop
|
||||
task
|
||||
|
||||
:content
|
||||
Starts or updates a custom HTTP listener backed by a UCE handler file.
|
||||
|
||||
The server key is runtime-wide. Calling `server_start_http()` again with the same key and the same bind target updates the mapped UCE file/function without restarting the listener. If the bind target changes, UCE stops the old listener and starts a replacement.
|
||||
|
||||
`socket_fn_or_port` may be a numeric TCP port such as `"19091"` or a Unix socket path.
|
||||
|
||||
Handler files use `SERVE_HTTP`:
|
||||
|
||||
```uce
|
||||
SERVE_HTTP(Request* req)
|
||||
{
|
||||
req->header["Content-Type"] = "text/plain; charset=utf-8";
|
||||
print("hello from custom HTTP\n");
|
||||
}
|
||||
|
||||
SERVE_HTTP:admin(Request* req)
|
||||
{
|
||||
print("named handler\n");
|
||||
}
|
||||
```
|
||||
|
||||
The custom server dispatcher uses the same nonblocking HTTP listener machinery as the built-in HTTP/WebSocket path, and hands request/response data through the normal `Request` object. Handler code may block in the first implementation; future worker dispatch can be added without changing this API.
|
||||
@@ -0,0 +1,19 @@
|
||||
:sig
|
||||
bool server_stop(String key)
|
||||
|
||||
:params
|
||||
key : runtime-wide server key used with `server_start_http()`
|
||||
return value : `true` when no listener remains or a stop signal was sent
|
||||
|
||||
:see
|
||||
>sys
|
||||
server_start_http
|
||||
|
||||
:content
|
||||
Stops a custom server listener by key and removes its registry config.
|
||||
|
||||
```uce
|
||||
server_stop("site-tests-http");
|
||||
```
|
||||
|
||||
`server_stop()` currently targets custom servers started through `server_start_http()`. The same key model is intended to extend to future `server_start_tcp()` and `server_start_udp()` helpers.
|
||||
Reference in New Issue
Block a user