]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/comm.c
use pselect and a better timeout in cnid_dbd
[netatalk.git] / etc / cnid_dbd / comm.c
index 9b3ffad5cf65073012d7faa867b9442ff1089cb2..bdc696f146f41db4ddd756d979fb8c00dec7f85e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: comm.c,v 1.4 2009-10-13 22:55:37 didg Exp $
+ * $Id: comm.c,v 1.5 2009-10-18 17:50:13 didg Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYING.
@@ -38,6 +38,7 @@
 #include <sys/socket.h>
 #endif
 
+#include <sys/select.h>
 
 #include <assert.h>
 #include <time.h>
@@ -141,11 +142,11 @@ static int recv_cred(int fd)
  *  things and clean up fd_table. The same happens for any read/write errors.
  */
 
-static int check_fd(void)
+static int check_fd(time_t timeout, const sigset_t *sigmask)
 {
     int fd;
     fd_set readfds;
-    struct timeval tv;
+    struct timespec tv;
     int ret;
     int i;
     int maxfd = control_fd;
@@ -160,9 +161,9 @@ static int check_fd(void)
             maxfd = fd_table[i].fd;
     }
 
-    tv.tv_usec = 0;
-    tv.tv_sec  = 1;
-    if ((ret = select(maxfd + 1, &readfds, NULL, NULL, &tv)) < 0) {
+    tv.tv_nsec = 0;
+    tv.tv_sec  = timeout;
+    if ((ret = pselect(maxfd + 1, &readfds, NULL, NULL, &tv, sigmask)) < 0) {
         if (errno == EINTR)
             return 0;
         LOG(log_error, logtype_cnid, "error in select: %s",strerror(errno));
@@ -250,12 +251,12 @@ int comm_nbe(void)
 }
 
 /* ------------ */
-int comm_rcv(struct cnid_dbd_rqst *rqst)
+int comm_rcv(struct cnid_dbd_rqst *rqst, time_t timeout, const sigset_t *sigmask)
 {
     char *nametmp;
     int b;
 
-    if ((cur_fd = check_fd()) < 0)
+    if ((cur_fd = check_fd(timeout, sigmask)) < 0)
         return -1;
 
     if (!cur_fd)