[SCM] Samba Shared Repository - branch v3-6-test updated
Volker Lendecke
vlendec at samba.org
Mon Feb 28 09:51:43 MST 2011
The branch, v3-6-test has been updated
via 3470f2f nsswitch: Eliminate select from wb_common
via 961d408 Remove sys_select[_intr]
via a8f4758 tevent: Add a poll backend
via 2fa65d2 libcli: Eliminate select from smb_readline_replacement
via 78f7259 s3: Eliminate select from libaddns
via 11fc407 s3: Eliminate sys_select from do_smb_resolve() -- untested
via eebe73c s3: Eliminate sys_select from do_smb_browse() -- untested
via 5c5ca24 s3: Eliminate sys_select_intr from smbfilter
via 4683862 s3: Remove unused receive_packet
via 6c00331 s3: Eliminate sys_select_intr from read_fd_with_timeout
via 72018af s3: Eliminiate sys_select_intr from client.c
via 62aa2a8 s3: Add poll_intr_one_fd
via 845d387 s3: Add sys_poll_intr
via 01260b7 s3: Eliminate sys_select from g_lock_lock
via 46f3b40 s3: Eliminate sys_select from fd_is_readable
via 48c9c07 s3: Eliminate select from packet_fd_read_sync
via 5c3e0b7 s3: Add poll_one_fd()
via fa14ca5 s3: Remove select-based s3 event backend
via ade1ba2 s3: Use poll in nmbd
via 46c760e s3: Use poll in winbind
via 1194a63 s3: Use poll in smbd
via 8aa2502 s3: Use poll for the event loop
via 782067d s3: Add sys_poll
via 29cb7fc libreplace: poll based on select
via 1243274 s3: Add timeval_to_msec
from ac2ccbd s3:msg_idmap: The solaris cc compiler does not like unnamed unions as struct members - fix the build
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-6-test
- Log -----------------------------------------------------------------
commit 3470f2f19e93be3e2821fedf9ccb7dffa8117f27
Author: Volker Lendecke <vl at samba.org>
Date: Fri Feb 18 13:57:35 2011 +0100
nsswitch: Eliminate select from wb_common
Autobuild-User: Volker Lendecke <vlendec at samba.org>
Autobuild-Date: Mon Feb 28 17:26:18 CET 2011 on sn-devel-104
commit 961d40893730031d3d2c4ec5cb922d6360cd8529
Author: Volker Lendecke <vl at samba.org>
Date: Fri Feb 18 12:34:08 2011 +0100
Remove sys_select[_intr]
commit a8f47581c85431368a75f357fb198c5144815c60
Author: Volker Lendecke <vl at samba.org>
Date: Wed Feb 9 15:28:10 2011 +0100
tevent: Add a poll backend
commit 2fa65d286bd9de715cf3f2cb25e4a49649f6eaf9
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 14 12:14:12 2011 +0100
libcli: Eliminate select from smb_readline_replacement
commit 78f7259208de665bf3c237b332327746d124895f
Author: Volker Lendecke <vl at samba.org>
Date: Thu Feb 10 11:01:54 2011 +0100
s3: Eliminate select from libaddns
commit 11fc407104cc5222c046d9647c5ead9b69170742
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 7 17:19:03 2011 +0100
s3: Eliminate sys_select from do_smb_resolve() -- untested
commit eebe73caf5f460b190a7857bbe2e3598db6ba09f
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 7 17:17:26 2011 +0100
s3: Eliminate sys_select from do_smb_browse() -- untested
commit 5c5ca243a397b481486983e5f6ccbbd9e3422fe4
Author: Volker Lendecke <vl at samba.org>
Date: Wed Feb 9 13:38:06 2011 +0100
s3: Eliminate sys_select_intr from smbfilter
commit 46838626a44d1f5ffd46c6ad60eb3404a5917f47
Author: Stefan Metzmacher <metze at samba.org>
Date: Fri Feb 18 12:32:12 2011 +0100
s3: Remove unused receive_packet
commit 6c003313615679a1f7b2395c2f3d6c727b4249b0
Author: Volker Lendecke <vl at samba.org>
Date: Tue Feb 8 17:57:12 2011 +0100
s3: Eliminate sys_select_intr from read_fd_with_timeout
commit 72018af1beb5c83d7ab0d65440960d1f7a900f2e
Author: Volker Lendecke <vl at samba.org>
Date: Tue Feb 8 17:56:10 2011 +0100
s3: Eliminiate sys_select_intr from client.c
commit 62aa2a88d45737e27d847e511bb304325739cf0a
Author: Volker Lendecke <vl at samba.org>
Date: Tue Feb 8 17:33:59 2011 +0100
s3: Add poll_intr_one_fd
commit 845d387e6c6b983e6cafc9592e0ac66fdaaeb676
Author: Volker Lendecke <vl at samba.org>
Date: Tue Feb 8 17:28:27 2011 +0100
s3: Add sys_poll_intr
commit 01260b72096529be21bf8a6c29396d37fce93689
Author: Volker Lendecke <vl at samba.org>
Date: Tue Feb 8 11:59:04 2011 +0100
s3: Eliminate sys_select from g_lock_lock
commit 46f3b40c8e7aab9bc46621951412b91a700e0432
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 7 17:02:44 2011 +0100
s3: Eliminate sys_select from fd_is_readable
commit 48c9c0762d212285571867b28bb7095d80d04784
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 7 16:59:38 2011 +0100
s3: Eliminate select from packet_fd_read_sync
commit 5c3e0b79b8fc7a05cb96c7af30139c081ef47076
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 7 16:55:16 2011 +0100
s3: Add poll_one_fd()
commit fa14ca5493f56782733645d6f714fb76701a23ce
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 7 15:24:07 2011 +0100
s3: Remove select-based s3 event backend
commit ade1ba24f9db9393203fad916bd78688ab780716
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 7 15:20:39 2011 +0100
s3: Use poll in nmbd
commit 46c760e1ba773bc240b2317b4a1e8386ee88ccc7
Author: Volker Lendecke <vl at samba.org>
Date: Thu Feb 3 22:05:30 2011 +0100
s3: Use poll in winbind
commit 1194a63aa54623cb8f4207c449f53342e5b87cc5
Author: Volker Lendecke <vl at samba.org>
Date: Thu Feb 3 21:55:02 2011 +0100
s3: Use poll in smbd
commit 8aa2502c87be1da726fe3c1917795715a0fca2c5
Author: Volker Lendecke <vl at samba.org>
Date: Thu Feb 3 16:34:07 2011 +0100
s3: Use poll for the event loop
commit 782067d231207d4da0bb056c43e5144f662b34c4
Author: Volker Lendecke <vl at samba.org>
Date: Mon Feb 7 16:29:13 2011 +0100
s3: Add sys_poll
commit 29cb7fc2cbc3a0f0b3497032428cccde88666627
Author: Volker Lendecke <vl at samba.org>
Date: Wed Feb 9 19:22:25 2011 +0100
libreplace: poll based on select
commit 1243274e5a93b900be59cc7c239b19d9ae848e6c
Author: Volker Lendecke <vl at samba.org>
Date: Tue Feb 8 12:55:02 2011 +0100
s3: Add timeval_to_msec
-----------------------------------------------------------------------
Summary of changes:
lib/addns/dnssock.c | 24 ++--
lib/replace/poll.c | 133 +++++++++++++++++
lib/replace/replace.h | 5 +
lib/replace/system/config.m4 | 4 +
lib/replace/system/select.h | 36 +++++
lib/replace/wscript | 4 +
lib/tevent/libtevent.m4 | 1 +
lib/tevent/tevent.c | 1 +
lib/tevent/tevent_internal.h | 1 +
lib/tevent/tevent_poll.c | 306 ++++++++++++++++++++++++++++++++++++++
lib/tevent/wscript | 1 +
lib/util/select.c | 142 ++++++------------
lib/util/select.h | 6 +-
libcli/smbreadline/smbreadline.c | 12 +-
nsswitch/wb_common.c | 55 ++++----
source3/client/client.c | 16 +--
source3/client/dnsbrowse.c | 35 +----
source3/configure.in | 2 +-
source3/include/event.h | 10 +-
source3/include/packet.h | 3 +-
source3/include/proto.h | 4 +-
source3/lib/ctdbd_conn.c | 11 +-
source3/lib/events.c | 222 ++++++++++++++++++++++-----
source3/lib/g_lock.c | 42 ++++--
source3/lib/packet.c | 21 ++--
source3/lib/util.c | 5 +
source3/lib/util_sock.c | 63 +++++++--
source3/libsmb/nmblib.c | 33 ----
source3/nmbd/nmbd_packets.c | 215 ++++++++++++++-------------
source3/smbd/globals.h | 8 +
source3/smbd/process.c | 49 +++----
source3/utils/smbfilter.c | 60 ++++++--
source3/winbindd/winbindd_dual.c | 51 ++++---
33 files changed, 1102 insertions(+), 479 deletions(-)
create mode 100644 lib/replace/poll.c
create mode 100644 lib/tevent/tevent_poll.c
Changeset truncated at 500 lines:
diff --git a/lib/addns/dnssock.c b/lib/addns/dnssock.c
index 7c8bd41..42b4e2d 100644
--- a/lib/addns/dnssock.c
+++ b/lib/addns/dnssock.c
@@ -22,9 +22,11 @@
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
+#include "replace.h"
#include "dns.h"
#include <sys/time.h>
#include <unistd.h>
+#include "system/select.h"
static int destroy_dns_connection(struct dns_connection *conn)
{
@@ -103,7 +105,7 @@ static DNS_ERROR dns_udp_open( const char *nameserver,
}
memcpy( &ulAddress, pHost->h_addr, pHost->h_length );
}
-
+
/* Create a socket for sending data */
conn->s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
@@ -143,7 +145,7 @@ DNS_ERROR dns_open_connection( const char *nameserver, int32 dwType,
case DNS_UDP:
return dns_udp_open( nameserver, mem_ctx, conn );
}
-
+
return ERROR_DNS_INVALID_PARAMETER;
}
@@ -212,21 +214,17 @@ DNS_ERROR dns_send(struct dns_connection *conn, const struct dns_buffer *buf)
static DNS_ERROR read_all(int fd, uint8 *data, size_t len)
{
size_t total = 0;
- fd_set rfds;
- struct timeval tv;
while (total < len) {
+ struct pollfd pfd;
ssize_t ret;
int fd_ready;
-
- FD_ZERO( &rfds );
- FD_SET( fd, &rfds );
-
- /* 10 second timeout */
- tv.tv_sec = 10;
- tv.tv_usec = 0;
-
- fd_ready = select( fd+1, &rfds, NULL, NULL, &tv );
+
+ ZERO_STRUCT(pfd);
+ pfd.fd = fd;
+ pfd.events = POLLIN|POLLHUP;
+
+ fd_ready = poll(&pfd, 1, 10000);
if ( fd_ready == 0 ) {
/* read timeout */
return ERROR_DNS_SOCKET_ERROR;
diff --git a/lib/replace/poll.c b/lib/replace/poll.c
new file mode 100644
index 0000000..e41548d
--- /dev/null
+++ b/lib/replace/poll.c
@@ -0,0 +1,133 @@
+/*
+ Unix SMB/CIFS implementation.
+ poll.c - poll wrapper
+
+ This file is based on code from libssh (LGPLv2.1+ at the time it
+ was downloaded), thus the following copyrights:
+
+ Copyright (c) 2009-2010 by Andreas Schneider <mail at cynapses.org>
+ Copyright (c) 2003-2009 by Aris Adamantiadis
+ Copyright (c) 2009 Aleksandar Kanchev
+ Copyright (C) Volker Lendecke 2011
+
+ ** NOTE! The following LGPL license applies to the replace
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "system/select.h"
+
+
+int rep_poll(struct pollfd *fds, nfds_t nfds, int timeout)
+{
+ fd_set rfds, wfds, efds;
+ struct timeval tv, *ptv;
+ int max_fd;
+ int rc;
+ nfds_t i;
+
+ if (fds == NULL) {
+ errno = EFAULT;
+ return -1;
+ }
+
+ FD_ZERO(&rfds);
+ FD_ZERO(&wfds);
+ FD_ZERO(&efds);
+
+ rc = 0;
+ max_fd = 0;
+
+ /* compute fd_sets and find largest descriptor */
+ for (i = 0; i < nfds; i++) {
+ if ((fds[i].fd < 0) || (fds[i].fd >= FD_SETSIZE)) {
+ fds[i].revents = POLLNVAL;
+ continue;
+ }
+
+ if (fds[i].events & (POLLIN | POLLRDNORM)) {
+ FD_SET(fds[i].fd, &rfds);
+ }
+ if (fds[i].events & (POLLOUT | POLLWRNORM | POLLWRBAND)) {
+ FD_SET(fds[i].fd, &wfds);
+ }
+ if (fds[i].events & (POLLPRI | POLLRDBAND)) {
+ FD_SET(fds[i].fd, &efds);
+ }
+ if (fds[i].fd > max_fd &&
+ (fds[i].events & (POLLIN | POLLOUT | POLLPRI |
+ POLLRDNORM | POLLRDBAND |
+ POLLWRNORM | POLLWRBAND))) {
+ max_fd = fds[i].fd;
+ }
+ }
+
+ if (timeout < 0) {
+ ptv = NULL;
+ } else {
+ ptv = &tv;
+ if (timeout == 0) {
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ } else {
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ }
+ }
+
+ rc = select(max_fd + 1, &rfds, &wfds, &efds, ptv);
+ if (rc < 0) {
+ return -1;
+ }
+
+ for (rc = 0, i = 0; i < nfds; i++) {
+ if ((fds[i].fd < 0) || (fds[i].fd >= FD_SETSIZE)) {
+ continue;
+ }
+
+ fds[i].revents = 0;
+
+ if (FD_ISSET(fds[i].fd, &rfds)) {
+ int err = errno;
+ int available = 0;
+ int ret;
+
+ /* support for POLLHUP */
+ ret = ioctl(fds[i].fd, FIONREAD, &available);
+ if ((ret == -1) || (available == 0)) {
+ fds[i].revents |= POLLHUP;
+ } else {
+ fds[i].revents |= fds[i].events
+ & (POLLIN | POLLRDNORM);
+ }
+
+ errno = err;
+ }
+ if (FD_ISSET(fds[i].fd, &wfds)) {
+ fds[i].revents |= fds[i].events
+ & (POLLOUT | POLLWRNORM | POLLWRBAND);
+ }
+ if (FD_ISSET(fds[i].fd, &efds)) {
+ fds[i].revents |= fds[i].events
+ & (POLLPRI | POLLRDBAND);
+ }
+ if (fds[i].revents & ~POLLHUP) {
+ rc++;
+ }
+ }
+ return rc;
+}
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index 60aa3d4..c081f23 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -797,4 +797,9 @@ int fdatasync(int );
#endif
#endif
+#ifndef HAVE_POLL
+#define poll rep_poll
+/* prototype is in "system/network.h" */
+#endif
+
#endif /* _LIBREPLACE_REPLACE_H */
diff --git a/lib/replace/system/config.m4 b/lib/replace/system/config.m4
index 04364bc..b7cdf14 100644
--- a/lib/replace/system/config.m4
+++ b/lib/replace/system/config.m4
@@ -6,6 +6,10 @@ AC_CHECK_HEADERS(sys/acl.h acl/libacl.h sys/file.h)
# select
AC_CHECK_HEADERS(sys/select.h)
+# poll
+AC_CHECK_HEADERS(poll.h)
+AC_CHECK_FUNCS(poll,[],[LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/poll.o"])
+
# time
AC_CHECK_HEADERS(sys/time.h utime.h)
AC_HEADER_TIME
diff --git a/lib/replace/system/select.h b/lib/replace/system/select.h
index da18de0..11c5390 100644
--- a/lib/replace/system/select.h
+++ b/lib/replace/system/select.h
@@ -38,4 +38,40 @@
#define SELECT_CAST
#endif
+#ifdef HAVE_POLL
+
+#include <poll.h>
+
+#else
+
+/* Type used for the number of file descriptors. */
+typedef unsigned long int nfds_t;
+
+/* Data structure describing a polling request. */
+struct pollfd
+{
+ int fd; /* File descriptor to poll. */
+ short int events; /* Types of events poller cares about. */
+ short int revents; /* Types of events that actually occurred. */
+};
+
+/* Event types that can be polled for. These bits may be set in `events'
+ to indicate the interesting event types; they will appear in `revents'
+ to indicate the status of the file descriptor. */
+#define POLLIN 0x001 /* There is data to read. */
+#define POLLPRI 0x002 /* There is urgent data to read. */
+#define POLLOUT 0x004 /* Writing now will not block. */
+#define POLLRDNORM 0x040 /* Normal data may be read. */
+#define POLLRDBAND 0x080 /* Priority data may be read. */
+#define POLLWRNORM 0x100 /* Writing now will not block. */
+#define POLLWRBAND 0x200 /* Priority data may be written. */
+#define POLLERR 0x008 /* Error condition. */
+#define POLLHUP 0x010 /* Hung up. */
+#define POLLNVAL 0x020 /* Invalid polling request. */
+
+/* define is in "replace.h" */
+int rep_poll(struct pollfd *fds, nfds_t nfds, int timeout);
+
+#endif
+
#endif
diff --git a/lib/replace/wscript b/lib/replace/wscript
index ad291a5..f1fe6ea 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -243,6 +243,9 @@ def configure(conf):
if conf.CONFIG_SET('HAVE_EPOLL_CREATE') and conf.CONFIG_SET('HAVE_SYS_EPOLL_H'):
conf.DEFINE('HAVE_EPOLL', 1)
+ conf.CHECK_HEADERS('poll.h')
+ conf.CHECK_FUNCS('poll')
+
if not conf.CHECK_CODE('''#define LIBREPLACE_CONFIGURE_TEST_STRPTIME
#include "test/strptime.c"''',
define='HAVE_STRPTIME',
@@ -406,6 +409,7 @@ def build(bld):
if bld.CONFIG_SET('REPLACE_GETPASS'): REPLACE_SOURCE += ' getpass.c'
if not bld.CONFIG_SET('HAVE_CRYPT'): REPLACE_SOURCE += ' crypt.c'
if not bld.CONFIG_SET('HAVE_DLOPEN'): REPLACE_SOURCE += ' dlfcn.c'
+ if not bld.CONFIG_SET('HAVE_POLL'): REPLACE_SOURCE += ' poll.c'
if not bld.CONFIG_SET('HAVE_SOCKETPAIR'): REPLACE_SOURCE += ' socketpair.c'
if not bld.CONFIG_SET('HAVE_CONNECT'): REPLACE_SOURCE += ' socket.c'
diff --git a/lib/tevent/libtevent.m4 b/lib/tevent/libtevent.m4
index 4162ba3..5c5969b 100644
--- a/lib/tevent/libtevent.m4
+++ b/lib/tevent/libtevent.m4
@@ -30,6 +30,7 @@ TEVENT_OBJ="tevent.o tevent_debug.o tevent_util.o"
TEVENT_OBJ="$TEVENT_OBJ tevent_fd.o tevent_timed.o tevent_immediate.o tevent_signal.o"
TEVENT_OBJ="$TEVENT_OBJ tevent_req.o tevent_wakeup.o tevent_queue.o"
TEVENT_OBJ="$TEVENT_OBJ tevent_standard.o tevent_select.o"
+TEVENT_OBJ="$TEVENT_OBJ tevent_poll.o"
AC_CHECK_HEADERS(sys/epoll.h)
AC_CHECK_FUNCS(epoll_create)
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c
index 4849bc1..87e5aff 100644
--- a/lib/tevent/tevent.c
+++ b/lib/tevent/tevent.c
@@ -113,6 +113,7 @@ void tevent_set_default_backend(const char *backend)
static void tevent_backend_init(void)
{
tevent_select_init();
+ tevent_poll_init();
tevent_standard_init();
#ifdef HAVE_EPOLL
tevent_epoll_init();
diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h
index 7f5fd64..3d71bfd 100644
--- a/lib/tevent/tevent_internal.h
+++ b/lib/tevent/tevent_internal.h
@@ -303,6 +303,7 @@ void tevent_cleanup_pending_signal_handlers(struct tevent_signal *se);
bool tevent_standard_init(void);
bool tevent_select_init(void);
+bool tevent_poll_init(void);
#ifdef HAVE_EPOLL
bool tevent_epoll_init(void);
#endif
diff --git a/lib/tevent/tevent_poll.c b/lib/tevent/tevent_poll.c
new file mode 100644
index 0000000..c133194
--- /dev/null
+++ b/lib/tevent/tevent_poll.c
@@ -0,0 +1,306 @@
+/*
+ Unix SMB/CIFS implementation.
+ main select loop and event handling
+ Copyright (C) Andrew Tridgell 2003-2005
+ Copyright (C) Stefan Metzmacher 2005-2009
+
+ ** NOTE! The following LGPL license applies to the tevent
+ ** library. This does NOT imply that all of Samba is released
+ ** under the LGPL
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "system/filesys.h"
+#include "system/select.h"
+#include "tevent.h"
+#include "tevent_util.h"
+#include "tevent_internal.h"
+
+struct poll_event_context {
+ /*
+ * These two arrays are maintained together.
+ */
+ struct pollfd *fds;
+ struct tevent_fd **fd_events;
+ int num_fds;
+
+ /* information for exiting from the event loop */
+ int exit_code;
+};
+
+/*
+ create a select_event_context structure.
+*/
+static int poll_event_context_init(struct tevent_context *ev)
+{
+ struct poll_event_context *poll_ev;
+
+ poll_ev = talloc_zero(ev, struct poll_event_context);
+ if (poll_ev == NULL) {
+ return -1;
+ }
+ ev->additional_data = poll_ev;
+ return 0;
+}
+
+/*
+ destroy an fd_event
+*/
+static int poll_event_fd_destructor(struct tevent_fd *fde)
+{
+ struct tevent_context *ev = fde->event_ctx;
+ struct poll_event_context *poll_ev = NULL;
+ struct tevent_fd *moved_fde;
+ int del_idx;
+
+ if (ev == NULL) {
+ goto done;
+ }
+
+ poll_ev = talloc_get_type_abort(
+ ev->additional_data, struct poll_event_context);
+
+ /*
+ * Assume a void * can carry enough bits to hold num_fds.
+ */
+ del_idx = (int)(fde->additional_data);
+
+ moved_fde = poll_ev->fd_events[poll_ev->num_fds-1];
+ poll_ev->fd_events[del_idx] = moved_fde;
+ poll_ev->fds[del_idx] = poll_ev->fds[poll_ev->num_fds-1];
+ moved_fde->additional_data = (void *)del_idx;
+
+ poll_ev->num_fds -= 1;
+done:
+ return tevent_common_fd_destructor(fde);
+}
+
+/*
+ add a fd based event
+ return NULL on failure (memory allocation error)
+*/
+static struct tevent_fd *poll_event_add_fd(struct tevent_context *ev,
+ TALLOC_CTX *mem_ctx,
+ int fd, uint16_t flags,
+ tevent_fd_handler_t handler,
+ void *private_data,
+ const char *handler_name,
+ const char *location)
+{
+ struct poll_event_context *poll_ev = talloc_get_type_abort(
+ ev->additional_data, struct poll_event_context);
+ struct pollfd *pfd;
+ struct tevent_fd *fde;
+
+ fde = tevent_common_add_fd(ev, mem_ctx, fd, flags,
+ handler, private_data,
+ handler_name, location);
+ if (fde == NULL) {
+ return NULL;
+ }
+
+ /* we allocate 16 slots to avoid a lot of reallocations */
+ if (talloc_array_length(poll_ev->fds) == poll_ev->num_fds) {
+ struct pollfd *tmp_fds;
+ struct tevent_fd **tmp_fd_events;
+ tmp_fds = talloc_realloc(
+ poll_ev, poll_ev->fds, struct pollfd,
+ poll_ev->num_fds + 16);
+ if (tmp_fds == NULL) {
+ TALLOC_FREE(fde);
+ return NULL;
+ }
+ poll_ev->fds = tmp_fds;
+
+ tmp_fd_events = talloc_realloc(
+ poll_ev, poll_ev->fd_events, struct tevent_fd *,
+ poll_ev->num_fds + 16);
+ if (tmp_fd_events == NULL) {
+ TALLOC_FREE(fde);
+ return NULL;
+ }
+ poll_ev->fd_events = tmp_fd_events;
+ }
+
+ pfd = &poll_ev->fds[poll_ev->num_fds];
+
+ pfd->fd = fd;
+
+ pfd->events = 0;
+ pfd->revents = 0;
+
+ if (flags & TEVENT_FD_READ) {
+ pfd->events |= (POLLIN|POLLHUP);
+ }
+ if (flags & TEVENT_FD_WRITE) {
+ pfd->events |= (POLLOUT);
+ }
+
+ /*
+ * Assume a void * can carry enough bits to hold num_fds.
+ */
+ fde->additional_data = (void *)poll_ev->num_fds;
+ poll_ev->fd_events[poll_ev->num_fds] = fde;
+
+ poll_ev->num_fds += 1;
+
+ talloc_set_destructor(fde, poll_event_fd_destructor);
--
Samba Shared Repository
More information about the samba-cvs
mailing list