Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ Command-line flags:
------------------

-listen=":8080": The [IP]:port to listen for incoming connections on.
-socket="/run/my.sock": Unix socket to listen to (overrides TCP address).
-max_connections=4096: The maximum number of incoming connections allowed.
-period=16s: Time between each byte sent on a connection.
-response_len=10485760: The number of bytes to send total per connection.
-timeslice=50ms: How often each thread should wake up to send.
-workers=4: The number of worker threads to execute.

It defaults to dual-stack IPv4/IPv6. If you want IPv4-only, specify an IPv4
listen address, like -listen="0.0.0.0:8080".
listen address, like `-listen="0.0.0.0:8080"`.
Unix socket defaults to empty string (i.e. unused), but will override the
`-listen` address for binding purposes, if provided.

It will try to raise "ulimit -n" to the max_connections that you specify.
It defaults to raising the limit as much as it can; if you want it higher
Expand Down
21 changes: 15 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var (
listenAddr = flag.String("listen", ":8080", "The [IP]:port to listen for incoming connections on.")
unixSocket = flag.String("socket", "", "Unix socket to listen to (overrides TCP address).")
workers = flag.Int("workers", runtime.NumCPU(), "The number of worker threads to execute.")
period = flag.Duration("period", 16*time.Second, "Time between each byte sent on a connection.")
timeslice = flag.Duration("timeslice", 50*time.Millisecond, "How often each thread should wake up to send.")
Expand All @@ -38,14 +39,22 @@ func main() {
http.HandleFunc("/", tp.Handler)
http.HandleFunc("/robots.txt", robotsDisallowHandler)

log.Fatal(listenAndServe(*listenAddr))
log.Fatal(listenAndServe(*listenAddr, *unixSocket))
}

func listenAndServe(addr string) error {
func listenAndServe(addr string, socket string) error {
srv := &http.Server{Addr: addr}
ln, err := net.Listen("tcp", addr)
if err != nil {
return err
if socket == "" {
ln, err := net.Listen("tcp", addr)
if err != nil {
return err
}
return srv.Serve(NewBufSizeListener(*rcvBuf, *sndBuf, ln.(*net.TCPListener)))
} else {
ln, err := net.Listen("unix", socket)
if err != nil {
return err
}
return srv.Serve(ln)
}
return srv.Serve(NewBufSizeListener(*rcvBuf, *sndBuf, ln.(*net.TCPListener)))
}