Documentation ¶
Index ¶
- func Dial(ctx context.Context, address string, handle func(net.Conn), ...) error
- func Listen(ctx context.Context, address string, handle func(net.Conn), ...) error
- func ListenWithListener(ctx context.Context, listener net.Listener, handle func(net.Conn), ...) error
- func ListenerWithAssignedPort(ctx context.Context, ip string) (net.Listener, int, error)
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.
Types ¶
This section is empty.