提交 1cacc01d 编写于 作者: R Rich Felker

optimize SOCK_CLOEXEC fallback for socket function

the fcntl function is heavy, so make the syscall directly instead.
also, avoid the code size and runtime overhead of querying the old
flags, since it's reasonable to assume nothing will be set on a
newly-created socket. this code is only used on old kernels which lack
proper atomic close-on-exec support, so future changes that might
invalidate such an assumption do not need to be considered.
上级 1d348566
...@@ -13,9 +13,9 @@ int socket(int domain, int type, int protocol) ...@@ -13,9 +13,9 @@ int socket(int domain, int type, int protocol)
protocol, 0, 0, 0); protocol, 0, 0, 0);
if (s < 0) return s; if (s < 0) return s;
if (type & SOCK_CLOEXEC) if (type & SOCK_CLOEXEC)
fcntl(s, F_SETFD, FD_CLOEXEC); __syscall(SYS_fcntl, s, F_SETFD, FD_CLOEXEC);
if (type & SOCK_NONBLOCK) if (type & SOCK_NONBLOCK)
fcntl(s, F_SETFL, fcntl(s, F_GETFL) | O_NONBLOCK); __syscall(SYS_fcntl, s, F_SETFL, O_NONBLOCK);
} }
return s; return s;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册