std/lib/net/os: add bind, listen and accept for posix platforms

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2023-07-06 10:10:02 +02:00
committed by Christoffer Lerno
parent 97ded16ea2
commit df9bc377dd

View File

@@ -9,6 +9,9 @@ def NativeSocket = distinct inline Fd;
extern fn CInt connect(NativeSocket socket, SockAddrPtr address, Socklen_t address_len); extern fn CInt connect(NativeSocket socket, SockAddrPtr address, Socklen_t address_len);
extern fn NativeSocket socket(CInt af, CInt type, CInt protocol) @extern("socket"); extern fn NativeSocket socket(CInt af, CInt type, CInt protocol) @extern("socket");
extern fn int fcntl(NativeSocket socket, int cmd, ...) @extern("fcntl"); extern fn int fcntl(NativeSocket socket, int cmd, ...) @extern("fcntl");
extern fn CInt bind(NativeSocket socket, SockAddrPtr address, Socklen_t address_len) @extern("bind");
extern fn CInt listen(NativeSocket socket, CInt backlog) @extern("listen");
extern fn NativeSocket accept(NativeSocket socket, SockAddrPtr address, Socklen_t* address_len) @extern("accept");
macro void! NativeSocket.close(NativeSocket this) macro void! NativeSocket.close(NativeSocket this)
{ {
@@ -32,4 +35,4 @@ macro void! NativeSocket.set_non_blocking(NativeSocket this)
macro bool NativeSocket.is_non_blocking(NativeSocket this) macro bool NativeSocket.is_non_blocking(NativeSocket this)
{ {
return fcntl(this, F_GETFL, 0) & O_NONBLOCK == O_NONBLOCK; return fcntl(this, F_GETFL, 0) & O_NONBLOCK == O_NONBLOCK;
} }