Skip to content

Server-side Observe (RFC 7641, roadmap 2.1)#40

Merged
cvik merged 2 commits intomainfrom
server-observe
Mar 18, 2026
Merged

Server-side Observe (RFC 7641, roadmap 2.1)#40
cvik merged 2 commits intomainfrom
server-observe

Conversation

@cvik
Copy link
Owner

@cvik cvik commented Mar 18, 2026

Summary

Server-side RFC 7641 Observe — the last Tier 2 feature. Handlers register observers, application pushes notifications from any thread.

API

// At startup:
const temp_rid = server.allocateResource().?;

// In handler (on Observe=0):
_ = req.observeResource(temp_rid);

// From any thread:
server.notify(temp_rid, coap.Response.ok("22.5"));

Implementation

  • observe.zig: Pre-allocated ObserverRegistry with resource slots, per-resource observer lists, lock-free MPSC notification queue
  • handler.zig: Request.observeResource(rid) and Request.removeObserver(rid)
  • Server.zig: Config (max_observers, max_observe_resources), init/deinit, public notify()/allocateResource(), tick-loop drainNotifications(), RST observer eviction

Design

  • Thread-safe notify() encodes NON notification with Observe sequence into MPSC queue
  • Tick loop drains queue and sends to all registered observers
  • Observers evicted on RST from client
  • Zero overhead when no observers registered (early return on empty queue)

Test plan

  • zig build test — all 148+ tests pass (8 new observe registry tests)
  • Tier 2 now fully complete (2.1-2.4 all done)

@cvik cvik merged commit 5c28391 into main Mar 18, 2026
1 check passed
@cvik cvik deleted the server-observe branch March 18, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant