lineproto

package
v0.0.0-...-0fd5418 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCloseConnection = errors.New("close")

ErrCloseConnection must be returned by a LineHandler when we want to cleanly terminate the connection without raising an error.

Functions

func NewUNIXSocketListener

func NewUNIXSocketListener(socketPath string) (net.Listener, error)

NewUNIXSocketListener creates a new net.Listener listening on a UNIX socket at the given path, with a filesystem-level lock.

Types

type Conn

type Conn struct {
	net.Conn
	*Reader
	*Writer

	ServerName string
}

func NewConn

func NewConn(c net.Conn, name string) *Conn

func (*Conn) Close

func (c *Conn) Close() error

type Handler

type Handler interface {
	ServeConnection(c *Conn)
}

type LineHandler

type LineHandler interface {
	ServeLine(context.Context, LineResponseWriter, []byte) error
}

LineHandler is the handler for LineServer.

type LineResponseWriter

type LineResponseWriter interface {
	// WriteLine writes a response as a single line (the line
	// terminator is added by the function).
	WriteLine(...[]byte) error
}

LineResponseWriter writes a single-line response to the underlying connection.

type LineServer

type LineServer struct {
	IdleTimeout    time.Duration
	WriteTimeout   time.Duration
	RequestTimeout time.Duration
	// contains filtered or unexported fields
}

LineServer implements a line-based text protocol. It satisfies the Handler interface.

func NewLineServer

func NewLineServer(h LineHandler) *LineServer

NewLineServer returns a new LineServer with the given handler and default I/O timeouts.

func (*LineServer) ServeConnection

func (l *LineServer) ServeConnection(c *Conn)

ServeConnection handles a new connection. It will accept multiple requests on the same connection (or not, depending on the client preference).

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

func (*Reader) ReadLine

func (r *Reader) ReadLine() ([]byte, error)

type Server

type Server struct {
	Name string
	// contains filtered or unexported fields
}

func NewServer

func NewServer(name string, l net.Listener, h Handler) *Server

func (*Server) Close

func (s *Server) Close()

Close the socket listener and release all associated resources. Waits for active connections to terminate before returning.

func (*Server) Serve

func (s *Server) Serve() error

Serve connections.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func (*Writer) WriteLine

func (w *Writer) WriteLine(args ...[]byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL