add TCPConn Read+Write and ancilliary methods; looks like IP mux is broken

This commit is contained in:
soypat
2025-05-25 18:30:55 -03:00
parent 682e533017
commit a967f083cb
5 changed files with 232 additions and 2 deletions
+20
View File
@@ -14,9 +14,11 @@ import (
"github.com/soypat/lneto"
"github.com/soypat/lneto/arp"
"github.com/soypat/lneto/ethernet"
"github.com/soypat/lneto/http/httpraw"
"github.com/soypat/lneto/internal"
"github.com/soypat/lneto/internal/ltesto"
"github.com/soypat/lneto/internet"
"github.com/soypat/lneto/tcp"
)
const (
@@ -57,6 +59,7 @@ func main() {
fmt.Println("hosting server at ", addrPort.String())
var buf [mtu]byte
var hdr httpraw.Header
for {
nread, err := tap.Read(buf[:])
if err != nil {
@@ -81,6 +84,23 @@ func main() {
slogger.info("write", slog.Int("plen", nw))
}
}
if handler.State() == tcp.StateEstablished {
data := handler.BufferedInput()
if data > 0 {
n, err := handler.Read(buf[:])
if err != nil {
slogger.error("tcp-read", slog.String("err", err.Error()))
} else {
hdr.Reset(buf[:n])
err = hdr.Parse(false)
if err != nil {
slogger.error("http-parse", slog.String("err", err.Error()))
} else {
fmt.Println(hdr.String())
}
}
}
}
if nread == 0 && nw == 0 {
time.Sleep(5 * time.Millisecond)
}