Skip to content

TinyGophers together stronk - httphi replace both httpraw and net/http (1000x heap usage reduction) - #60

Open
soypat wants to merge 3 commits into
mainfrom
httphi
Open

TinyGophers together stronk - httphi replace both httpraw and net/http (1000x heap usage reduction)#60
soypat wants to merge 3 commits into
mainfrom
httphi

Conversation

@soypat

@soypat soypat commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

So I saw an opportunity to ditch net/http entirely (Except client case) which seems like a huge win especially when the resulting HTTP handling reads better in most cases (except form parsing, though more explicit on what is happening). Check it out!

I do keep net dependency for net.Listener though- it is a very nice abstraction.

@deadprogram

Copy link
Copy Markdown
Member

I was not able to get the webserver example running. Here is my pcapdebug output, perhaps you can spot something.

$ tinygo flash -target xiao-esp32c3 -ldflags="-X main.ssid=XXXX -X main.password=YYYYYYYYYYY" -size short -monitor -tags pcapdebug ./examples/webserver/
   code    data     bss |   flash     ram
 967278   33940  102636 | 1001218  136576
Connecting to /dev/ttyACM0...
Connected.
Detected chip: ESP32-C3
USB-JTAG/Serial interface detected, disabling watchdogs
Loading stub loader...
Stub running.
Erasing flash...
[##################################################]  100.0%
Flash erased.
Attaching SPI flash...
Configuring flash size...
Auto-detected flash size: 4MB
Flash params set to 0x022F
SHA digest in image updated
Attaching SPI flash...
Switching to 460800 baud...
Running at 460800 baud.
Compressed 1001312 bytes to 635921 (64%)
Flash begin: 635921 bytes at 0x00000000 (39 compressed blocks)
[##################################################]  100.0%
Flash complete. Verifying...
MD5 verified: c51b944ac13cbf7cb6faa037a1cb7267

Device reset.
Connected to /dev/ttyACM0. Press Ctrl-C to exit.
SHA-256 comparison failed:
Calculated: eede96c9bfe83c8fc3d1a84c4d8eaaf78590af839550be5d1ad6d02cc0aa49af
Expected: a3194cc2c324d392d8019b1f3619d2b4860c6199383170ad3643fa42321ccfe1
Attempting to boot anyway...
entry 0x4039aef0
Connecting to WiFi...
3.512 OUT 340 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=b0:a6:04:04:b4:70; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0x00; (Total Length)=326; identification=0xc5c6; flags=0x4000; (Time to live)=0x40; protocol=0x11; checksum=0x73e1; source=0.0.0.0; destination=255.255.255.255 | UDP len=8; (Source port)=68; (Destination port)=67; size=306; checksum=0x48a5 | DHCPv4 len=240; op=1; (Hardware Address Type)=0x01; (Hardware Address Length)=6; Hops=0x00; (Transaction ID)=0xd3a01665; (Start Time)=0x0001; Flags=0x0000; (Client Address)=0.0.0.0; (Offered Address)=0.0.0.0; (Server Next Address)=255.255.255.255; (Relay Agent Address)=0.0.0.0; (Client Hardware Address)=b0:a6:04:04:b4:70
3.543 IN  340 Ethernet len=14; destination=b0:a6:04:04:b4:70; source=74:24:9f:97:ca:0d; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0x00; (Total Length)=326; identification=0xa19a; flags=0x4000; (Time to live)=0x40; protocol=0x11; checksum=0x1414; source=192.168.1.1; destination=192.168.1.167 | UDP len=8; (Source port)=67; (Destination port)=68; size=306; checksum=0x0cd5 | DHCPv4 len=240; op=2; (Hardware Address Type)=0x01; (Hardware Address Length)=6; Hops=0x00; (Transaction ID)=0xd3a01665; (Start Time)=0x0000; Flags=0x0000; (Client Address)=0.0.0.0; (Offered Address)=192.168.1.167; (Server Next Address)=192.168.1.1; (Relay Agent Address)=0.0.0.0; (Client Hardware Address)=b0:a6:04:04:b4:70
3.543 OUT 338 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=b0:a6:04:04:b4:70; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0x00; (Total Length)=324; identification=0xc5c7; flags=0x4000; (Time to live)=0x40; protocol=0x11; checksum=0x73e2; source=0.0.0.0; destination=255.255.255.255 | UDP len=8; (Source port)=68; (Destination port)=67; size=304; checksum=0xd768 | DHCPv4 len=240; op=1; (Hardware Address Type)=0x01; (Hardware Address Length)=6; Hops=0x00; (Transaction ID)=0xd3a01665; (Start Time)=0x0001; Flags=0x0000; (Client Address)=0.0.0.0; (Offered Address)=192.168.1.167; (Server Next Address)=192.168.1.1; (Relay Agent Address)=0.0.0.0; (Client Hardware Address)=b0:a6:04:04:b4:70
3.586 IN  340 Ethernet len=14; destination=b0:a6:04:04:b4:70; source=74:24:9f:97:ca:0d; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0x00; (Total Length)=326; identification=0xa19d; flags=0x4000; (Time to live)=0x40; protocol=0x11; checksum=0x1411; source=192.168.1.1; destination=192.168.1.167 | UDP len=8; (Source port)=67; (Destination port)=68; size=306; checksum=0x09d5 | DHCPv4 len=240; op=2; (Hardware Address Type)=0x01; (Hardware Address Length)=6; Hops=0x00; (Transaction ID)=0xd3a01665; (Start Time)=0x0000; Flags=0x0000; (Client Address)=0.0.0.0; (Offered Address)=192.168.1.167; (Server Next Address)=192.168.1.1; (Relay Agent Address)=0.0.0.0; (Client Hardware Address)=b0:a6:04:04:b4:70
3.612 OUT 60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=b0:a6:04:04:b4:70; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=b0:a6:04:04:b4:70; (Sender protocol address)=192.168.1.167; (Target hardware address)=00:00:00:00:00:00; (Target protocol address)=192.168.1.1
3.617 IN  60 Ethernet len=14; destination=b0:a6:04:04:b4:70; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=2; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=b0:a6:04:04:b4:70; (Target protocol address)=192.168.1.167
HTTP server listening on http://192.168.1.167:80
4.852 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
6.287 IN  86 Ethernet len=14; destination=33:33:ff:cb:7e:54; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=fd25:89f9:465d:0:81e4:c82b:9cb:7e54 | unknown proto len=32; undefined=0x87004c0e00000000fd2589f9465d000081e4c82b09cb7e5401019483c4b73bbb
6.287 IN  86 Ethernet len=14; destination=33:33:ff:6d:d3:cc; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=fd25:89f9:465d:0:98f2:9854:706d:d3cc | unknown proto len=32; undefined=0x8700056b00000000fd2589f9465d000098f29854706dd3cc01019483c4b73bbb
6.288 IN  86 Ethernet len=14; destination=33:33:ff:ba:62:38; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2a0d:3344:28ea:cc00:4b33:5d31:fba:6238 | unknown proto len=32; undefined=0x8700b240000000002a0d334428eacc004b335d310fba623801019483c4b73bbb
6.290 IN  86 Ethernet len=14; destination=33:33:ff:73:1e:26; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2a0d:3344:28ea:cc00:8533:b096:1773:1e26 | unknown proto len=32; undefined=0x87001028000000002a0d334428eacc008533b09617731e2601019483c4b73bbb
6.291 IN  86 Ethernet len=14; destination=33:33:ff:fd:80:b0; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=fd25:89f9:465d:0:4851:d81c:6dfd:80b0 | unknown proto len=32; undefined=0x8700d23500000000fd2589f9465d00004851d81c6dfd80b001019483c4b73bbb
6.298 IN  86 Ethernet len=14; destination=33:33:ff:f4:6b:7b; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=fd25:89f9:465d:0:1496:994c:5bf4:6b7b | unknown proto len=32; undefined=0x870005c900000000fd2589f9465d00001496994c5bf46b7b01019483c4b73bbb
6.298 IN  86 Ethernet len=14; destination=33:33:ff:2a:01:01; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2600:1f16:d83:1200:6d30:5f74:cb2a:101 | unknown proto len=32; undefined=0x870090930000000026001f160d8312006d305f74cb2a010101019483c4b73bbb
6.300 IN  86 Ethernet len=14; destination=33:33:ff:88:ac:dd; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2a0d:3344:28ea:cc00:6b26:4d1f:d588:acdd | unknown proto len=32; undefined=0x87007196000000002a0d334428eacc006b264d1fd588acdd01019483c4b73bbb
6.301 IN  86 Ethernet len=14; destination=33:33:ff:00:20:0a; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2a00:1450:4003:818::200a | unknown proto len=32; undefined=0x87003e7c000000002a00145040030818000000000000200a01019483c4b73bbb
6.303 IN  86 Ethernet len=14; destination=33:33:ff:00:00:5f; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2607:f8b0:4002:c08::5f | unknown proto len=32; undefined=0x8700b524000000002607f8b040020c08000000000000005f01019483c4b73bbb
6.596 IN  60 Ethernet len=14; destination=01:00:5e:00:00:01; source=74:24:9f:97:ca:0d; protocol=0x0800 | IPv4 len=24; version=0x04; (Header Length)=6; (Type of Service)=0xc0; (Total Length)=32; identification=0x0000; flags=0x4000; (Time to live)=0x01; protocol=0x02; checksum=0x0417; source=0.0.0.0; destination=224.0.0.1; options=0x94040000 errs=(incorrect checksum) | unknown proto len=8; undefined=0x1164ee9b00000000
6.903 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
7.210 IN  86 Ethernet len=14; destination=33:33:00:00:00:02; source=74:24:9f:97:ca:0d; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::7624:9fff:fe97:ca0d; source=ff02::2 | unknown proto len=32; undefined=0x3a000502000001008400a05300000000ff050000000000000000000000010003
7.311 IN  86 Ethernet len=14; destination=33:33:00:00:00:02; source=74:24:9f:97:ca:0d; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::7624:9fff:fe97:ca0d; source=ff02::2 | unknown proto len=32; undefined=0x3a000502000001008400a05700000000ff020000000000000000000000010002
7.412 IN  60 Ethernet len=14; destination=01:00:5e:00:00:fb; source=e4:c7:67:65:0e:46; protocol=0x0800 | IPv4 len=24; version=0x04; (Header Length)=6; (Type of Service)=0xc0; (Total Length)=32; identification=0x0000; flags=0x4000; (Time to live)=0x01; protocol=0x02; checksum=0x4095; source=192.168.1.223; destination=224.0.0.251; options=0x94040000 errs=(incorrect checksum) | unknown proto len=8; undefined=0x16000904e00000fb
8.232 IN  230 Ethernet len=14; destination=33:33:00:00:00:01; source=74:24:9f:97:ca:0d; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x0e2db2; (Total Length)=176; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::7624:9fff:fe97:ca0d; source=ff02::1 | unknown proto len=176; undefined=0x8600a71440c801200000000000000000010174249f97ca0d05010000000005dc030440c0000001210000008b000000002a0d334428eacc000000000000000000030440c0ffffffffffffffff00000000fd2589f9465d0000000000000000000018033808000001212a0d334428eacc00000000000000000018033008fffffffffd2589f9465d0000000000000000000019030000000003c0fd2589f9465d000000000000000000010701000000017700
8.233 IN  250 Ethernet len=14; destination=33:33:00:00:00:16; source=1c:83:41:30:92:2a; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=196; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::1894:1c69:b15:118b; source=ff02::16 | unknown proto len=196; undefined=0x3a000502000001008f00e5f20000000904000000ff0200000000000000000001ff88acdd04000000ff0200000000000000000001fff46b7b04000000ff0200000000000000000001ff000a4d04000000ff0200000000000000000000000000fb04000000ff0200000000000000000001ff731e2604000000ff0200000000000000000001ff5ed12904000000ff0200000000000000000001fffd80b004000000ff0200000000000000000001ffcb7e5404000000ff0200000000000000000001ff15118b
8.235 IN  210 Ethernet len=14; destination=33:33:00:00:00:16; source=e4:c7:67:65:0e:46; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=156; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::b787:1ceb:8f9b:504f; source=ff02::16 | unknown proto len=156; undefined=0x3a000502000001008f00a39f0000000704000000ff0200000000000000000001ff0006eb04000000ff0200000000000000000000000000fb04000000ff0200000000000000000001ffba623804000000ff0200000000000000000001ff795a8604000000ff0200000000000000000001ff21205504000000ff0200000000000000000001ff6dd3cc04000000ff0200000000000000000001ff9b504f
8.337 IN  210 Ethernet len=14; destination=33:33:00:00:00:16; source=e4:c7:67:65:0e:46; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=156; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::b787:1ceb:8f9b:504f; source=ff02::16 | unknown proto len=156; undefined=0x3a000502000001008f00a39f0000000704000000ff0200000000000000000001ff0006eb04000000ff0200000000000000000000000000fb04000000ff0200000000000000000001ffba623804000000ff0200000000000000000001ff795a8604000000ff0200000000000000000001ff21205504000000ff0200000000000000000001ff6dd3cc04000000ff0200000000000000000001ff9b504f
8.846 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
9.052 IN  250 Ethernet len=14; destination=33:33:00:00:00:16; source=1c:83:41:30:92:2a; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=196; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::1894:1c69:b15:118b; source=ff02::16 | unknown proto len=196; undefined=0x3a000502000001008f00e5f20000000904000000ff0200000000000000000001ff88acdd04000000ff0200000000000000000001fff46b7b04000000ff0200000000000000000001ff000a4d04000000ff0200000000000000000000000000fb04000000ff0200000000000000000001ff731e2604000000ff0200000000000000000001ff5ed12904000000ff0200000000000000000001fffd80b004000000ff0200000000000000000001ffcb7e5404000000ff0200000000000000000001ff15118b
10.894 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
12.942 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
14.890 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
14.890 IN  211 Ethernet len=14; destination=33:33:00:01:00:02; source=1c:83:41:30:92:2a; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x0c9f14; (Total Length)=157; (Next Header)=0x11; (Hop Limit)=0x01; source=fe80::1894:1c69:b15:118b; source=ff02::1:2 | UDP len=8; (Source port)=546; (Destination port)=547; size=157; checksum=0x3440
14.892 IN  250 Ethernet len=14; destination=33:33:00:00:00:16; source=1c:83:41:30:92:2a; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=196; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::1894:1c69:b15:118b; source=ff02::16 | unknown proto len=196; undefined=0x3a000502000001008f00e5f20000000904000000ff0200000000000000000001ff88acdd04000000ff0200000000000000000001fff46b7b04000000ff0200000000000000000001ff000a4d04000000ff0200000000000000000000000000fb04000000ff0200000000000000000001ff731e2604000000ff0200000000000000000001ff5ed12904000000ff0200000000000000000001fffd80b004000000ff0200000000000000000001ffcb7e5404000000ff0200000000000000000001ff15118b
15.195 IN  250 Ethernet len=14; destination=33:33:00:00:00:16; source=1c:83:41:30:92:2a; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=196; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::1894:1c69:b15:118b; source=ff02::16 | unknown proto len=196; undefined=0x3a000502000001008f00e5f20000000904000000ff0200000000000000000001ff88acdd04000000ff0200000000000000000001fff46b7b04000000ff0200000000000000000001ff000a4d04000000ff0200000000000000000000000000fb04000000ff0200000000000000000001ff731e2604000000ff0200000000000000000001ff5ed12904000000ff0200000000000000000001fffd80b004000000ff0200000000000000000001ffcb7e5404000000ff0200000000000000000001ff15118b
15.704 IN  74 Ethernet len=14; destination=b0:a6:04:04:b4:70; source=e4:c7:67:65:0e:46; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0x00; (Total Length)=60; identification=0xfde6; flags=0x4000; (Time to live)=0x40; protocol=0x06; checksum=0xb7fe; source=192.168.1.223; destination=192.168.1.167 | TCP len=40; (Source port)=41074; (Destination port)=80; (Sequence number)=0x090c39f9; (Acknowledgement number)=0x00000000; (Header length)=10; flags=SYN; Window=0xfaf0; checksum=0x063a; options=0x020405b40402080a12c3cb70000000000103030a
15.704 OUT 60 Ethernet len=14; destination=74:24:9f:97:ca:0d; source=b0:a6:04:04:b4:70; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0x00; (Total Length)=40; identification=0x2f89; flags=0x4000; (Time to live)=0x40; protocol=0x06; checksum=0x8670; source=192.168.1.167; destination=192.168.1.223 | TCP len=20; (Source port)=80; (Destination port)=41074; (Sequence number)=0x00000000; (Acknowledgement number)=0x090c39fa; (Header length)=5; flags=RST,ACK; Window=0x0000; checksum=0x4731
15.706 IN  74 Ethernet len=14; destination=b0:a6:04:04:b4:70; source=e4:c7:67:65:0e:46; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0x00; (Total Length)=60; identification=0x3d9e; flags=0x4000; (Time to live)=0x40; protocol=0x06; checksum=0x7847; source=192.168.1.223; destination=192.168.1.167 | TCP len=40; (Source port)=41076; (Destination port)=80; (Sequence number)=0x7facf6b4; (Acknowledgement number)=0x00000000; (Header length)=10; flags=SYN; Window=0xfaf0; checksum=0xd2d7; options=0x020405b40402080a12c3cb74000000000103030a
15.708 OUT 60 Ethernet len=14; destination=74:24:9f:97:ca:0d; source=b0:a6:04:04:b4:70; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0x00; (Total Length)=40; identification=0x850f; flags=0x4000; (Time to live)=0x40; protocol=0x06; checksum=0x30ea; source=192.168.1.167; destination=192.168.1.223 | TCP len=20; (Source port)=80; (Destination port)=41076; (Sequence number)=0x00000000; (Acknowledgement number)=0x7facf6b5; (Header length)=5; flags=RST,ACK; Window=0x0000; checksum=0x13d3
15.721 IN  82 Ethernet len=14; destination=b0:a6:04:04:b4:70; source=74:24:9f:97:ca:0d; protocol=0x0800 | IPv4 len=20; version=0x04; (Header Length)=5; (Type of Service)=0xc0; (Total Length)=68; identification=0x428a; flags=0x0000; (Time to live)=0x40; protocol=0x01; checksum=0xb376; source=192.168.1.1; destination=192.168.1.167 | ICMP len=48; type=0x05; Code=0x01; checksum=0xbd68; (Gateway Address)=192.168.1.223; (Original Datagram)=0x450000282f8940003f068770c0a801a7c0a801df0050a07200000000090c39fa5014000047310000
16.526 IN  86 Ethernet len=14; destination=33:33:ff:6d:d3:cc; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=fd25:89f9:465d:0:98f2:9854:706d:d3cc | unknown proto len=32; undefined=0x8700056b00000000fd2589f9465d000098f29854706dd3cc01019483c4b73bbb
16.526 IN  86 Ethernet len=14; destination=33:33:ff:ba:62:38; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2a0d:3344:28ea:cc00:4b33:5d31:fba:6238 | unknown proto len=32; undefined=0x8700b240000000002a0d334428eacc004b335d310fba623801019483c4b73bbb
16.528 IN  86 Ethernet len=14; destination=33:33:ff:f4:6b:7b; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=fd25:89f9:465d:0:1496:994c:5bf4:6b7b | unknown proto len=32; undefined=0x870005c900000000fd2589f9465d00001496994c5bf46b7b01019483c4b73bbb
16.530 IN  86 Ethernet len=14; destination=33:33:ff:88:ac:dd; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2a0d:3344:28ea:cc00:6b26:4d1f:d588:acdd | unknown proto len=32; undefined=0x87007196000000002a0d334428eacc006b264d1fd588acdd01019483c4b73bbb
16.531 IN  86 Ethernet len=14; destination=33:33:ff:00:00:5f; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2607:f8b0:4002:c08::5f | unknown proto len=32; undefined=0x8700b524000000002607f8b040020c08000000000000005f01019483c4b73bbb
16.537 IN  86 Ethernet len=14; destination=33:33:ff:00:20:0e; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2a00:1450:4003:809::200e | unknown proto len=32; undefined=0x87003e92000000002a00145040030809000000000000200e01019483c4b73bbb
16.538 IN  86 Ethernet len=14; destination=33:33:ff:00:00:10; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2607:6bc0::10 | unknown proto len=32; undefined=0x870067b80000000026076bc000000000000000000000001001019483c4b73bbb
16.539 IN  86 Ethernet len=14; destination=33:33:ff:cb:7e:54; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=fd25:89f9:465d:0:81e4:c82b:9cb:7e54 | unknown proto len=32; 
undefined=0x87004c0e00000000fd2589f9465d000081e4c82b09cb7e5401019483c4b73bbb
16.541 IN  86 Ethernet len=14; destination=33:33:ff:73:1e:26; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=2a0d:3344:28ea:cc00:8533:b096:1773:1e26 | unknown proto len=32; undefined=0x87001028000000002a0d334428eacc008533b09617731e2601019483c4b73bbb
16.542 IN  86 Ethernet len=14; destination=33:33:ff:fd:80:b0; source=94:83:c4:b7:3b:bb; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::48bc:60ff:fedf:b029; source=fd25:89f9:465d:0:4851:d81c:6dfd:80b0 | unknown proto len=32; undefined=0x8700d23500000000fd2589f9465d00004851d81c6dfd80b001019483c4b73bbb
16.629 IN  86 Ethernet len=14; destination=33:33:ff:58:3a:6d; source=94:83:c4:b7:42:41; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::4466:92ff:fe6a:bb2d; source=2a0d:3344:28ea:cc00:a49:e0c8:8458:3a6d | unknown proto len=32; undefined=0x87005480000000002a0d334428eacc000a49e0c884583a6d01019483c4b74241
16.629 IN  86 Ethernet len=14; destination=33:33:ff:6d:d3:cc; source=94:83:c4:b7:42:41; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x3a; (Hop Limit)=0xff; source=fe80::4466:92ff:fe6a:bb2d; source=fd25:89f9:465d:0:98f2:9854:706d:d3cc | unknown proto len=32; undefined=0x8700c6ab00000000fd2589f9465d000098f29854706dd3cc01019483c4b74241
16.938 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
18.881 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
20.724 IN  60 Ethernet len=14; destination=b0:a6:04:04:b4:70; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=00:00:00:00:00:00; (Target protocol address)=192.168.1.167
20.725 OUT 60 Ethernet len=14; destination=74:24:9f:97:ca:0d; source=b0:a6:04:04:b4:70; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=2; (Sender hardware address)=b0:a6:04:04:b4:70; (Sender protocol address)=192.168.1.167; (Target hardware address)=74:24:9f:97:ca:0d; (Target protocol address)=192.168.1.1
20.932 IN  60 Ethernet len=14; destination=ff:ff:ff:ff:ff:ff; source=74:24:9f:97:ca:0d; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=74:24:9f:97:ca:0d; (Sender protocol address)=192.168.1.1; (Target hardware address)=ff:ff:ff:ff:ff:ff; (Target protocol address)=192.168.100.1
21.184 IN  60 Ethernet len=14; destination=b0:a6:04:04:b4:70; source=e4:c7:67:65:0e:46; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=1; (Sender hardware address)=e4:c7:67:65:0e:46; (Sender protocol address)=192.168.1.223; (Target hardware address)=00:00:00:00:00:00; (Target protocol address)=192.168.1.167
21.185 OUT 60 Ethernet len=14; destination=e4:c7:67:65:0e:46; source=b0:a6:04:04:b4:70; protocol=0x0806 | ARP len=28; (Hardware type)=0x0001; (Protocol type)=0x0800; (Hardware size)=6; (Protocol size)=4; op=2; (Sender hardware address)=b0:a6:04:04:b4:70; (Sender protocol address)=192.168.1.167; (Target hardware address)=e4:c7:67:65:0e:46; (Target protocol address)=192.168.1.223
21.443 IN  86 Ethernet len=14; destination=33:33:00:00:00:02; source=74:24:9f:97:ca:0d; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::7624:9fff:fe97:ca0d; source=ff02::2 | unknown proto len=32; undefined=0x3a000502000001008400a05300000000ff050000000000000000000000010003
21.544 IN  86 Ethernet len=14; destination=33:33:00:00:00:02; source=74:24:9f:97:ca:0d; protocol=0x86dd | IPv6 len=40; version=0x06; (Type of Service)=0x00; (Flow Label)=0x000000; (Total Length)=32; (Next Header)=0x00; (Hop Limit)=0x01; source=fe80::7624:9fff:fe97:ca0d; source=ff02::2 | unknown proto len=32; undefined=0x3a000502000001008400a05700000000ff020000000000000000000000010002

@soypat

soypat commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@deadprogram looks like net.Listener is not working correctly. If I tap in directly to lneto's StackGo it works. Will use that instead

@soypat

soypat commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Alright, not entirely happy with net.Listener failure, but that's something out of the scope of this PR

@soypat

soypat commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Also we'd need to merge soypat/lneto#173 before merging this. If it works for you too throw in a good word for the PR so we can upgrade the httphi API!


func Listen(link *netlink.Esplink, port string) (net.Listener, error) {
// Listen by asking the lneto stack for a socket directly instead of going
// through stdlib net.Listen and the netdev file descriptor layer due to a bug.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the bug?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's as if Listen never opened the port in the stack so when a TCP packet arrives at port 80 (the one it supposedly opened and did not return an error) the stack sends an RST back, which is what it should do when no socket is registered on that port.

@soypat

soypat commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Comparison

Before

~10kB of allocations every time "On" button clicked in webserver example.
nethttp.log

After

~12B of allocations every time "On" button clicked in webserver example
phi.log

@soypat soypat changed the title TinyGophers together stronk - httphi replace both httpraw and net/http TinyGophers together stronk - httphi replace both httpraw and net/http (1000x heap usage reduction) Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants