mirror of
https://github.com/soypat/lneto.git
synced 2026-08-15 12:23:44 +00:00
fix examples
This commit is contained in:
@@ -10,14 +10,19 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/soypat/lneto/http/httphi"
|
||||
"github.com/soypat/lneto/internal/rawsock"
|
||||
)
|
||||
|
||||
const (
|
||||
kB = 1 << 10
|
||||
listenPort = 8080
|
||||
bufferSizes = 2 * kB
|
||||
numGoroutines = 4
|
||||
readTimeout = 2 * time.Second
|
||||
kB = 1 << 10
|
||||
listenPort = 8080
|
||||
bufferSizes = 2 * kB
|
||||
// A browser sends around twenty header fields; a request carrying more
|
||||
// than this is answered 431 rather than parsed into memory it was not
|
||||
// given. Each field costs 8 bytes of table.
|
||||
numHeaderFields = 32
|
||||
numGoroutines = 4
|
||||
readTimeout = 2 * time.Second
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -29,7 +34,7 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
ln, err := Listen(listenPort)
|
||||
ln, err := rawsock.Listen(listenPort)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -43,6 +48,7 @@ func run() error {
|
||||
err = router.Configure(httphi.RouterConfig{
|
||||
FixedNumGoroutines: numGoroutines,
|
||||
RequestHeaderBufferSize: bufferSizes,
|
||||
RequestNumHeaderKVCap: numHeaderFields,
|
||||
ResponseHeaderMinBufferSize: bufferSizes,
|
||||
MaxAwaitingConns: 256,
|
||||
Backoff: func(consecutiveBackoffs uint) (sleepOrFlag time.Duration) {
|
||||
@@ -57,8 +63,8 @@ func run() error {
|
||||
defer router.TeardownGoroutines()
|
||||
|
||||
for {
|
||||
conn := new(Conn)
|
||||
err := ln.Accept(conn)
|
||||
conn := new(rawsock.Conn)
|
||||
err := ln.AcceptConn(conn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ func run() error {
|
||||
}()
|
||||
fmt.Println(time.Now().Format("15:04:05.000"), "writing...")
|
||||
conn.Write(req)
|
||||
hdr.Reset(nil)
|
||||
hdr.Reset(nil, 0) // No preallocation. Both key/value and raw buffer will grow and allocate.
|
||||
var needMore bool = true
|
||||
for needMore {
|
||||
_, err = hdr.ReadFromLimited(conn, 1024)
|
||||
|
||||
Reference in New Issue
Block a user