diff options
author | Jef Poskanzer <jef@mail.acme.com> | 2013-02-28 11:26:51 -0800 |
---|---|---|
committer | Jef Poskanzer <jef@mail.acme.com> | 2013-02-28 11:26:51 -0800 |
commit | 0da578e79fb07478c3f9ee319913c04071d3eab1 (patch) | |
tree | 6c0c408e9152894b7ee41a871b495cbdb228cb89 /src/net.c | |
parent | 6ae6111b275458bc9086f85154bdc61f37ef04b6 (diff) | |
download | iperf3-0da578e79fb07478c3f9ee319913c04071d3eab1.tar.gz |
Improved version of setnonblocking() - still not used.
Diffstat (limited to 'src/net.c')
-rw-r--r-- | src/net.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -251,17 +251,21 @@ set_tcp_options(int sock, int no_delay, int mss) /****************************************************************************/ -// XXX: This function is not being used. int -setnonblocking(int sock) +setnonblocking(int fd) { - int opts = 0; + int flags, newflags; - opts = (opts | O_NONBLOCK); - if (fcntl(sock, F_SETFL, opts) < 0) - { - perror("fcntl(F_SETFL)"); + flags = fcntl(fd, F_GETFL, 0); + if (flags < 0) { + perror("fcntl(F_GETFL)"); return -1; } + newflags = flags | (int) O_NONBLOCK; + if (newflags != flags) + if (fcntl(fd, F_SETFL, newflags) < 0) { + perror("fcntl(F_SETFL)"); + return -1; + } return 0; } |