textproto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyTLS is returned if the connection already performed a tls
	// handshake.
	ErrAlreadyTLS = errors.New("textproto: already secured by tls")
)
View Source
var (
	// ErrServerClosed is returned when a server is shut down.
	ErrServerClosed = errors.New("textproto: server closed")
)

Functions

This section is empty.

Types

type Conn

type Conn interface {
	Reader
	Writer

	// SetReadTimeout sets the deadline for read calls to a time now + x.
	SetReadTimeout(time.Duration) error

	// SetWriteTimeout sets the deadline for write calls to a time now + x.
	SetWriteTimeout(time.Duration) error

	// UpgradeTLS replaces the underlying network connection with a tls
	// connection. Nothing happens, when an error occurred.
	UpgradeTLS(*tls.Config) error

	// IsTLS returns whether or not the connection is secured with tls.
	IsTLS() bool

	// RemoteAddr returns the remote network address.
	RemoteAddr() net.IP

	// Context returns the connection context.
	Context() context.Context
}

Conn is a wrapper around a network connection to enable line based reading and buffered writing.

type Protocol

type Protocol interface {
	// Handle is supposed to consume a connection and manage all traffic
	// over it. Once Handle returns, the underlying network connection is
	// automatically closed by the server.
	Handle(Conn)
}

Protocol is an interface for text based protocol implementations.

type Reader

type Reader interface {
	// ReadLine tries to read the next line, but may fail and return an error.
	// If the line is non-nil, the error is nil and vice versa.
	ReadLine() ([]byte, error)
	// DotReader returns an io.Reader, which decodes a dot-encoded block of text
	// up to, but discarding, the closing dot line.
	DotReader() io.Reader
}

Reader is a buffer for line based reading.

type Server

type Server interface {
	// Listen will open a new tcp listener and block until an error occurs.
	// An error is either returned when trying to bind the given address or
	// whenever accepting a new connection fails.
	Listen(addr string) error

	// Shutdown gracefully shuts down the Server. Repeated calls are not supported
	// and will result in a panic.
	// Once called, no more connections will be established. Pending connections
	// are still waited on until the context is canceled.
	Shutdown(ctx context.Context)
}

Server is a general purpose tcp server for text based protocols like SMTP or POP3.

func NewServer

func NewServer(proto Protocol, tlsConfig *tls.Config) Server

NewServer returns a Server using a specified protocol implementation. If the provided *tls.Config is non-nil, the Server will accept only connections over tls. The Server has to be started explicitly afterwards.

type Writer

type Writer interface {
	io.Writer

	// WriteString writes a string to the buffer.
	WriteString(string) error

	// Endline writes a <CR> <LF> sequence to the buffer.
	Endline() error

	// Flush writes the buffer to the underlying direct writer.
	Flush() error

	// DotWriter returns an io.WriteCloser, which encodes text into a
	// dot-encoded sequence of lines. Upon closing a final dot line is written.
	DotWriter() io.WriteCloser
}

Writer is a buffered writer.

Jump to

Keyboard shortcuts

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