aboutsummaryrefslogtreecommitdiff
path: root/core/net/socket_linux.odin
diff options
context:
space:
mode:
authorSokus <soqs687@gmail.com>2023-03-08 13:17:59 +0100
committerSokus <soqs687@gmail.com>2023-03-08 13:30:12 +0100
commit1ecab2fcbc4a52b481f185ccf87bb38c9691c39e (patch)
tree504fdf5d5635246329c3575386342b70263652a8 /core/net/socket_linux.odin
parenta262c0bbf325051891debe1a86866f5c9059ee58 (diff)
Add `set_blocking` for network sockets
Diffstat (limited to 'core/net/socket_linux.odin')
-rw-r--r--core/net/socket_linux.odin23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/net/socket_linux.odin b/core/net/socket_linux.odin
index 81419f6c9..690e09ab7 100644
--- a/core/net/socket_linux.odin
+++ b/core/net/socket_linux.odin
@@ -317,6 +317,29 @@ _set_option :: proc(s: Any_Socket, option: Socket_Option, value: any, loc := #ca
}
@(private)
+_set_blocking :: proc(socket: Any_Socket, should_block: bool) -> (err: Network_Error) {
+ socket := any_socket_to_socket(socket)
+
+ flags, getfl_err := os.fcntl(int(socket), os.F_GETFL, 0)
+ if getfl_err != os.ERROR_NONE {
+ return Set_Blocking_Error(getfl_err)
+ }
+
+ if should_block {
+ flags &= ~int(os.O_NONBLOCK)
+ } else {
+ flags |= int(os.O_NONBLOCK)
+ }
+
+ _, setfl_err := os.fcntl(int(socket), os.F_SETFL, flags)
+ if setfl_err != os.ERROR_NONE {
+ return Set_Blocking_Error(setfl_err)
+ }
+
+ return nil
+}
+
+@(private)
_endpoint_to_sockaddr :: proc(ep: Endpoint) -> (sockaddr: os.SOCKADDR_STORAGE_LH) {
switch a in ep.address {
case IP4_Address: