1
0
Fork 0
forked from AbleOS/ableos
ableos/sysdata/libraries/sunset_proto/src/server.hb

46 lines
1.5 KiB
Plaintext
Raw Normal View History

2024-11-10 12:57:48 -06:00
.{math, log, string, random, buffer, memory} := @use("../../stn/src/lib.hb");
.{Surface, new_surface} := @use("../../render/src/lib.hb");
.{Window, WindowProps, WindowData, MessageHeader, BUFFER, message, receive_message, send_message, await_message} := @use("./lib.hb")
2024-11-10 12:57:48 -06:00
2024-11-10 19:03:01 -06:00
WindowServer := struct {
window_count: uint,
id: uint,
// ! replace this with an actual collection when we get an allocator
2024-11-10 19:03:01 -06:00
windows: ^WindowData,
}
2024-11-10 12:57:48 -06:00
// ! in the future this should be safely handled
server := @as(WindowServer, idk)
2024-11-10 12:57:48 -06:00
start := fn(): void {
2024-11-10 19:03:01 -06:00
windows := memory.alloc(WindowData, 10)
server = .(0, buffer.create(BUFFER), windows)
log.debug("server: started server\0")
2024-11-10 12:57:48 -06:00
}
// ! this function will be rewritten to several functions that allow the server mainloop to handle these itself
2024-11-10 19:03:01 -06:00
handle_connections := fn(): bool {
recv := receive_message(MessageHeader, server.id)
2024-11-10 19:03:01 -06:00
if recv == null {
return true
}
if recv.kind == message.syn {
buffer_id := buffer.create_without_name()
send_message(MessageHeader, .(message.ack, buffer_id), server.id)
log.debug("server: sent ack\0")
resp := await_message(WindowProps, buffer_id)
log.debug("server: received props\0")
2024-11-10 19:03:01 -06:00
data := WindowData.(resp, buffer_id)
send_message(WindowData, data, buffer_id)
log.debug("server: sent window data\0");
*(server.windows + server.window_count) = data
server.window_count += 1
2024-11-10 19:03:01 -06:00
} else if recv.kind == message.shutdown {
log.warn("server: shutdown handled without validation\n\r this is temporary behaviour\0")
2024-11-10 19:03:01 -06:00
return false
2024-11-10 12:57:48 -06:00
}
2024-11-10 19:03:01 -06:00
return true
2024-11-10 12:57:48 -06:00
}