From a8070a429a43f9e180fa1bc21c3c6fed9d5a292b Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Tue, 28 Jun 2022 17:11:46 +0200 Subject: [PATCH] libc: propagate fd flags in socket_fs_plugin When creating a socket, fd flags can be specified by ORing them with the socket type. Most importantly, the flag SOCK_NONBLOCK must be propagated to the Socket_fs::Context in order to support non-blocking recv/send. genodelabs/genode#4550 --- repos/libports/src/lib/libc/socket_fs_plugin.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/repos/libports/src/lib/libc/socket_fs_plugin.cc b/repos/libports/src/lib/libc/socket_fs_plugin.cc index 7295ab3be7..e9d7a044dd 100644 --- a/repos/libports/src/lib/libc/socket_fs_plugin.cc +++ b/repos/libports/src/lib/libc/socket_fs_plugin.cc @@ -1065,6 +1065,13 @@ extern "C" int socket_fs_socket(int domain, int type, int protocol) Socket_fs::Context(proto, handle_fd); } catch (New_socket_failed) { return Errno(ENFILE); } + if (context) { + int flags = 0; + if (type & SOCK_NONBLOCK) flags |= O_NONBLOCK; + if (type & SOCK_CLOEXEC) flags |= O_CLOEXEC; + context->fd_flags(flags); + } + File_descriptor *fd = file_descriptor_allocator()->alloc(&plugin(), context); if (!fd) { Libc::Allocator alloc { };