mirror of
https://github.com/zap-proto/go.git
synced 2026-10-30 15:05:00 +00:00
zap-proto/go had the wire codec + rpc envelope/pipeline but no network transport — this fills that gap so hanzo AND lux consume one identical RPC plumbing instead of forking luxfi/zap's CGO-tainted node layer. Thin by design: the codegen already emits typed clients against a one-method Channel (Call(envelope) (rpc.Response, error)) and server-side DispatchX functions. This is the drop-in NETWORK realisation of those exact contracts — *Conn implements Channel, Listen serves a Dispatch — so generated code is byte-for-byte unchanged; only the bytes now cross a socket. - transport.go: Conn (symmetric: calls + serves on one socket), length+dir framed [len][dir][envelope], PromiseID correlation from the envelope itself (no transport-level id). TCP writev fast path; 64MiB frame cap. - listen.go: Server accept loop; unix stale-socket reclaim. - Pure Go, zero CGO. QUIC + PQ X-Wing (X25519MLKEM768) land next behind the same Conn/Dispatch contract. Proven: TCP + Unix round-trips, 64-way concurrent PromiseID correlation, clean close (ErrClosed), AND the real generated EchoClient + DispatchEcho running unchanged over a live socket. No protobuf, no gRPC in the path.
24 lines
694 B
Go
24 lines
694 B
Go
// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package transport
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
// removeIfSocket removes path only if it exists and is a Unix-domain socket.
|
|
// It is used before binding a "unix" listener to clear a stale socket left
|
|
// by a crashed predecessor, without ever deleting a regular file or
|
|
// directory a misconfiguration might point at.
|
|
func removeIfSocket(path string) error {
|
|
fi, err := os.Stat(path)
|
|
if err != nil {
|
|
return nil // nothing there (or unstat-able) — let net.Listen decide
|
|
}
|
|
if fi.Mode()&os.ModeSocket == 0 {
|
|
return nil // not a socket — refuse to touch it
|
|
}
|
|
return os.Remove(path)
|
|
}
|