gitoriaLog in with ident

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchmain2149e902notes mission 002 (4/4): code order — README file map + same-output test, STATUS, LOG, report; tests/letcount.py, tests/realdata-baseline.mjs, tests/realdata-compare.pymremain/plugins/http1/web_socket_client.hl

3.3 KB

  1. \* hl:http1 — the OUTGOING WebSocket client (ticket #109). Subclass it
  2. (`inherit WebSocketClient`) and answer `on open()`, `on message(text)`
  3. and `on close(code)`. AUTO-CONNECT: the file root IS the constructor and
  4. its last statement is connect(), so `new WebSocketClient(url = "ws://…")`
  5. dials immediately, mirroring NativeHttpServer's AUTO-LISTEN. `wss://`
  6. uses the same client TLS as hl:fetch: the system trust store, hostname
  7. verification always on, and `caFile` names an EXTRA anchor for a
  8. self-signed test fixture (never a replacement for the system store). *\
  9. /* Ping/pong is entirely automatic (mission 091's liveness sweep, mirrored
  10. here): a quiet connection is pinged and dropped if the pong doesn't
  11. answer in time, and any inbound ping is answered with a pong — neither
  12. ever reaches `.hl`, the protocol requires them and they are not
  13. application information. RECONNECT IS NEVER AUTOMATIC: a dropped
  14. connection reaches you as exactly one `close` event and nothing here
  15. dials again on its own — call connect() again yourself, e.g. from your
  16. own `on close`, if you want a reconnect policy. */
  17. \* The connection is open and ready for send(). *\
  18. emit open()
  19. \* One complete text (or binary) message arrived from the peer. *\
  20. emit message(
  21. String data \\ the message payload
  22. )
  23. \* The connection ended — at most one `open` ever preceded it (a connection
  24. that never opened still gets exactly one `close`: 1006 for a dial that
  25. never reached a peer, 1002 for a handshake the peer answered but got
  26. wrong). *\
  27. emit close(
  28. Number code \\ the WebSocket close code (RFC 6455 §7.4)
  29. )
  30. String url = null \\ "ws://host[:port][/path]" or "wss://…"
  31. Hybrid headers = {} \\ extra headers on the Upgrade request
  32. String caFile = null \\ wss:// only — an extra trust anchor, exactly hl:fetch's field of the same name
  33. Boolean connected = false \\ true between `open` and `close`
  34. Number #id = 0
  35. Number #srcId = 0
  36. \* Dial the configured url (idempotent — a connect() while already dialling
  37. or open is a no-op: false). Ping/pong needs no call here; it is
  38. automatic — see above. *\
  39. connect() {
  40. if (#id != 0) {
  41. return false
  42. }
  43. id = __native("http1.wsc_connect", url, { headers = headers; caFile = caFile; })
  44. if (id == null) {
  45. hlError("hl:http1: WebSocketClient connect() needs a ws:// or wss:// url — got " + url)
  46. }
  47. #id = id
  48. ev = __native("http1.wsc_events", id)
  49. #srcId = __native("eventloop.register", ev, "wscEvent")
  50. return true
  51. }
  52. \* One text frame to the peer; false when not open. *\
  53. send(
  54. String text \\ the frame to send
  55. ) {
  56. return __native("http1.wsc_send", #id, text)
  57. }
  58. \* Close this connection; `on close` still fires once the peer's echo (or a
  59. timeout) completes the handshake. False when not open. *\
  60. close() {
  61. return __native("http1.wsc_close", #id)
  62. }
  63. // Raw native events ({ kind, data, code }) re-emitted as the documented
  64. // surface — emit is the universal primitive (mirrors NativeWebSocketServer).
  65. on wscEvent(ev) {
  66. if (ev.kind == "open") {
  67. connected = true
  68. emit open()
  69. }
  70. if (ev.kind == "message") {
  71. emit message(ev.data)
  72. }
  73. if (ev.kind == "close") {
  74. connected = false
  75. __native("eventloop.unregister", #srcId)
  76. #id = 0 // connect() again is allowed from here — reconnect is the caller's choice, never automatic
  77. emit close(ev.code)
  78. }
  79. }
  80. // Run body: the constructor's last act — dial the configured url.
  81. connect()

Branches

  • mainmain branch

Latest commits

  • 2149e902notes mission 002 (4/4): code order — README file map + same-output test, STATUS, LOG, report; tests/letcount.py, tests/realdata-baseline.mjs, tests/realdata-compare.pymre
  • 47db4fc1notes mission 002 (3/4): code order — let only where reassigned (58 dropped; 34 left: 19 reassigned, 15 loop-bound); gates 50/0 + 18/0, live-data run = step 2mre
  • 3f8cb383notes mission 002 (2/4): code order — topics, map, thin wrappers: lib/util.hl, lib/notes(-helpers).hl, lib/users.hl (+userOfLoginCode, tagOf), lib/api(-helpers).hl; project.hl = map; login routes take &req/&sessions (failed-login reason now kept); dead notes#1 functions removed; gates 50/0 + 18/0mre
  • 8cda5412notes mission 002 (1/4): code order — files moved: lib/notes.hl, lib/users.hl, lib/jsoncheck.hl, components/styles.hl (imports only); gates 50/0 + 18/0, live-data run identicalmre
  • 47dad68bnotes: Hybriel master 06617221 (plugin allocators 3a781359 + 413f60e4, mpackdb 2cb7ae5e, http1 773de63e); gates 50/0 + 18/0mre
  • a4a2b2aeantcolony#40: tracker missions moved too — references to them in missions/reports/LOG.md updatedmre
  • 3dea0ef2notes: Hybriel master 190aa11d (fc838894 GC correctness, #126 closure scopes, #127); gate 50/0mre
  • e27c7d71notes: Hybriel master 8efba065 (#126 GC by bytes, #48 lambda params copy; audit: nothing to fix; gate 50/0)mre
  • 124613b6antcolony#40: mission references point to the moved missionsmre
  • 1ca2f34dantcolony#40: history (LOG.md), worker briefs (missions/) and reports moved here from antcolony, numbered per project; old numbers in antcolony docs/mission-map.mdmre
  • 2bebebdanotes: Hybriel master ff51cf46 (re-vendor round)mre
  • 3eff126dnotes#3: installable app (manifest + own icon/favicon; notes' own sw.js kept)mre
  • 9883c540deploy.sh: back up live storage/.sessions/.env before every deploy (newest 5 kept)mre
  • eee693b8deploy.sh: never send .git or .gitignore to Byrodinmre
  • c8904061State of 2026-09-27, before the move to gitoriamre