diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-05-05 12:50:50 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-05-05 12:50:50 -0400 |
| commit | b13a02ed1aaab407a29b37bb5559639bf3a69715 (patch) | |
| tree | 4da25b198f947d548a0c636ac0d41f7c9ef2edac | |
| parent | 0a2104689b4c3c686f2268b5053ad38fd01c1d55 (diff) | |
| download | zig-b13a02ed1aaab407a29b37bb5559639bf3a69715.tar.gz zig-b13a02ed1aaab407a29b37bb5559639bf3a69715.zip | |
avoid unnecessary fcntl syscalls when setting socket flags
| -rw-r--r-- | lib/std/os.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index 74d7ec8d81..7e50ad256a 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -2173,7 +2173,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!fd_t { switch (errno(rc)) { 0 => { const fd = @intCast(fd_t, rc); - if (!have_sock_flags and filtered_sock_type != socket_type) { + if (!have_sock_flags) { try setSockFlags(fd, socket_type); } return fd; @@ -2341,7 +2341,7 @@ pub fn accept( switch (errno(rc)) { 0 => { const fd = @intCast(fd_t, rc); - if (!have_accept4 and flags != 0) { + if (!have_accept4) { try setSockFlags(fd, flags); } return fd; @@ -3277,26 +3277,26 @@ pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) FcntlError!usize { } fn setSockFlags(fd: fd_t, flags: u32) !void { - { + if ((flags & SOCK_CLOEXEC) != 0) { var fd_flags = fcntl(fd, F_GETFD, 0) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, else => |e| return e, }; - if ((flags & SOCK_CLOEXEC) != 0) fd_flags |= FD_CLOEXEC; + fd_flags |= FD_CLOEXEC; _ = fcntl(fd, F_SETFD, fd_flags) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, else => |e| return e, }; } - { + if ((flags & SOCK_NONBLOCK) != 0) { var fl_flags = fcntl(fd, F_GETFL, 0) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, else => |e| return e, }; - if ((flags & SOCK_NONBLOCK) != 0) fl_flags |= O_NONBLOCK; + fl_flags |= O_NONBLOCK; _ = fcntl(fd, F_SETFL, fl_flags) catch |err| switch (err) { error.FileBusy => unreachable, error.Locked => unreachable, |
