summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorajs <ajs>2005-02-16 00:45:37 +0000
committerajs <ajs>2005-02-16 00:45:37 +0000
commita269d613fe0536a01eb86367a545e337e51d1309 (patch)
tree21e648eaac2a1569af79dcbc75a962481b6cbc75 /lib
parent6ea7cdc593f7637e26da54192ef67245185994f3 (diff)
2005-02-15 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* network.h: Declare new function set_nonblocking. Indicate that readn and writen are deprecated. * network.c: (set_nonblocking) New function to make a file descriptor non-blocking, since it seems silly to have fcntl calls sprinkled throughout the code.
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog8
-rw-r--r--lib/network.c14
-rw-r--r--lib/network.h7
3 files changed, 29 insertions, 0 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 2b29056f..ee024389 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,11 @@
+2005-02-15 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+ * network.h: Declare new function set_nonblocking. Indicate that
+ readn and writen are deprecated.
+ * network.c: (set_nonblocking) New function to make a file descriptor
+ non-blocking, since it seems silly to have fcntl calls sprinkled
+ throughout the code.
+
2005-02-14 Paul Jakma <paul.jakma@sun.com>
* stream.h: Unsigned long updated to size_t
diff --git a/lib/network.c b/lib/network.c
index e1f733cf..3b296720 100644
--- a/lib/network.c
+++ b/lib/network.c
@@ -21,6 +21,8 @@
*/
#include <zebra.h>
+#include "log.h"
+#include "network.h"
/* Read nbytes from fd and store into ptr. */
int
@@ -69,3 +71,15 @@ writen(int fd, const u_char *ptr, int nbytes)
}
return nbytes - nleft;
}
+
+int
+set_nonblocking(int fd)
+{
+ if (fcntl(fd, F_SETFL, (fcntl(fd, F_GETFL) | O_NONBLOCK)) < 0)
+ {
+ zlog_warn("fcntl failed setting fd %d non-blocking: %s",
+ fd, safe_strerror(errno));
+ return -1;
+ }
+ return 0;
+}
diff --git a/lib/network.h b/lib/network.h
index f0a7d4df..589b80e9 100644
--- a/lib/network.h
+++ b/lib/network.h
@@ -23,7 +23,14 @@
#ifndef _ZEBRA_NETWORK_H
#define _ZEBRA_NETWORK_H
+/* Both readn and writen are deprecated and will be removed. They are not
+ suitable for use with non-blocking file descriptors.
+ */
int readn (int, u_char *, int);
int writen (int, const u_char *, int);
+/* Set the file descriptor to use non-blocking I/O. Returns 0 for success,
+ -1 on error. */
+extern int set_nonblocking(int fd);
+
#endif /* _ZEBRA_NETWORK_H */