aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorJef Poskanzer <jef@mail.acme.com>2013-02-28 11:26:51 -0800
committerJef Poskanzer <jef@mail.acme.com>2013-02-28 11:26:51 -0800
commit0da578e79fb07478c3f9ee319913c04071d3eab1 (patch)
tree6c0c408e9152894b7ee41a871b495cbdb228cb89 /src/net.c
parent6ae6111b275458bc9086f85154bdc61f37ef04b6 (diff)
downloadiperf3-0da578e79fb07478c3f9ee319913c04071d3eab1.tar.gz
Improved version of setnonblocking() - still not used.
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/net.c b/src/net.c
index 0dd6d82..7862ee5 100644
--- a/src/net.c
+++ b/src/net.c
@@ -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;
}