reuseable

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: MIT Imports: 5 Imported by: 2

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

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

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

func DialTimeout

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

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

func Listen

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

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

func ListenPacket

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

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

Types

This section is empty.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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