stack allocated structs, print ips in net examples
This commit is contained in:
@@ -22,7 +22,7 @@ struct CHIP8
|
||||
keyboard_map: Array
|
||||
|
||||
func chip8_create[] : CHIP8
|
||||
c := new CHIP8
|
||||
c := new* CHIP8
|
||||
c->memory = mem.alloc(4096)
|
||||
mem.zero(c->memory, 4096)
|
||||
c->display = mem.alloc(64*32)
|
||||
|
||||
@@ -2,12 +2,20 @@ func main[] : i64
|
||||
s : i64 = must(net.listen?(net.pack_addr(127, 0, 0, 1), 8000))
|
||||
|
||||
io.println("Listening on port 8000...")
|
||||
|
||||
resp := mem.alloc(60000)
|
||||
addr := mem.alloc(16)
|
||||
while true
|
||||
conn := net.accept(s)
|
||||
conn := net.accept(s, addr)
|
||||
if conn < 0
|
||||
continue
|
||||
|
||||
io.printf("%d.%d.%d.%d:%d\n", addr[4], addr[5], addr[6], addr[7], mem.read16be(addr + 2))
|
||||
|
||||
n := net.read(conn, resp, 60000)
|
||||
|
||||
io.print_sized(resp, n)
|
||||
io.println("")
|
||||
|
||||
net.send(conn, resp, n)
|
||||
net.close(conn)
|
||||
|
||||
@@ -8,5 +8,10 @@ func main[] : i64
|
||||
net.UDPPacket.free(pkt)
|
||||
continue
|
||||
|
||||
io.printf("%d.%d.%d.%d:%d\n", pkt->source_addr[4], pkt->source_addr[5], pkt->source_addr[6], pkt->source_addr[7], mem.read16be(pkt->source_addr + 2))
|
||||
|
||||
io.print_sized(pkt->data, pkt->size)
|
||||
io.println("")
|
||||
|
||||
net.udp_send_to(s, pkt->source_addr, pkt->data, pkt->size)
|
||||
net.UDPPacket.free(pkt)
|
||||
|
||||
Reference in New Issue
Block a user