From: Brendan Hansen Date: Mon, 17 Jan 2022 22:41:50 +0000 (-0600) Subject: even more cleanup in net X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=ff91ebd5624af85f1165c8d9d68a717f7f2fc7ca;p=onyx.git even more cleanup in net --- diff --git a/core/net/net.onyx b/core/net/net.onyx index 4510f312..9f2e8cdb 100644 --- a/core/net/net.onyx +++ b/core/net/net.onyx @@ -8,45 +8,36 @@ Socket :: struct { use stream : io.Stream; handle: Handle; - close :: socket_close - bind :: socket_bind - listen :: socket_listen - accept :: socket_accept - connect :: socket_connect - send :: socket_send - sendall :: socket_sendall - recv :: socket_recv + close :: socket_close + bind :: socket_bind + listen :: socket_listen + accept :: socket_accept + connect :: socket_connect + send :: socket_send + sendall :: socket_sendall + recv :: socket_recv + recv_into :: socket_recv_into } -#foreign "onyx_runtime" { - __net_create_socket :: (out_handle: ^Socket.Handle, domain: SocketDomain, type: SocketType) -> SocketError --- - __net_close_socket :: (handle: Socket.Handle) -> void --- - __net_bind :: (handle: Socket.Handle, port: u16) -> bool --- - __net_listen :: (handle: Socket.Handle, backlog: i32) -> void --- - __net_accept :: (handle: Socket.Handle) -> Socket.Handle --- // This should also return the address, but in what format? - __net_connect :: (handle: Socket.Handle, host: str, port: u16) -> SocketError --- - __net_send :: (handle: Socket.Handle, data: [] u8) -> u32 --- - __net_recv :: (handle: Socket.Handle, data: [] u8) -> u32 --- -} - -#local { - SocketError :: enum { - None :: 0x00; - BadSettings :: 0x01; - NoHost :: 0x02; - ConnectFailed :: 0x03; - } +SocketError :: enum { + None :: 0x00; + BadSettings :: 0x01; + NoHost :: 0x02; + ConnectFailed :: 0x03; +} - SocketDomain :: enum { - Unix :: 0x00; - Inet :: 0x01; - Inet6 :: 0x02; - } +SocketDomain :: enum { + Unix :: 0x00; + Inet :: 0x01; + Inet6 :: 0x02; +} - SocketType :: enum { - Stream :: 0x00; - Dgram :: 0x01; - } +SocketType :: enum { + Stream :: 0x00; + Dgram :: 0x01; +} + +SocketSetting :: enum { } socket_create :: (domain: SocketDomain, type: SocketType) -> (Socket, SocketError) { @@ -65,6 +56,9 @@ socket_close :: (s: ^Socket) { s.vtable = null; } +socket_setting :: (s: ^Socket, setting: SocketSetting, value: u32) { +} + socket_connect :: (s: ^Socket, host: str, port: u16) -> SocketError { return __net_connect(s.handle, host, port); } @@ -136,6 +130,16 @@ socket_recv_into :: (s: ^Socket, buffer: [] u8) -> u32 { } }; +#foreign "onyx_runtime" { + #package __net_create_socket :: (out_handle: ^Socket.Handle, domain: SocketDomain, type: SocketType) -> SocketError --- + #package __net_close_socket :: (handle: Socket.Handle) -> void --- + #package __net_bind :: (handle: Socket.Handle, port: u16) -> bool --- + #package __net_listen :: (handle: Socket.Handle, backlog: i32) -> void --- + #package __net_accept :: (handle: Socket.Handle) -> Socket.Handle --- // This should also return the address, but in what format? + #package __net_connect :: (handle: Socket.Handle, host: str, port: u16) -> SocketError --- + #package __net_send :: (handle: Socket.Handle, data: [] u8) -> u32 --- + #package __net_recv :: (handle: Socket.Handle, data: [] u8) -> u32 --- +} #operator >= macro (a, b: Socket.Handle) => cast(u32) a >= cast(u32) b; #operator == macro (a, b: Socket.Handle) => cast(u32) a == cast(u32) b;