Documentation
¶
Overview ¶
Package socket provides a Unix domain socket transport for the compose protocol. It implements framed read/write of protocol.Header + payload messages over a single net.Conn, along with server-side listening and client-side dialing.
Conn ¶
Conn wraps a net.Conn with framed I/O. Each frame on the wire is a 64-byte header (see protocol.HeaderSize) followed by PayloadSize bytes of payload. Reads and writes are independently locked, so concurrent producers and consumers are safe on the same connection.
Listener ¶
Listener binds a Unix domain socket (AF_UNIX) and accepts incoming connections. On startup it removes any stale socket file left by a previous crash, preventing "address already in use" errors.
Dialer ¶
Dialer connects to a compositor's Unix domain socket. It is intentionally simple — reconnection with backoff belongs in higher layers (internal/conn.Manager), keeping the transport layer focused on establishing a single connection.
Platform support ¶
Unix domain sockets are supported on Linux, macOS, and Windows 10 1803+ (AF_UNIX). No CGO required on any platform.
Index ¶
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) ReadFrame() (protocol.Header, []byte, error)
- func (c *Conn) ReadFrameInto(buf []byte) (protocol.Header, []byte, error)
- func (c *Conn) ReadHandshakeHello() (protocol.HelloMsg, error)
- func (c *Conn) ReadHandshakeWelcome() (protocol.WelcomeMsg, error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) WriteFrame(hdr *protocol.Header, payload []byte) error
- func (c *Conn) WriteHandshakeHello(msg *protocol.HelloMsg) error
- func (c *Conn) WriteHandshakeWelcome(msg *protocol.WelcomeMsg) error
- type Dialer
- type Listener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn wraps a net.Conn with framed header+payload read/write. Concurrent reads and writes are safe (separate locks). Concurrent reads from multiple goroutines are serialized by readMu. Concurrent writes from multiple goroutines are serialized by writeMu.
func (*Conn) ReadFrame ¶
ReadFrame reads a header + payload from the connection. The returned payload slice is freshly allocated if PayloadSize > 0.
func (*Conn) ReadFrameInto ¶
ReadFrameInto reads a header + payload into a caller-provided buffer. If buf is nil or too small for the header's PayloadSize, a new buffer is allocated. The returned slice may be a sub-slice of buf or a new allocation.
func (*Conn) ReadHandshakeHello ¶
ReadHandshakeHello reads a HelloMsg from the connection.
func (*Conn) ReadHandshakeWelcome ¶
func (c *Conn) ReadHandshakeWelcome() (protocol.WelcomeMsg, error)
ReadHandshakeWelcome reads a WelcomeMsg from the connection.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote address of the underlying connection.
func (*Conn) WriteFrame ¶
WriteFrame sends a header + payload atomically. The header is encoded into an internal buffer and written together with payload in a single locked section to prevent interleaving.
func (*Conn) WriteHandshakeHello ¶
WriteHandshakeHello sends a HelloMsg on the connection.
func (*Conn) WriteHandshakeWelcome ¶
func (c *Conn) WriteHandshakeWelcome(msg *protocol.WelcomeMsg) error
WriteHandshakeWelcome sends a WelcomeMsg on the connection.
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer connects to a compositor's Unix domain socket. Reconnection with backoff belongs in higher layers (internal/conn.Manager); the dialer is a simple one-shot connect helper.
func NewDialer ¶
NewDialer creates a dialer for the given Unix domain socket address. The default timeout is 5 seconds.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener accepts module connections on a Unix domain socket (AF_UNIX). On startup it removes any stale socket file left by a previous crash.
func Listen ¶
Listen creates a Unix domain socket listener at the given path.
If a socket file already exists at addr, it is removed first. This is the standard Unix pattern to avoid "address already in use" after an unclean shutdown. On Windows, AF_UNIX is supported since Windows 10 version 1803.
func (*Listener) Accept ¶
Accept waits for and returns the next module connection. The returned Conn is ready for handshake (WriteHandshakeWelcome / ReadHandshakeHello).