Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kavu/go_reuseport
Brings SO_REUSEPORT into your Go server
https://github.com/kavu/go_reuseport
go
Last synced: about 2 months ago
JSON representation
Brings SO_REUSEPORT into your Go server
- Host: GitHub
- URL: https://github.com/kavu/go_reuseport
- Owner: kavu
- License: mit
- Created: 2014-03-16T20:09:22.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-04-28T20:14:20.000Z (over 3 years ago)
- Last Synced: 2024-08-02T20:46:46.059Z (5 months ago)
- Topics: go
- Language: Go
- Homepage:
- Size: 52.7 KB
- Stars: 568
- Watchers: 22
- Forks: 70
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GO_REUSEPORT
[![Build Status](https://travis-ci.org/kavu/go_reuseport.png?branch=master)](https://travis-ci.org/kavu/go_reuseport)
[![codecov](https://codecov.io/gh/kavu/go_reuseport/branch/master/graph/badge.svg)](https://codecov.io/gh/kavu/go_reuseport)
[![GoDoc](https://godoc.org/github.com/kavu/go_reuseport?status.png)](https://godoc.org/github.com/kavu/go_reuseport)**GO_REUSEPORT** is a little expirement to create a `net.Listener` that supports [SO_REUSEPORT](http://lwn.net/Articles/542629/) 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](http://godoc.org/github.com/kavu/go_reuseport "go_reuseport documentation").## Example ##
```go
package mainimport (
"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](https://github.com/aartur) [post](http://freeprogrammersblog.vhex.net/post/linux-39-introdued-new-way-of-writing-socket-servers/2) about `SO_REUSEPORT`.