reuse

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: MIT Imports: 5 Imported by: 0

README

go-reuse

Documentation

Overview

Package reuse provides Listen and Dial functions that set socket options in order to be able to reuse ports. You should only use this package if you know what SO_REUSEADDR and SO_REUSEPORT are.

For example:

// listen on the same port.
l1, _ := greuse.Listen("tcp", "127.0.0.1:1234")
l2, _ := greuse.Listen("tcp", "127.0.0.1:1234")

// dial from the same port.
l1, _ := greuse.Listen("tcp", "127.0.0.1:1234")
l2, _ := greuse.Listen("tcp", "127.0.0.1:1235")
c, _ := greuse.Dial("tcp", "127.0.0.1:1234", "127.0.0.1:1235")

Note: can't dial self because tcp/ip stacks use 4-tuples to identify connections, and doing so would clash.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Enabled returns whether or not SO_REUSEPORT or equivalent behaviour is
	// enabled in the OS.
	Enabled = false
)

Functions

func Control

func Control(network, address string, c syscall.RawConn) (err error)

func Dial

func Dial(network, laddr, raddr string) (net.Conn, error)

Dial dials the given network and address. see net.Dialer.Dial Returns a net.Conn created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func DialAddr

func DialAddr(network string, laddr net.Addr, raddr net.Addr) (net.Conn, error)

DialAddr dials the given network and address. see net.Dialer.Dial Returns a net.Conn created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func DialIP

func DialIP(network string, laddr *net.IPAddr, raddr *net.IPAddr) (net.Conn, error)

DialIP dials the given network and ip address. see net.Dialer.Dial Returns a net.Conn created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func DialTCP

func DialTCP(network string, laddr *net.TCPAddr, raddr *net.TCPAddr) (net.Conn, error)

DialTCP dials the given network and tcp address. see net.Dialer.Dial Returns a net.Conn created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func DialTimeOut

func DialTimeOut(network, laddr, raddr string, timeout time.Duration) (net.Conn, error)

DialTimeOut dials the given network and address. see net.Dialer.Dial Returns a net.Conn created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func DialUDP

func DialUDP(network string, laddr *net.UDPAddr, raddr *net.UDPAddr) (net.Conn, error)

DialUDP dials the given network and udp address. see net.Dialer.Dial Returns a net.Conn created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func DialUnix

func DialUnix(network string, laddr *net.UnixAddr, raddr *net.UnixAddr) (net.Conn, error)

DialUnix dials the given network and unix address. see net.Dialer.Dial Returns a net.Conn created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func Listen

func Listen(network, address string) (net.Listener, error)

Listen listens at the given network and address. see net.Listen Returns a net.Listener created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func ListenPacket

func ListenPacket(network, address string) (net.PacketConn, error)

ListenPacket listens at the given network and address. see net.ListenPacket Returns a net.Listener created from a file discriptor for a socket with SO_REUSEPORT and SO_REUSEADDR option set.

func ResolveAddr

func ResolveAddr(network, address string) (net.Addr, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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