package reuseport
import "github.com/valyala/fasthttp/reuseport"
Index ¶
Examples ¶
Functions ¶
func Listen ¶
Listen returns TCP listener with SO_REUSEADDR option set, SO_REUSEPORT is not supported on Windows, so it uses
SO_REUSEADDR as an alternative to achieve the same effect.
Code:play
Example¶
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: %v", err)
}
if err = fasthttp.Serve(ln, requestHandler); err != nil {
log.Fatalf("error in fasthttp Server: %v", 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.41.0
- Published
- Oct 22, 2022
- Platform
- windows/amd64
- Imports
- 5 packages
- Last checked
- 2 months ago –
Tools for package owners.