Skip to content

Instantly share code, notes, and snippets.

@lithdew
Last active May 20, 2021 09:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lithdew/deb9065a4146e0e5f1afdd314616eb3a to your computer and use it in GitHub Desktop.
Save lithdew/deb9065a4146e0e5f1afdd314616eb3a to your computer and use it in GitHub Desktop.
zig: `std.x` wishlist
  • Include std.x.os.Reactor.

A high-level I/O event reactor interface that wraps over event notification systems like epoll, kqueue.

Plan is to get epoll done first, kqueue second, select third, then iocp/afd fourth.

  • Include std.x.os.Socket.setLinger(linger_for_num_seconds: ?u16) !void.
  • Include std.x.os.Socket.getRemoteAddress() !std.x.Socket.Address.
  • Include std.x.os.Socket.setKeepAlive(enabled bool) !void.
  • Include std.x.os.Socket.(r|R)eader(flags) and std.x.os.Socket.(w|W)riter(flags).
  • Include Windows version of std.x.os.Socket.
  • Generalize std.x.os.Socket to be cross-platform (replace stream read/write-related functions with cross-platform std.x.os.Socket.write, std.x.os.Socket.writeMessage, std.x.os.Socket.read, std.x.os.Socket.readMessage).
  • Include cross-platform std.x.os.Buffer (iovec/WSABUF).
  • Include cross-platform std.x.os.Socket.Message (msghdr).
  • Include cross-platform std.x.os.Socket.Linger (linger).
  • Include cross-platform std.x.os.Socket.Address.Storage (sockaddr_storage).
  • Include cross-platform std.x.os.Socket.init() flags (async, close on exec).
  • Include cross-platform std.x.os.Socket.{read, write, readMessage, writeMessage}() flags.
  • Include lockless/lock-free MPMC/MPSC/SPSC queues into std.x.sync.*.
  • Implement std.x.tcp.Client.connectToHost.

Implements "happy eyeballs" (IETF RFC 8305). The function signature is as follows:

std.x.tcp.Client.connectToHost(
  hostname: []const u8,
  location: union(enum) {
    port: u16,
    service: []const u8,
  },
);
  • Rename std.x.os.IP{v4, v6}.Address to std.x.os.IP{v4, v6}.Endpoint.
  • Implement kqueue support for std.x.os.Reactor.
  • Prepare to include a thread pool scheduler adapted from kprotty/zap into std.x.sync.
  • Include std.x.sync.Waker for abstracting waking/calling async frames/callbacks.
  • Include std.x.sync.CancellationToken for a general-purpose cancellation mechanism.
  • Kickstart work for async sockets (std.x.net.AsyncSocket (?)).
  • Include std.x.os.ctrl_c for cross-platform Ctrl+C handling.
  • Kickstart work on blocking/non-blocking sync primitives (i.e. AutoResetEvent, Semaphore, etc.)
@matu3ba
Copy link

matu3ba commented May 6, 2021

7.1. port or reuse verfied bip buffer implementation for SPSC for bulk data transfer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment