utp

package module
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 22 Imported by: 14

README

go-libutp

GoDoc CircleCI Go Report Card Appveyor Status

This is a Go wrapper for libutp.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosed = errors.New("closed")
)
View Source
var Logger = log.Default.WithContextText("go-libutp")

The default Socket Logger. Override per Socket by using WithLogger with NewSocket.

Functions

func WriteStatus

func WriteStatus(w io.Writer)

Types

type Conn

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

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) OnError

func (c *Conn) OnError(f func(error))

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteBufferLen

func (c *Conn) SetWriteBufferLen(len int)

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

func (*Conn) WriteBufferLen

func (c *Conn) WriteBufferLen() int

type FirewallCallback

type FirewallCallback func(net.Addr) bool

A firewall callback returns true if an incoming connection request should be ignored. This is better than just accepting and closing, as it means no acknowledgement packet is sent.

type NewSocketOpt added in v1.2.0

type NewSocketOpt func(s *Socket)

func WithLogger added in v1.2.0

func WithLogger(l log.Logger) NewSocketOpt

type Option

type Option = C.int
const (
	LogNormal   Option = C.UTP_LOG_NORMAL
	LogMtu      Option = C.UTP_LOG_MTU
	LogDebug    Option = C.UTP_LOG_DEBUG
	SendBuffer  Option = C.UTP_SNDBUF
	RecvBuffer  Option = C.UTP_RCVBUF
	TargetDelay Option = C.UTP_TARGET_DELAY

	TimedOut = C.UTP_ETIMEDOUT
)

type Socket

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

func NewSocket

func NewSocket(network, addr string, opts ...NewSocketOpt) (*Socket, error)

func (*Socket) Accept

func (s *Socket) Accept() (net.Conn, error)

func (*Socket) Addr

func (s *Socket) Addr() net.Addr

func (*Socket) Close

func (s *Socket) Close() error

func (*Socket) Dial

func (s *Socket) Dial(addr string) (net.Conn, error)

func (*Socket) DialContext

func (s *Socket) DialContext(ctx context.Context, network, addr string) (_ net.Conn, err error)

Passing an empty network will use the network of the Socket's listener.

func (*Socket) DialTimeout

func (s *Socket) DialTimeout(addr string, timeout time.Duration) (net.Conn, error)

func (*Socket) LocalAddr

func (s *Socket) LocalAddr() net.Addr

func (*Socket) ReadBufferLen

func (s *Socket) ReadBufferLen() int

func (*Socket) ReadFrom

func (s *Socket) ReadFrom(b []byte) (n int, addr net.Addr, err error)

func (*Socket) SetDeadline

func (s *Socket) SetDeadline(t time.Time) error

func (*Socket) SetFirewallCallback

func (s *Socket) SetFirewallCallback(f FirewallCallback)

The callback is used before each packet is processed by libutp without the this package's mutex being held. libutp may not actually need the result as the packet might not be a connection attempt. If the callback function is expensive, it may be worth setting a synchronous callback using SetSyncFirewallCallback.

func (*Socket) SetOption

func (s *Socket) SetOption(opt Option, val int) int

func (*Socket) SetReadDeadline

func (s *Socket) SetReadDeadline(t time.Time) error

func (*Socket) SetSyncFirewallCallback added in v1.1.0

func (s *Socket) SetSyncFirewallCallback(f FirewallCallback)

SetSyncFirewallCallback sets a synchronous firewall callback. It's only called as needed by libutp. It is called with the package-wide mutex held. Any locks acquired by the callback should not also be held by code that might use this package.

func (*Socket) SetWriteBufferLen

func (s *Socket) SetWriteBufferLen(len int)

func (*Socket) SetWriteDeadline

func (s *Socket) SetWriteDeadline(t time.Time) error

func (*Socket) WriteBufferLen

func (s *Socket) WriteBufferLen() int

func (*Socket) WriteTo

func (s *Socket) WriteTo(b []byte, addr net.Addr) (int, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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