s3: Use poll in smbd
authorVolker Lendecke <vl@samba.org>
Thu, 3 Feb 2011 20:55:02 +0000 (21:55 +0100)
committerVolker Lendecke <vlendec@samba.org>
Mon, 28 Feb 2011 15:40:19 +0000 (16:40 +0100)
source3/smbd/globals.h
source3/smbd/process.c

index c326846825266a53933dae051d88289d2d593b2a..b10268e6d7b1dbad41807e6e5cf522557ca1fb78 100644 (file)
@@ -18,6 +18,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include "system/select.h"
+
 #if defined(WITH_AIO)
 struct aio_extra;
 extern struct aio_extra *aio_list_head;
@@ -456,6 +458,12 @@ struct smbd_server_connection {
        bool using_smb2;
        int trans_num;
 
+       /*
+        * Cache for calling poll(2) to avoid allocations in our
+        * central event loop
+        */
+       struct pollfd *pfds;
+
        struct files_struct *files;
        struct bitmap *file_bmap;
        int real_max_open_files;
index 3c2591c32b235cb8607d93951cc91702d0857cd8..c0f33fd4f8e702b4a317449709e98fc952d86c13 100644 (file)
@@ -26,6 +26,7 @@
 #include "ctdbd_conn.h"
 #include "../lib/util/select.h"
 #include "printing/pcap.h"
+#include "system/select.h"
 
 extern bool global_machine_password_needs_changing;
 
@@ -963,31 +964,23 @@ void smbd_setup_sig_hup_handler(struct tevent_context *ev,
 
 static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *conn)
 {
-       fd_set r_fds, w_fds;
-       int selrtn;
-       struct timeval to;
-       int maxfd = 0;
-
-       to.tv_sec = SMBD_SELECT_TIMEOUT;
-       to.tv_usec = 0;
-
-       /*
-        * Setup the select fd sets.
-        */
+       int timeout;
+       int num_pfds = 0;
+       int ret;
+       bool retry;
 
-       FD_ZERO(&r_fds);
-       FD_ZERO(&w_fds);
+       timeout = SMBD_SELECT_TIMEOUT * 1000;
 
        /*
         * Are there any timed events waiting ? If so, ensure we don't
         * select for longer than it would take to wait for them.
         */
 
-       event_add_to_select_args(smbd_event_context(),
-                                &r_fds, &w_fds, &to, &maxfd);
+       event_add_to_poll_args(smbd_event_context(), conn,
+                              &conn->pfds, &num_pfds, &timeout);
 
        /* Process a signal and timed events now... */
-       if (run_events(smbd_event_context(), 0, NULL, NULL)) {
+       if (run_events_poll(smbd_event_context(), 0, NULL, 0)) {
                return NT_STATUS_RETRY;
        }
 
@@ -995,23 +988,25 @@ static NTSTATUS smbd_server_connection_loop_once(struct smbd_server_connection *
                int sav;
                START_PROFILE(smbd_idle);
 
-               selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&to);
+               ret = sys_poll(conn->pfds, num_pfds, timeout);
                sav = errno;
 
                END_PROFILE(smbd_idle);
                errno = sav;
        }
 
-       if (selrtn == -1 && errno != EINTR) {
+       if (ret == -1 && errno != EINTR) {
                return map_nt_error_from_unix(errno);
        }
 
-       if (run_events(smbd_event_context(), selrtn, &r_fds, &w_fds)) {
+       retry = run_events_poll(smbd_event_context(), ret, conn->pfds,
+                               num_pfds);
+       if (retry) {
                return NT_STATUS_RETRY;
        }
 
        /* Did we timeout ? */
-       if (selrtn == 0) {
+       if (ret == 0) {
                return NT_STATUS_RETRY;
        }