fasthttp: Index | Examples | Files

package reuseport

import ""

Package reuseport provides TCP net.Listener with SO_REUSEPORT support.

SO_REUSEPORT allows linear scaling server performance on multi-CPU servers. See for more details :)

The package is based on .



Package Files


func Listen Uses

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

Listen returns TCP listener with SO_REUSEPORT option set.

The returned listener tries enabling the following TCP options, which usually have positive impact on performance:

- TCP_DEFER_ACCEPT. This option expects that the server reads from accepted

connections before writing to them.

- TCP_FASTOPEN. See for details.

Use if you want customizing these options.

Only tcp4 and tcp6 networks are supported.

ErrNoReusePort error is returned if the system doesn't support SO_REUSEPORT.


package main

import (


func main() {
    ln, err := reuseport.Listen("tcp4", "localhost:12345")
    if err != nil {
        log.Fatalf("error in reuseport listener: %s", err)

    if err = fasthttp.Serve(ln, requestHandler); err != nil {
        log.Fatalf("error in fasthttp Server: %s", err)

func requestHandler(ctx *fasthttp.RequestCtx) {
    fmt.Fprintf(ctx, "Hello, world!")

type ErrNoReusePort Uses

type ErrNoReusePort struct {
    // contains filtered or unexported fields

ErrNoReusePort is returned if the OS doesn't support SO_REUSEPORT.

func (*ErrNoReusePort) Error Uses

func (e *ErrNoReusePort) Error() string

Error implements error interface.

Package reuseport imports 4 packages (graph) and is imported by 11 packages. Updated 2018-09-25. Refresh now. Tools for package owners.