Categorygithub.com/projecthunt/reuseable
modulepackage
0.0.7
Repository: https://github.com/projecthunt/reuseable.git
Documentation: pkg.go.dev

# README

Go Reference Coverage Status

This library helps go developers to open sockets with SO_REUSEPORT and SO_REUSEADDR flags.

Why ?

This flags will allow many processes to bind to the same port. In fact, any number of processes will be allowed to bind and the load will be spread across them.

With SO_REUSEPORT and SO_REUSEADDR each of the processes will have a separate socket descriptor. Therefore each will own a dedicated UDP or TCP receive buffer.

Installation

go get github.com/projecthunt/reuseable

Simple Example

package main

import (
	"log"
	"github.com/projecthunt/reuseable"
)

func main() {
	l1, err := reuseable.Listen("tcp", "127.0.0.1:54651")
	if err != nil {
		log.Fatalf("unable to start listener 1: %v", err)
	}

	// Listen on same port number
	l2, err := reuseable.Listen("tcp", "127.0.0.1:54651")
	if err != nil {
		log.Fatalf("unable to start listener 2: %v", err)
	}

	// If err not exists. We have two listener on the same port and same ip.
	log.Printf("Listener 1 Address: %s\n", l1.Addr().String())
	log.Printf("Listener 2 Address: %s\n", l2.Addr().String())

	l1.Close()
	l2.Close()
}

The program output:

Listener 1 Address: 127.0.0.1:54651
Listener 2 Address: 127.0.0.1:54651

LICENSE

This project is under MIT License

# Packages

No description provided by the author

# Functions

Dial do the same thing with net.Dial but with socket that have SO_REUSEADDR and SO_REUSEPORT flags.
DialTimeout do the same thing with net.DialTimeout but with socket that have SO_REUSEADDR and SO_REUSEPORT flags.
Listen do the same thing with net.Listen but with socket that have SO_REUSEADDR and SO_REUSEPORT flags.
ListenPacket do the same thing with net.ListenPacket but with socket that have SO_REUSEADDR and SO_REUSEPORT flags.