diff --git a/vm/src/sys/mod.rs b/vm/src/sys/mod.rs index ca83961..fa1a358 100644 --- a/vm/src/sys/mod.rs +++ b/vm/src/sys/mod.rs @@ -152,11 +152,12 @@ impl SysState { let mut syscalls = HashMap::::new(); + // Core VM syscalls + self.reg_syscall(VM_HEAP_SIZE, SysCallFn::Fn0_1(vm_heap_size)); + self.reg_syscall(VM_RESIZE_HEAP, SysCallFn::Fn1_1(vm_resize_heap)); self.reg_syscall(MEMSET, SysCallFn::Fn3_0(memset)); self.reg_syscall(MEMSET32, SysCallFn::Fn3_0(memset32)); self.reg_syscall(MEMCPY, SysCallFn::Fn3_0(memcpy)); - self.reg_syscall(VM_HEAP_SIZE, SysCallFn::Fn0_1(vm_heap_size)); - self.reg_syscall(VM_RESIZE_HEAP, SysCallFn::Fn1_1(vm_resize_heap)); self.reg_syscall(PRINT_I64, SysCallFn::Fn1_0(print_i64)); self.reg_syscall(PRINT_F32, SysCallFn::Fn1_0(print_f32)); @@ -177,6 +178,8 @@ impl SysState self.reg_syscall(WINDOW_ON_TEXTINPUT, SysCallFn::Fn2_0(window_on_textinput)); self.reg_syscall(AUDIO_OPEN_OUTPUT, SysCallFn::Fn4_1(audio_open_output)); + + // TODO: NET_, networking syscalls } } diff --git a/vm/src/sys/net.rs b/vm/src/sys/net.rs index ea6f14e..25a5d86 100644 --- a/vm/src/sys/net.rs +++ b/vm/src/sys/net.rs @@ -1,8 +1,15 @@ use std::net::{TcpListener, TcpStream}; +use std::io::{self, Read}; use crate::vm::{VM, Value}; +// We could create a thread for the listening socket that accepts connections, +// and so simply use this socket in blocking mode + +// However, for individual TCP streams, how do we poll? +// We could use the polling crate: https://crates.io/crates/polling + /* @@ -28,3 +35,27 @@ fn main() -> std::io::Result<()> { } */ + + + + +// Non-blocking read from a TCP stream +/* +let mut stream = TcpStream::connect("127.0.0.1:7878") + .expect("Couldn't connect to the server..."); +stream.set_nonblocking(true).expect("set_nonblocking call failed"); + +let mut buf = vec![]; +loop { + match stream.read_to_end(&mut buf) { + Ok(_) => break, + Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { + // wait until network socket is ready, typically implemented + // via platform-specific APIs such as epoll or IOCP + wait_for_fd(); + } + Err(e) => panic!("encountered IO error: {e}"), + }; +}; +println!("bytes: {buf:?}"); +*/ \ No newline at end of file