MCPcopy Create free account
hub / github.com/kavu/go_reuseport

github.com/kavu/go_reuseport @v1.5.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.5.0 ↗ · + Follow
23 symbols 56 edges 8 files 5 documented · 22% 7 cross-repo links ● updated 5y ago★ 5731 open issues

Browse by type

⨍ Functions 23◇ Types & classes 0
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

GO_REUSEPORT

Build Status codecov GoDoc

GO_REUSEPORT is a little expirement to create a net.Listener that supports SO_REUSEPORT socket option.

For now, Darwin and Linux (from 3.9) systems are supported. I'll be pleased if you'll test other systems and tell me the results. documentation on godoc.org.

Example

package main

import (
  "fmt"
  "html"
  "net/http"
  "os"
  "runtime"
  "github.com/kavu/go_reuseport"
)

func main() {
  listener, err := reuseport.Listen("tcp", "localhost:8881")
  if err != nil {
    panic(err)
  }
  defer listener.Close()

  server := &http.Server{}
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Println(os.Getgid())
    fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path))
  })

  panic(server.Serve(listener))
}

Now you can run several instances of this tiny server without Address already in use errors.

Thanks

Inspired by Artur Siekielski post about SO_REUSEPORT.

Core symbols most depended-on inside this repo

browse all functions →

Shape

Function 23

Languages

Go100%

Modules by API surface

tcp_test.go6 symbols
reuseport.go4 symbols
udp_test.go3 symbols
udp.go3 symbols
tcp.go3 symbols
reuseport_windows.go2 symbols
reuseport_linux.go1 symbols
reuseport_bsd.go1 symbols

For agents

$ claude mcp add go_reuseport \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page