net.connect, net.listen

This commit is contained in:
2025-07-26 13:21:37 +02:00
parent 65bdac2fe3
commit 9ae0230f5f
10 changed files with 97 additions and 150 deletions

View File

@@ -26,7 +26,7 @@ func main[] : I64
if !str.nth(memory, p)
i = i + 1
let opened: I64 = 0
while i < src_len && !(str.nth(src, i) == ']' && !opened)
while i < src_len & !(str.nth(src, i) == ']' & !opened)
if str.nth(src, i) == '['
opened = opened + 1
else if str.nth(src, i) == ']'
@@ -36,7 +36,7 @@ func main[] : I64
if str.nth(memory, p)
i = i - 1
let closed: I64 = 0
while i >= 0 && !(str.nth(src, i) == '[' && !closed)
while i >= 0 & !(str.nth(src, i) == '[' & !closed)
if str.nth(src, i) == ']'
closed = closed + 1
else if str.nth(src, i) == '['

View File

@@ -2,6 +2,6 @@ func main[] : I64
let sum: I64 = 0
for i in 0..1000
if i % 5 == 0 || i % 3 == 0
if i % 5 == 0 | i % 3 == 0
sum = sum + i
io.print_i64(sum)

View File

@@ -11,7 +11,7 @@ func rule110_step[state: Array] : Array
if i + 1 < state_len
right = state[i+1]
array.push(new_state, !((!left && !center && !right) || (left && !center && !right) || (left && center && right)))
array.push(new_state, !((!left & !center & !right) | (left & !center & !right) | (left & center & right)))
return new_state

View File

@@ -1,25 +1,7 @@
func main[] : I64
let s: I64 = c.socket(2, 1, 0)
if s < 0
dbg.panic("socket() failed")
let s: I64 = net.connect("devernay.free.fr", 80)
let port: I64 = 80
let sa: Ptr = c.calloc(1, 16)
str.set(sa, 0, 2)
str.set(sa, 1, 0)
str.set(sa, 2, bit.rshift(port, 8) && 255)
str.set(sa, 3, port && 255)
// 23.192.228.80 (example.com)
str.set(sa, 4, 23)
str.set(sa, 5, 192)
str.set(sa, 6, 228)
str.set(sa, 7, 80)
if c.connect(s, sa, 16) < 0
dbg.panic("connect() failed")
c.free(sa)
let req: String = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
let req: String = "GET /hacks/chip8/C8TECH10.HTM HTTP/1.0\r\nHost: devernay.free.fr\r\nConnection: close\r\n\r\n"
c.send(s, req, c.strlen(req), 0)
let resp: String = c.malloc(60000)

View File

@@ -1,26 +1,11 @@
func main[] : I64
let s: I64 = c.socket(2, 1, 0)
if s < 0
dbg.panic("socket() failed")
let port: I64 = 8080
let sa: Ptr = c.calloc(1, 16)
str.set(sa, 0, 2)
str.set(sa, 1, 0)
str.set(sa, 2, bit.rshift(port, 8) && 255)
str.set(sa, 3, port && 255)
if c.bind(s, sa, 16) < 0
dbg.panic("bind() failed")
if c.listen(s, 1) < 0
dbg.panic("listen() failed")
let s: I64 = net.listen(8000)
let resp: String = c.malloc(60000)
while true
let c: I64 = c.accept(s, 0, 0)
if c < 0
dbg.panic("accept() failed")
continue
let n: I64 = c.read(c, resp, 60000)
c.send(c, resp, n, 0)