Documentation
¶
Index ¶
- Variables
- func ReleaseBuffer(buffer *Buffer)
- type Buffer
- type CompositeBuffer
- type Conn
- type Events
- func (ev *Events) Adopt(conn net.Conn, userdata any) (Conn, error)
- func (ev *Events) Close(err error) error
- func (ev *Events) Dial(addr string, userdata any) (Conn, error)
- func (ev *Events) DialContext(dialCtx context.Context, addr string, userdata any) (Conn, error)
- func (ev *Events) Serve(addrs ...string) (err error)
- type UnflushedError
Constants ¶
This section is empty.
Variables ¶
var ( ErrOutboundOverflow = errors.New("uio: outbound buffer limit exceeded") ErrInboundOverflow = errors.New("uio: inbound buffer limit exceeded") ErrTaskQueueFull = errors.New("uio: pending write task limit exceeded") ErrUnflushedData = errors.New("uio: connection closed with unflushed data") ErrDialOnEventLoop = errors.New("uio: Dial cannot run on an event loop") ErrTooManyListenAddresses = errors.New("uio: Serve accepts at most one listen address") )
Functions ¶
func ReleaseBuffer ¶ added in v1.1.0
func ReleaseBuffer(buffer *Buffer)
ReleaseBuffer returns an unsubmitted buffer to the pool. It must be called at most once, and the buffer must not be used afterward.
Types ¶
type Buffer ¶ added in v1.1.0
Buffer is reusable byte storage that can be transferred to a connection with Conn.WriteOwned. Newly acquired writable capacity is not zeroed; every committed byte must be initialized. A Buffer must not be used after its ownership is transferred or it is released.
func AcquireBuffer ¶ added in v1.1.0
AcquireBuffer returns an empty pooled buffer with at least capacity bytes of writable space. Release it when ownership is not transferred to WriteOwned.
type CompositeBuffer ¶
type CompositeBuffer = bytebuf.CompositeBuffer
type Conn ¶
type Conn interface {
// LocalAddr is the connection's local socket address.
LocalAddr() net.Addr
// RemoteAddr is the connection's remote address.
RemoteAddr() net.Addr
// Userdata returns user-defined connection data. It may be called outside a
// callback, but callers must serialize it with SetUserdata.
Userdata() any
// SetUserdata replaces user-defined connection data. It may be called outside
// a callback, but callers must serialize it with Userdata.
SetUserdata(value any)
// SetLinger sets the behavior of Close on a connection which still
// has data waiting to be sent or to be acknowledged.
//
// If sec < 0 (the default), the operating system finishes sending the
// data in the background.
//
// If sec == 0, the operating system discards any unsent or
// unacknowledged data.
//
// If sec > 0, the data is sent in the background as with sec < 0. On
// some operating systems after sec seconds have elapsed any remaining
// unsent data may be discarded.
SetLinger(secs int) error
// SetNoDelay controls whether the operating system should delay
// packet transmission in hopes of sending fewer packets (Nagle's
// algorithm).
// The default is true (no delay), meaning that data is sent as soon as possible after a Write.
SetNoDelay(nodelay bool) error
// SetKeepAlive sets whether the operating system should send
// keep-alive messages on the connection.
SetKeepAlive(keepalive bool) error
// SetKeepAlivePeriod tells operating system to send keep-alive messages on the connection
// and sets period between TCP keep-alive probes.
SetKeepAlivePeriod(secs int) error
// SetReadBuffer sets the size of the operating system's
// receive buffer associated with the connection.
SetReadBuffer(size int) error
// SetWriteBuffer sets the size of the operating system's
// transmit buffer associated with the connection.
SetWriteBuffer(size int) error
// SetDeadline sets deadline for both read and write.
// If it is time.Zero, SetDeadline will clear the deadlines.
SetDeadline(t time.Time) error
// SetReadDeadline sets the deadline for future Read calls.
// When the user doesn't update the deadline and the deadline exceeds,
// the connection will be closed.
// If it is time.Zero, SetReadDeadline will clear the deadline.
SetReadDeadline(t time.Time) error
// SetWriteDeadline sets the deadline for future data writing.
// If it is time.Zero, SetWriteDeadline will clear the deadline.
SetWriteDeadline(t time.Time) error
// Peek returns the next len(b) bytes without advancing the inbound buffer.
// It may only be called from a connection callback.
Peek(b []byte) []byte
// PeekChunk returns the first contiguous inbound chunk without advancing it.
// The returned slice is valid only until Discard or the callback returns.
// It may only be called from a connection callback.
PeekChunk() []byte
// Discard advances the inbound buffer with next n bytes, returning the number of bytes discarded.
// It may only be called from a connection callback.
Discard(n int) (int, error)
// InboundBuffered returns a inbound buffer data length.
// It may only be called from a connection callback.
InboundBuffered() int
// OutboundBuffered returns accepted payload bytes not yet sent, including
// both queued write tasks and the loop-owned outbound buffer.
OutboundBuffered() int
// WriterTo
// It may only be called from a connection callback.
// Notice: non-blocking interface, should not be used as you use std.
io.WriterTo
// ReadWriteCloser
// Read may only be called from a connection callback. Write and Close are
// safe from other goroutines.
// Notice: non-blocking interface, should not be used as you use std.
io.ReadWriteCloser
// ByteWriter
// Notice: non-blocking interface, should not be used as you use std.
io.ByteWriter
// StringWriter
// Notice: non-blocking interface, should not be used as you use std.
io.StringWriter
// Writev "writev"-like batch write optimization.
// Notice: non-blocking interface, should not be used as you use std.
Writev(vec [][]byte) (int, error)
// WriteOwned submits buffer without copying and always consumes its
// ownership, including when it returns an error. For UDP, one buffer is sent
// as one datagram.
WriteOwned(buffer *Buffer) (int, error)
// Flush schedules buffered data for writing without waiting for socket I/O.
// Writes accepted before Flush remain ordered before later writes.
Flush() error
// Wake schedules one OnData callback after previously submitted tasks.
Wake() error
// CloseWith asynchronously closes the connection on its owning loop.
// On Unix, unsent accepted payload is reported as UnflushedError.
CloseWith(err error) error
}
Conn is a non-blocking connection managed by an event loop. On Unix, callbacks and connection state run on the owning loop. Writes from other goroutines are safe and retain no caller-owned data after returning. Close and CloseWith return after the close request is accepted; OnClose is final.
type Events ¶
type Events struct {
// Pollers is set up to start the given number of event-loop goroutine.
// The default value is runtime.NumCPU().
Pollers int
// ReusePort indicates whether to set up the SO_REUSEPORT socket option.
// The default value is false.
ReusePort bool
// LockOSThread is used to determine whether each I/O event-loop is associated to an OS thread.
// The default value is false.
LockOSThread bool
// MaxBufferSize is the maximum number of bytes that can be read from the remote when the readable event comes.
// The default value is 4KB.
MaxBufferSize int
// WriteBufferedThreshold enabled when value is greater than 0, writes will go into the outbound buffer instead of attempting to send them out immediately,
// unless the outbound buffer reaches the threshold or the flush function is manually called.
//
// If you have multiple Write call requirements, opening it will improve write performance because it reduces the number of system calls by merging multiple write operations to improve performance.
// The default value is 0.
WriteBufferedThreshold int
// MaxOutboundBuffered limits accepted but unsent payload bytes per
// connection. Zero disables the byte limit.
MaxOutboundBuffered int
// MaxPendingWrites limits write tasks not yet consumed by a connection's
// event loop. Values <= 0 use a default of 1024.
MaxPendingWrites int
// MaxInboundBuffered limits unread payload retained per connection. Zero
// disables the limit.
MaxInboundBuffered int
// OnOpen fires when a new connection has been opened.
OnOpen func(c Conn)
// OnData fires when a socket receives data from the remote.
OnData func(c Conn) error
// OnClose fires when a connection has been closed.
OnClose func(c Conn, err error)
// OnInbound when any bytes read by a socket, it triggers the inbound event.
OnInbound func(c Conn, readBytes int)
// OnOutbound when any bytes write to a socket, it triggers the outbound event.
OnOutbound func(c Conn, writeBytes int)
// OnStart it triggers on the server initialized.
OnStart func(ev *Events)
// OnStop it triggers on the server closed.
OnStop func(ev *Events)
// contains filtered or unexported fields
}
func (*Events) Adopt ¶ added in v1.1.0
Adopt transfers ownership of an established stream connection to ev. The caller must not use conn after calling Adopt, including when Adopt returns an error. ev must already be serving.
func (*Events) Dial ¶
Dial connects to the address on the named network.
Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and "unixpacket".
Examples:
Dial("tcp://golang.org:http")
Dial("tcp://192.0.2.1:http")
Dial("tcp://198.51.100.1:80")
Dial("udp://[2001:db8::1]:domain")
Dial("udp://[fe80::1%lo0]:53")
Dial("tcp://:80")
Dial("unix:///path/your/unix.sock")
func (*Events) DialContext ¶ added in v1.0.1
DialContext connects from outside event callbacks and allows cancellation while resolving or establishing the network connection.
type UnflushedError ¶ added in v1.1.0
type UnflushedError struct {
Remaining int64
}
UnflushedError reports payload accepted by the framework but not sent before the connection was closed.
func (UnflushedError) Error ¶ added in v1.1.0
func (err UnflushedError) Error() string
func (UnflushedError) Unwrap ¶ added in v1.1.0
func (err UnflushedError) Unwrap() error
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
module
|
|
|
internal
|
|
|
taskqueue
Package taskqueue provides a small intrusive MPSC FIFO queue.
|
Package taskqueue provides a small intrusive MPSC FIFO queue. |
|
Package uws provides an asynchronous WebSocket server built on UIO.
|
Package uws provides an asynchronous WebSocket server built on UIO. |
|
autobahn/server
command
|
|
|
examples/echo
command
|
|
|
examples/nethttp
command
|
|
|
internal/frame
Package frame implements the wire-level WebSocket frame codec.
|
Package frame implements the wire-level WebSocket frame codec. |