[server-dummy] Minor improvements to the dummy server.

This commit is contained in:
Ciprian Dorin Craciun 2021-12-16 11:55:04 +02:00
parent bf4ea4f10c
commit 7c18defaa9
2 changed files with 38 additions and 9 deletions

View file

@ -2,6 +2,8 @@
package main
import "fmt"
import "os"
import "runtime"
import "runtime/debug"
import "time"
@ -22,8 +24,24 @@ func main () () {
debug.SetMaxStack (16 * 1024)
_listener, _error := reuseport.Listen ("tcp4", "127.9.185.194:8080")
if _error != nil { panic (_error) }
_endpoint := "127.0.0.1:8080"
_timeouts := false
switch len (os.Args) {
case 1 :
// NOP
case 2 :
_endpoint = os.Args[1]
default :
panic ("[60023f00] invalid arguments!")
}
_listener, _error := reuseport.Listen ("tcp4", _endpoint)
if _error != nil {
panic (fmt.Sprintf ("[8c30a625] failed to listen: %s", _error))
}
fmt.Fprintf (os.Stderr, "[ii] listening on `http://%s/`...\n", _endpoint)
_server := & fasthttp.Server {
@ -43,15 +61,17 @@ func main () () {
WriteBufferSize : 16 * 1024,
MaxRequestBodySize : 16 * 1024,
// ReadTimeout : 30 * time.Second,
// WriteTimeout : 30 * time.Second,
// IdleTimeout : 360 * time.Second,
ReadTimeout : 30 * time.Second,
WriteTimeout : 30 * time.Second,
IdleTimeout : 360 * time.Second,
TCPKeepalive : true,
TCPKeepalivePeriod : 60 * time.Second,
ReduceMemoryUsage : false,
KeepHijackedConns : true,
CloseOnShutdown : true,
DisableKeepalive : false,
ErrorHandler : nil,
ConnState : nil,
@ -62,18 +82,24 @@ func main () () {
}
if !_timeouts {
_server.ReadTimeout = 0
_server.WriteTimeout = 0
_server.IdleTimeout = 0
}
_error = _server.Serve (_listener)
if _error != nil { panic (_error) }
if _error != nil {
panic (fmt.Sprintf ("[ee9bc0a5] failed to serve: %s", _error))
}
}
func serve (_context *fasthttp.RequestCtx) () {
_context.Response.Header.SetRaw (serveMeta)
_context.Response.SetBodyRaw (serveData)
}
var serveMeta = []byte ("HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\n")
var serveData = []byte ("hello world!\n")

View file

@ -1181,6 +1181,9 @@ func main_0 () (error) {
ReduceMemoryUsage : _httpServerReduceMemory,
CloseOnShutdown : true,
DisableKeepalive : false,
}
_httpsServer := & fasthttp.Server {}