Documentation ¶
Index ¶
- Constants
- Variables
- func Append(into []byte, lit byte, body ...[]byte) (res []byte)
- func AppendHeader(into []byte, lit byte, bodylen int) (ret []byte)
- func AppendTiny(into []byte, lit byte, body []byte) (res []byte)
- func CloseHeader(buf []byte, bookmark int)
- func Concat(msg ...[]byte) []byte
- func Incomplete(data []byte) int
- func Join(records ...[]byte) (ret []byte)
- func Lit(rec []byte) byte
- func OpenHeader(buf []byte, lit byte) (bookmark int, res []byte)
- func ProbeHeader(data []byte) (lit byte, hdrlen, bodylen int)
- func ProbeHeaders(lits string, data []byte) int
- func Pump(feeder Feeder, drainer Drainer) (err error)
- func PumpCtx(ctx context.Context, feeder Feeder, drainer Drainer) (err error)
- func PumpCtxCallback(ctx context.Context, feeder Feeder, drainer Drainer, f func() bool) (err error)
- func PumpN(feeder Feeder, drainer Drainer, n int) (err error)
- func PumpThenClose(feed FeedCloser, drain DrainCloser) error
- func Record(lit byte, body ...[]byte) []byte
- func Relay(feeder Feeder, drainer Drainer) error
- func Take(lit byte, data []byte) (body, rest []byte)
- func TakeAny(data []byte) (lit byte, body, rest []byte)
- func TakeAnyRecord(data []byte) (lit byte, rec, rest []byte)
- func TakeAnyWary(data []byte) (lit byte, body, rest []byte, err error)
- func TakeRecord(lit byte, data []byte) (rec, rest []byte)
- func TakeWary(lit byte, data []byte) (body, rest []byte, err error)
- func TinyRecord(lit byte, body []byte) (tiny []byte)
- func TotalLen(inputs [][]byte) (sum int)
- type ConnType
- type DestroyCallback
- type DrainCloser
- type Drainer
- type FeedCloser
- type FeedDrainCloser
- type FeedDrainCloserTraced
- type Feeder
- type InstallCallback
- type Net
- func (n *Net) Close() error
- func (n *Net) Connect(addr string) (err error)
- func (n *Net) ConnectPool(name string, addrs []string) (err error)
- func (de *Net) Disconnect(name string) (err error)
- func (n *Net) GetStats() NetStats
- func (n *Net) KeepConnecting(name string, addrs []string)
- func (n *Net) KeepListening(addr string)
- func (n *Net) Listen(addr string) error
- func (de *Net) Unlisten(addr string) error
- type NetOpt
- type NetReadBatchOpt
- type NetStats
- type NetTlsConfigOpt
- type Peer
- type Records
- type TcpBufferSizeOpt
- type Traced
Constants ¶
const ( TYPICAL_MTU = 1500 MAX_OUT_QUEUE_LEN = 1 << 20 // 16MB of pointers is a lot MAX_RETRY_PERIOD = time.Minute MIN_RETRY_PERIOD = time.Second / 2 )
const CaseBit uint8 = 'a' - 'A'
Variables ¶
var ( ErrAddressInvalid = errors.New("the address invalid") ErrAddressDuplicated = errors.New("the address already used") ErrIncomplete = errors.New("incomplete data") ErrBadRecord = errors.New("bad TLV record format") ErrAddressUnknown = errors.New("address unknown") ErrDisconnected = errors.New("disconnected by user") )
Functions ¶
func Append ¶
Append appends a record to the buffer; note that uppercase type is always explicit, lowercase can be defaulted.
func AppendHeader ¶
Feeds the header into the buffer. Subtle: lower-case lit allows for defaulting, uppercase must be explicit.
func CloseHeader ¶
CloseHeader closes a streamed TLV record
func Incomplete ¶
Incomplete returns the number of supposedly yet-unread bytes. 0 for complete, -1 for bad format, >0 for least-necessary read to complete either header or record.
func OpenHeader ¶
OpenHeader opens a streamed TLV record; use append() to create the record body, then call CloseHeader(&buf, bookmark)
func ProbeHeader ¶
ProbeHeader probes a TLV record header. Return values:
- 0 0 0 incomplete header
- '-' 0 0 bad format
- 'A' 2 123 success
func ProbeHeaders ¶
func PumpCtxCallback ¶
func PumpThenClose ¶
func PumpThenClose(feed FeedCloser, drain DrainCloser) error
func Take ¶
Take is used to read safe TLV inputs (e.g. from own storage) with record types known in advance.
func TakeAnyRecord ¶
func TakeAnyWary ¶
TakeWary reads TLV records of arbitrary type from unsafe input.
func TakeRecord ¶
func TinyRecord ¶
Types ¶
type DestroyCallback ¶
type DrainCloser ¶
type FeedCloser ¶
type FeedDrainCloserTraced ¶
type FeedDrainCloserTraced interface { FeedDrainCloser Traced }
type InstallCallback ¶
type InstallCallback func(name string) FeedDrainCloserTraced
type Net ¶
type Net struct {
// contains filtered or unexported fields
}
A TCP/TLS/QUIC server/client for the use case of real-time async communication. Differently from the case of request-response (like HTTP), we do not wait for a request, then dedicating a thread to processing, then sending back the resulting response. Instead, we constantly fan sendQueue tons of tiny messages. That dictates different work patterns than your typical HTTP/RPC server as, for example, we cannot let one slow receiver delay event transmission to all the other receivers.
func NewNet ¶
func NewNet(log utils.Logger, install InstallCallback, destroy DestroyCallback, opts ...NetOpt) *Net
func (*Net) Disconnect ¶
func (*Net) KeepConnecting ¶
func (*Net) KeepListening ¶
type NetReadBatchOpt ¶
type NetReadBatchOpt struct { ReadAccumTimeLimit time.Duration BufferMaxSize int BufferMinToProcess int }
func (*NetReadBatchOpt) Apply ¶
func (opt *NetReadBatchOpt) Apply(n *Net)
type NetTlsConfigOpt ¶
func (*NetTlsConfigOpt) Apply ¶
func (opt *NetTlsConfigOpt) Apply(n *Net)
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
func (*Peer) GetIncomingPacketBufferSize ¶
func (*Peer) GetTraceId ¶
type Records ¶
type Records [][]byte
Records (a batch of) as a very universal primitive, especially for database/network op/packet processing. Batching allows for writev() and other performance optimizations. Also, if you have cryptography, blobs are way handier than structs. Records converts easily to net.Buffers.
func (Records) ExactSuffix ¶
type TcpBufferSizeOpt ¶
func (*TcpBufferSizeOpt) Apply ¶
func (opt *TcpBufferSizeOpt) Apply(n *Net)