From: Brendan Hansen Date: Thu, 21 Dec 2023 20:32:16 +0000 (-0600) Subject: fixed: bugs in Onyx platform networking with UDP X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=20783d1068c2b19c900f4725ebf99c198c4fd165;p=onyx.git fixed: bugs in Onyx platform networking with UDP --- diff --git a/core/runtime/platform/onyx/net.onyx b/core/runtime/platform/onyx/net.onyx index 9579cdd4..41518b7c 100644 --- a/core/runtime/platform/onyx/net.onyx +++ b/core/runtime/platform/onyx/net.onyx @@ -117,7 +117,7 @@ __net_sock_recv_from :: (s: SocketData, buf: [] u8, out: &SocketAddress) -> Resu addr_len := 512; recieved := __net_recvfrom(s, buf, &addr_buf, &addr_len); - if recieved == 0 || recieved == -1 + if recieved == -1 { return .{ Err = .EOF }; } @@ -141,7 +141,7 @@ __net_sock_send_to :: (s: SocketData, buf: [] u8, addr: &SocketAddress) -> Resul case h: .HostPort => __net_sendto_host(s, buf, h.host, h.port); }; - if sent == 0 || sent == -1 + if sent == -1 { // If there was an error sending data, call the connection closed. return .{ Err = .EOF }; @@ -246,12 +246,12 @@ __net_resolve :: (host: str, port: u16, out_addrs: [] SocketAddress) -> i32 { case 2 { addr_in: &sockaddr_in_t = ~~addr; - *out = .{ Inet = .{ addr_in.port, addr_in.addr } }; + *out = .{ Inet = .{ beu16_to_leu16(addr_in.port), addr_in.addr } }; } case 10 { addr_in6: &sockaddr_in6_t = ~~addr; - *out = .{ Inet6 = .{ addr_in6.port, addr_in6.addr } }; + *out = .{ Inet6 = .{ beu16_to_leu16(addr_in6.port), addr_in6.addr } }; } } } @@ -284,4 +284,11 @@ __net_resolve :: (host: str, port: u16, out_addrs: [] SocketAddress) -> i32 { __net_setting_flag :: (handle: SocketData, setting: SocketOption, value: bool) -> void --- } -} \ No newline at end of file + + beu16_to_leu16 :: (x: u16) -> u16 { + lo := x & 0xff; + hi := (x & 0xff00) >> 8; + + return hi | (lo << 8); + } +}