Juan Batiz-Benet 096958438a fixed fd leaks
2015-01-23 16:16:15 -08:00
2015-01-23 01:44:02 -08:00
2015-01-18 19:42:16 -08:00
2015-01-20 12:56:10 -08:00
2015-01-23 16:16:15 -08:00
2015-01-20 19:32:37 -08:00
2015-01-22 22:12:35 -08:00
2015-01-22 22:12:35 -08:00
2015-01-23 16:16:15 -08:00
2015-01-20 19:32:37 -08:00
2015-01-22 07:19:41 -08:00
2015-01-18 20:16:39 -08:00
2015-01-19 02:42:52 -08:00
2015-01-19 16:05:57 -08:00
2015-01-23 16:16:15 -08:00

go-reuseport

travisbadge

This package enables listening and dialing from the same TCP or UDP port. This means that the following sockopts are set:

SO_REUSEADDR
SO_REUSEPORT

This is a simple package to get around the problem of reusing addresses. The go net package (to my knowledge) does not allow setting socket options. This is particularly problematic when attempting to do TCP NAT holepunching, which requires a process to both Listen and Dial on the same TCP port. This package makes this possible for me. It is a pretty narrow use case, but perhaps this package can grow to be more general over time.

Examples

// listen on the same port. oh yeah.
l1, _ := reuse.Listen("tcp", "127.0.0.1:1234")
l2, _ := reuse.Listen("tcp", "127.0.0.1:1234")
// dial from the same port. oh yeah.
l1, _ := reuse.Listen("tcp", "127.0.0.1:1234")
l2, _ := reuse.Listen("tcp", "127.0.0.1:1235")
c, _ := reuse.Dial("tcp", "127.0.0.1:1234", "127.0.0.1:1235")

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

Tested

Tested on darwin and linux.

Description
reuse tcp/udp ports in golang
Readme ISC 364 KiB
Languages
Go 100%