From e190e33d83b0cca2a116f5f49c6923087a637df9 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 18 Jan 2022 19:13:14 -0600 Subject: [PATCH] even nicer api for socket_poll_all --- core/net/net.onyx | 21 +++++---------------- modules/onyx_runtime/onyx_runtime.c | 2 +- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/core/net/net.onyx b/core/net/net.onyx index f4b8a582..45799c00 100644 --- a/core/net/net.onyx +++ b/core/net/net.onyx @@ -114,27 +114,16 @@ socket_poll_all :: (sockets: [] ^Socket, timeout := -1, changed_buffer: [] i32 = handles[i] = sockets[i].handle; } - handles_changed := cast(^Socket.Handle) alloc.from_stack(sockets.count * sizeof Socket.Handle); + handles_changed := cast(^i32) alloc.from_stack(sockets.count * sizeof i32); num_changed := __net_poll_recv(handles, timeout, handles_changed); if changed_buffer.count == 0 do return .[]; assert(changed_buffer.count >= num_changed, "Not enough space to write back changed sockets."); - result := changed_buffer; - result.count = 0; - for handles_changed[0..num_changed] { - for si: sockets.count { - if it == sockets[si].handle { - result.data[result.count] = si; - result.count += 1; - continue continue; - } - } - } - - assert(result.count == num_changed, "bad."); + changed_buffer.count = num_changed; + memory.copy(changed_buffer.data, handles_changed, num_changed * sizeof i32); - return result; + return changed_buffer; } socket_send :: (s: ^Socket, data: [] u8) -> i32 { @@ -203,7 +192,7 @@ socket_recv_into :: (s: ^Socket, buffer: [] u8) -> i32 { #package __net_connect :: (handle: Socket.Handle, host: str, port: u16) -> SocketError --- #package __net_send :: (handle: Socket.Handle, data: [] u8) -> i32 --- #package __net_recv :: (handle: Socket.Handle, data: [] u8) -> i32 --- - #package __net_poll_recv :: (handle: [] Socket.Handle, timeout: i32, out_recv: ^Socket.Handle) -> i32 --- + #package __net_poll_recv :: (handle: [] Socket.Handle, timeout: i32, out_recv_indicies: ^i32) -> i32 --- #package __net_address_get_address :: (address: Socket_Address.Handle, out_buffer: [] u8) -> i32 --- #package __net_address_get_port :: (address: Socket_Address.Handle) -> i32 --- diff --git a/modules/onyx_runtime/onyx_runtime.c b/modules/onyx_runtime/onyx_runtime.c index 91c57063..da6dc385 100644 --- a/modules/onyx_runtime/onyx_runtime.c +++ b/modules/onyx_runtime/onyx_runtime.c @@ -979,7 +979,7 @@ ONYX_DEF(__net_poll_recv, (WASM_I32, WASM_I32, WASM_I32, WASM_I32), (WASM_I32)) cursor = 0; for (i=0; idata[1].of.i32; i++) { if (fds[i].revents & POLLIN) { - *(i32 *) ONYX_PTR(params->data[3].of.i32 + 4 * cursor) = fds[i].fd; + *(i32 *) ONYX_PTR(params->data[3].of.i32 + 4 * cursor) = i; cursor++; } } -- 2.25.1