s4:heimdal: import lorikeet-heimdal-202201172009 (commit 5a0b45cd723628b3690ea848548b...
[samba.git] / source4 / heimdal / lib / roken / socket.c
index 017d6252ea16e02593fa2f4a0b90b15d97bdd312..9feb343f50836c74d3b993fd5138de6be1d1cba0 100644 (file)
@@ -259,6 +259,28 @@ socket_set_tos (rk_socket_t sock, int tos)
 #endif
 }
 
+/*
+ * Set the non-blocking-ness of the socket.
+ */
+
+ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
+socket_set_nonblocking(rk_socket_t sock, int nonblock)
+{
+#if defined(O_NONBLOCK)
+    int flags = fcntl(sock, F_GETFL, 0);
+    if (flags == -1)
+       return;
+    if (nonblock)
+       flags |= O_NONBLOCK;
+    else
+       flags &= ~O_NONBLOCK;
+    fcntl(sock, F_SETFL, flags);
+#elif defined(FIOBIO)
+    int flags = !!nonblock;
+    return ioctl(sock, FIOBIO, &flags);
+#endif
+}
+
 /*
  * set the reuse of addresses on `sock' to `val'.
  */
@@ -283,6 +305,16 @@ socket_set_ipv6only (rk_socket_t sock, int val)
 #endif
 }
 
+/*
+ * Set the that the `sock' keepalive setting.
+ */
+
+ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
+socket_set_keepalive(rk_socket_t sock, int val)
+{
+    setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&val, sizeof(val));
+}
+
 /**
  * Create a file descriptor from a socket
  *