From 28f47daccea63d79134454bb7f42763928627210 Mon Sep 17 00:00:00 2001 From: LI Qing Date: Thu, 15 Oct 2020 11:25:57 +0800 Subject: [PATCH] Add ioctl support for FIONBIO command --- src/libos/src/fs/file_ops/ioctl/mod.rs | 2 ++ test/ioctl/main.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/libos/src/fs/file_ops/ioctl/mod.rs b/src/libos/src/fs/file_ops/ioctl/mod.rs index 02640fa7..f04fdeb8 100644 --- a/src/libos/src/fs/file_ops/ioctl/mod.rs +++ b/src/libos/src/fs/file_ops/ioctl/mod.rs @@ -30,6 +30,8 @@ impl_ioctl_nums_and_cmds! { TIOCGWINSZ => (0x5413, mut WinSize), // Set window size TIOCSWINSZ => (0x5414, WinSize), + // Set the nonblocking mode for socket + FIONBIO => (0x5421, i32), // If the given terminal was the controlling terminal of the calling process, give up this // controlling terminal. If the process was session leader, then send SIGHUP and SIGCONT to // the foreground process group and all processes in the current session lose their controlling diff --git a/test/ioctl/main.c b/test/ioctl/main.c index 05ae102a..1bd7ce06 100644 --- a/test/ioctl/main.c +++ b/test/ioctl/main.c @@ -274,6 +274,25 @@ int test_ioctl_SIOCGIFCONF(void) { return 0; } +int test_ioctl_FIONBIO(void) { + int sock = socket(AF_INET, SOCK_STREAM, 0); + + int on = 1; + if (ioctl(sock, FIONBIO, &on) < 0) { + close(sock); + THROW_ERROR("ioctl FIONBIO failed"); + } + + int actual_flags = fcntl(sock, F_GETFL); + if ((actual_flags & O_NONBLOCK) == 0) { + close(sock); + THROW_ERROR("failed to check the O_NONBLOCK flag after FIONBIO"); + } + + close(sock); + return 0; +} + // ============================================================================ // Test suite // ============================================================================ @@ -286,6 +305,7 @@ static test_case_t test_cases[] = { TEST_CASE(test_sgx_ioctl_SGXIOC_SELF_TARGET), TEST_CASE(test_sgx_ioctl_SGXIOC_CREATE_AND_VERIFY_REPORT), TEST_CASE(test_ioctl_SIOCGIFCONF), + TEST_CASE(test_ioctl_FIONBIO), }; int main() {