tcp

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(ctx context.Context, address string, handle func(net.Conn), handleErr func(error), timeout func(int) time.Duration) error

Dial a remote peer until a connection is successfully established, or until the context is done. Multiple dial attempts can be made, and the timeout function is used to define an upper bound on dial attempts. This function blocks until the connection is handled (and the handle function returns). This function will clean-up the connection.

func Listen

func Listen(ctx context.Context, address string, handle func(net.Conn), handleErr func(error), allow policy.Allow) error

Listen for connections from remote peers until the context is done. The allow function will be used to control the acceptance/rejection of connection attempts, and can be used to implement maximum connection limits, per-IP rate-limiting, and so on. This function spawns all accepted connections into their own background goroutines that run the handle function, and then clean-up the connection. This function blocks until the context is done.

func ListenWithListener

func ListenWithListener(ctx context.Context, listener net.Listener, handle func(net.Conn), handleErr func(error), allow policy.Allow) error

ListenWithListener is the same as Listen but instead of specifying an address, it accepts an already constructed listener.

NOTE: The listener passed to this function will be closed when the given context finishes.

func ListenerWithAssignedPort

func ListenerWithAssignedPort(ctx context.Context, ip string) (net.Listener, int, error)

ListenerWithAssignedPort creates a new listener on a random port assigned by the OS. On success, both the listener and port are returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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