From 25f9516752f06b5694c917ae8b34135964bc8786 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 17 Jan 2022 22:49:46 -0600 Subject: [PATCH] bugfixes with array.alloc_one --- core/container/array.onyx | 2 +- core/net/net.onyx | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/container/array.onyx b/core/container/array.onyx index 33627f0d..adad8989 100644 --- a/core/container/array.onyx +++ b/core/container/array.onyx @@ -71,7 +71,7 @@ ensure_capacity :: (arr: ^[..] $T, capacity: u32) -> bool { alloc_one :: (arr: ^[..] $T) -> ^T { if !ensure_capacity(arr, arr.count + 1) do return null; arr.count += 1; - return ^arr.data[arr.count]; + return ^arr.data[arr.count - 1]; } push :: (arr: ^[..] $T, x: T) -> bool { diff --git a/core/net/net.onyx b/core/net/net.onyx index 2610f927..a214d19b 100644 --- a/core/net/net.onyx +++ b/core/net/net.onyx @@ -108,6 +108,7 @@ socket_sendall :: (s: ^Socket, data: [] u8) { socket_recv :: (s: ^Socket, maxlen := 1024, allocator := context.allocator) -> [] u8 { buffer := alloc.from_stack(maxlen); received := __net_recv(s.handle, .{ buffer, maxlen }); + if received < 0 { s.vtable = null; return .[]; } result := memory.make_slice(u8, received, allocator=allocator); memory.copy(result.data, buffer, received); @@ -116,7 +117,9 @@ socket_recv :: (s: ^Socket, maxlen := 1024, allocator := context.allocator) -> [ } socket_recv_into :: (s: ^Socket, buffer: [] u8) -> i32 { - return __net_recv(s.handle, buffer); + received := __net_recv(s.handle, buffer); + if received < 0 { s.vtable = null; } + return received; } #local __net_socket_vtable := io.Stream_Vtable.{ @@ -124,13 +127,15 @@ socket_recv_into :: (s: ^Socket, buffer: [] u8) -> i32 { if handle == 0 do return .BadFile, 0; bytes_read := __net_recv(handle, buffer); + if bytes_read < 0 { s.vtable = null; } return .None, bytes_read; }, - write = (use p: ^Socket, buffer: [] u8) -> (io.Error, u32) { + write = (use s: ^Socket, buffer: [] u8) -> (io.Error, u32) { if handle == 0 do return .BadFile, 0; bytes_written := __net_send(handle, buffer); + if bytes_written < 0 { s.vtable = null; } return .None, bytes_written; }, -- 2.25.1