tile38/vendor/github.com/kavu/go_reuseport
tidwall 555e47036c Replaced net package with evio
- Added threads startup flag
- Replaced net package with evio
- Refactored controller into server
2018-10-28 15:51:47 -07:00
..
.circleci Replaced net package with evio 2018-10-28 15:51:47 -07:00
.gitignore Replaced net package with evio 2018-10-28 15:51:47 -07:00
.travis.yml Replaced net package with evio 2018-10-28 15:51:47 -07:00
LICENSE Replaced net package with evio 2018-10-28 15:51:47 -07:00
Makefile Replaced net package with evio 2018-10-28 15:51:47 -07:00
README.md Replaced net package with evio 2018-10-28 15:51:47 -07:00
go.mod Replaced net package with evio 2018-10-28 15:51:47 -07:00
reuseport.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
reuseport_bsd.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
reuseport_linux.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
reuseport_windows.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
tcp.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
tcp_test.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
test.bash Replaced net package with evio 2018-10-28 15:51:47 -07:00
udp.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
udp_test.go Replaced net package with evio 2018-10-28 15:51:47 -07:00

README.md

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.