]> git.puffer.fish Git - mirror/frr.git/commitdiff
2005-02-15 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
authorajs <ajs>
Wed, 16 Feb 2005 00:45:37 +0000 (00:45 +0000)
committerajs <ajs>
Wed, 16 Feb 2005 00:45:37 +0000 (00:45 +0000)
* 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.

lib/ChangeLog
lib/network.c
lib/network.h

index 2b29056f5fc65c79b44dc40d02b66c1d7f2b6e8d..ee0243894cda7ed0da3008e8fe1bf7a97d726c92 100644 (file)
@@ -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
index e1f733cf21484bc204b7dd4427e59da128193567..3b296720df22f59c76cf824cf659b6cd16f71931 100644 (file)
@@ -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;
+}
index f0a7d4df64325bb3432daf1b5898f0f4519d2278..589b80e9c17a71ad80bc152aff9325814a9d6407 100644 (file)
 #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 */