package reuseport

import "github.com/valyala/fasthttp/reuseport"

Index

Examples

Functions

func Listen

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

Listen always returns ErrNoReusePort on Windows

Example

Code:play 

package main

import (
	"fmt"
	"log"

	"github.com/valyala/fasthttp"
	"github.com/valyala/fasthttp/reuseport"
)

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!")
}

Types

type ErrNoReusePort

type ErrNoReusePort struct {
	// contains filtered or unexported fields
}

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

func (*ErrNoReusePort) Error

func (e *ErrNoReusePort) Error() string

Error implements error interface.

Source Files

reuseport_error.go reuseport_windows.go

Version
v1.13.1
Published
May 25, 2020
Platform
windows/amd64
Imports
2 packages
Last checked
2 months ago

Tools for package owners.