summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2016-09-23 12:31:00 -0700
committerKarolin Seeger <kseeger@samba.org>2016-10-20 10:43:28 +0200
commit4212718f2c211b994429ac38be003f6381a02ea2 (patch)
tree3557b550c3b1987884ec002c93b7d9ce4270c20b
parent6b134a8d499dc1f4f9bfb50614b769c19e689907 (diff)
downloadsamba-4212718f2c211b994429ac38be003f6381a02ea2.tar.gz
s3: nmbd: Change over to using tevent functions from direct poll.
This will allow us to eventually remove source3/lib/events.c dependency and make nmbd purely tevent based. Bug: https://bugzilla.samba.org/show_bug.cgi?id=12283 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> (cherry picked from commit b857bf9b3fa3a836647edc40ead92db7b782d367)
-rw-r--r--source3/nmbd/nmbd_packets.c58
1 files changed, 38 insertions, 20 deletions
diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c
index 8d40eaf568c..10a0c0ae145 100644
--- a/source3/nmbd/nmbd_packets.c
+++ b/source3/nmbd/nmbd_packets.c
@@ -1909,14 +1909,16 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
static int listen_number = 0;
int num_sockets;
int i;
+ int loop_rtn;
+ int timeout_secs;
- int pollrtn;
- int timeout;
#ifndef SYNC_DNS
int dns_fd;
int dns_pollidx = -1;
#endif
struct processed_packet *processed_packet_list = NULL;
+ struct tevent_timer *te = NULL;
+ bool got_timeout = false;
TALLOC_CTX *frame = talloc_stackframe();
if ((fds == NULL) || rescan_listen_set) {
@@ -1972,13 +1974,17 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
#endif
for (i=0; i<num_sockets; i++) {
- fds[i].events = POLLIN|POLLHUP;
- }
-
- /* Process a signal and timer events now... */
- if (run_events_poll(nmbd_event_context(), 0, NULL, 0)) {
- TALLOC_FREE(frame);
- return False;
+ struct tevent_fd *tfd = tevent_add_fd(nmbd_event_context(),
+ frame,
+ attrs[i].fd,
+ TEVENT_FD_READ,
+ nmbd_fd_handler,
+ &attrs[i]);
+ if (tfd == NULL) {
+ TALLOC_FREE(frame);
+ return true;
+ }
+ attrs[i].triggered = false;
}
/*
@@ -1988,28 +1994,40 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
* the time we are expecting the next netbios packet.
*/
- timeout = ((run_election||num_response_packets)
- ? 1 : NMBD_SELECT_LOOP) * 1000;
+ if (run_election||num_response_packets) {
+ timeout_secs = 1;
+ } else {
+ timeout_secs = NMBD_SELECT_LOOP;
+ }
- event_add_to_poll_args(nmbd_event_context(), NULL,
- &fds, &num_sockets, &timeout);
+ te = tevent_add_timer(nmbd_event_context(),
+ frame,
+ tevent_timeval_current_ofs(timeout_secs, 0),
+ nmbd_timeout_handler,
+ &got_timeout);
+ if (te == NULL) {
+ TALLOC_FREE(frame);
+ return true;
+ }
- pollrtn = poll(fds, num_sockets, timeout);
+ loop_rtn = tevent_loop_once(nmbd_event_context());
- if (run_events_poll(nmbd_event_context(), pollrtn, fds, num_sockets)) {
+ if (loop_rtn == -1) {
TALLOC_FREE(frame);
- return False;
+ return true;
}
- if (pollrtn == -1) {
+ if (got_timeout) {
TALLOC_FREE(frame);
- return False;
+ return false;
}
#ifndef SYNC_DNS
if ((dns_fd != -1) && (dns_pollidx != -1) &&
- (fds[dns_pollidx].revents & (POLLIN|POLLHUP|POLLERR))) {
+ attrs[dns_pollidx].triggered){
run_dns_queue(msg);
+ TALLOC_FREE(frame);
+ return false;
}
#endif
@@ -2020,7 +2038,7 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election)
int client_fd;
int client_port;
- if ((fds[i].revents & (POLLIN|POLLHUP|POLLERR)) == 0) {
+ if (!attrs[i].triggered) {
continue;
}