greuse

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 4 Imported by: 7

README

greuse Go Doc Release License

Package greuse 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.

Installation

go get -u -v github.com/gogf/greuse

or use go.mod

require github.com/gogf/greuse latest

Documentation

Quick Start

package main

import (
    "fmt"
    "github.com/gogf/greuse"
    "net/http"
    "os"
)

// We can create two processes with this code.
// Do some requests, then watch the output of the console.
func main() {
    listener, err := greuse.Listen("tcp", ":8881")
    if err != nil {
        panic(err)
    }
    defer listener.Close()

    server := &http.Server{}
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "gid: %d, pid: %d\n", os.Getgid(), os.Getpid())
    })

    panic(server.Serve(listener))
}

License

greuse is licensed under the MIT License, 100% free and open-source, forever.

Documentation

Overview

Package greuse 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 = false
)

Functions

func Control

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

See net.RawConn.Control

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 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)

ResolveAddr parses given parameters to net.Addr.

Types

This section is empty.

Jump to

Keyboard shortcuts

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