s3: Eliminate select from packet_fd_read_sync
authorVolker Lendecke <vl@samba.org>
Mon, 7 Feb 2011 15:59:38 +0000 (16:59 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 28 Feb 2011 16:52:08 +0000 (17:52 +0100)
source3/include/packet.h
source3/lib/ctdbd_conn.c
source3/lib/packet.c

index a77a1a7cbc438b3d2e4bb111f3f8a8ae23c38a14..c96a8017f898bc0520b5dd093efc174eb053ccec 100644 (file)
@@ -38,8 +38,7 @@ NTSTATUS packet_fd_read(struct packet_context *ctx);
 /*
  * Sync read, wait for the next chunk
  */
-NTSTATUS packet_fd_read_sync(struct packet_context *ctx,
-                            struct timeval *timeout);
+NTSTATUS packet_fd_read_sync(struct packet_context *ctx, int timeout);
 
 /*
  * Handle an incoming packet:
index bad5285026afb9fa175e86be766b80286b32c07d..cfe241e644e06b879b4d7645df2b0698512c706a 100644 (file)
@@ -331,13 +331,12 @@ static struct messaging_rec *ctdb_pull_messaging_rec(TALLOC_CTX *mem_ctx,
 
 static NTSTATUS ctdb_packet_fd_read_sync(struct packet_context *ctx)
 {
-       struct timeval timeout;
-       struct timeval *ptimeout;
+       int timeout = lp_ctdb_timeout();
 
-       timeout = timeval_set(lp_ctdb_timeout(), 0);
-       ptimeout = (timeout.tv_sec != 0) ? &timeout : NULL;
-
-       return packet_fd_read_sync(ctx, ptimeout);
+       if (timeout == 0) {
+               timeout = -1;
+       }
+       return packet_fd_read_sync(ctx, timeout);
 }
 
 /*
index 1abf35c51a525b3466af052e3055a29420f1df28..cce23db5516dda1761568de3046d9d7ea6bfc064 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include "../lib/util/select.h"
+#include "system/select.h"
 
 struct packet_context {
        int fd;
@@ -102,26 +103,24 @@ NTSTATUS packet_fd_read(struct packet_context *ctx)
        return NT_STATUS_OK;
 }
 
-NTSTATUS packet_fd_read_sync(struct packet_context *ctx,
-                            struct timeval *timeout)
+NTSTATUS packet_fd_read_sync(struct packet_context *ctx, int timeout)
 {
-       int res;
-       fd_set r_fds;
-
-       FD_ZERO(&r_fds);
-       FD_SET(ctx->fd, &r_fds);
-
-       res = sys_select(ctx->fd+1, &r_fds, NULL, NULL, timeout);
+       int res, revents;
 
+       res = poll_one_fd(ctx->fd, POLLIN|POLLHUP, timeout, &revents);
        if (res == 0) {
-               DEBUG(10, ("select timed out\n"));
+               DEBUG(10, ("poll timed out\n"));
                return NT_STATUS_IO_TIMEOUT;
        }
 
        if (res == -1) {
-               DEBUG(10, ("select returned %s\n", strerror(errno)));
+               DEBUG(10, ("poll returned %s\n", strerror(errno)));
                return map_nt_error_from_unix(errno);
        }
+       if ((revents & (POLLIN|POLLHUP|POLLERR)) == 0) {
+               DEBUG(10, ("socket not readable\n"));
+               return NT_STATUS_IO_TIMEOUT;
+       }
 
        return packet_fd_read(ctx);
 }