Building a net Conn Type From the Ground Up
summary
Implements a Linux AF_VSOCK net.Conn and net.Listener using raw BSD socket syscalls (socket, bind, connect, accept4), the golang.org/x/sys/unix package and OS newfile wrappers, integrates with the runtime network poll so non‑blocking I/O, deadlines and concurrent Close/Accept unblock correctly, and satisfies net.Error by translating syscall errors. Tests use x/net/nettest and the result serves HTTP and gRPC over AF_VSOCK successfully (works on Go 1.12+ with the accept4 raw‑read hook).
AI-written summary · about
chapters (20)
- 0:00Intro
- 0:30Package net
- 0:58What is a "stream-oriented" connection?
- 1:56What about other socket types?
- 4:05The BSD Sockets API
- 5:03net. Addr and net. Conn interfaces
- 5:33net. Addr and net. Conn implementations
- 8:12The initial conn type
- 8:27net.Listener interface
- 10:44The initial listener type
- 12:09Non-blocking I/O
- 13:16How does the runtime network poller work?
- 14:29The runtime network poller in summary
- 14:53Accessing the runtime network poller
- 16:07os. NewFile with a non-blocking file
- 16:41Testing net.Conn compliance
- 17:08net. Error compliance
- 17:59Non-blocking accept4(2)
- 19:10Testing net.Listener compliance
- 22:26The possibilities are endless








