* 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-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
*/
#include <zebra.h>
+#include "log.h"
+#include "network.h"
/* Read nbytes from fd and store into ptr. */
int
}
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;
+}
#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 */