summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-01-17 12:59:14 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:17:13 -0500
commitbf219447a35d86913c1a643b66d993986a651360 (patch)
treeabd6650e6694233de6d6f8e197a03b513ecaec56 /source3/smbd
parent60c1a8e5a8f905a5ae703dac05ed2f440875ad5d (diff)
downloadsamba-bf219447a35d86913c1a643b66d993986a651360.tar.gz
samba-bf219447a35d86913c1a643b66d993986a651360.tar.bz2
samba-bf219447a35d86913c1a643b66d993986a651360.zip
r20846: Before this gets out of control...
This add a struct event_context and infrastructure for fd events to smbd. This is step zero to import lib/events. Jeremy, I rely on you to watch the change in receive_message_or_smb() closely. For the normal code path this should be the only relevant change. The rest is either not yet used or is cosmetic. Volker (This used to be commit cd07f93a8aecb24c056e33b1ad3447a41959810f)
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/oplock.c5
-rw-r--r--source3/smbd/process.c65
-rw-r--r--source3/smbd/server.c10
3 files changed, 51 insertions, 29 deletions
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index 427fb7f245..1f73ea837d 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -342,7 +342,8 @@ static files_struct *initial_break_processing(SMB_DEV_T dev, SMB_INO_T inode, un
return fsp;
}
-static void oplock_timeout_handler(struct timed_event *te,
+static void oplock_timeout_handler(struct event_context *ctx,
+ struct timed_event *te,
const struct timeval *now,
void *private_data)
{
@@ -372,7 +373,7 @@ static void add_oplock_timeout_handler(files_struct *fsp)
}
fsp->oplock_timeout =
- add_timed_event(NULL,
+ event_add_timed(smbd_event_context(), NULL,
timeval_current_ofs(OPLOCK_BREAK_TIMEOUT, 0),
"oplock_timeout_handler",
oplock_timeout_handler, fsp);
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 929471a48c..2a52da12b3 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -225,7 +225,8 @@ struct idle_event {
void *private_data;
};
-static void idle_event_handler(struct timed_event *te,
+static void idle_event_handler(struct event_context *ctx,
+ struct timed_event *te,
const struct timeval *now,
void *private_data)
{
@@ -240,7 +241,8 @@ static void idle_event_handler(struct timed_event *te,
return;
}
- event->te = add_timed_event(event, timeval_sum(now, &event->interval),
+ event->te = event_add_timed(smbd_event_context(), event,
+ timeval_sum(now, &event->interval),
"idle_event_handler",
idle_event_handler, event);
@@ -267,11 +269,12 @@ struct idle_event *add_idle_event(TALLOC_CTX *mem_ctx,
result->handler = handler;
result->private_data = private_data;
- result->te = add_timed_event(result, timeval_sum(&now, &interval),
+ result->te = event_add_timed(smbd_event_context(), result,
+ timeval_sum(&now, &interval),
"idle_event_handler",
idle_event_handler, result);
if (result->te == NULL) {
- DEBUG(0, ("add_timed_event failed\n"));
+ DEBUG(0, ("event_add_timed failed\n"));
TALLOC_FREE(result);
return NULL;
}
@@ -350,7 +353,7 @@ The timeout is in milliseconds
static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
{
- fd_set fds;
+ fd_set r_fds, w_fds;
int selrtn;
struct timeval to;
int maxfd = 0;
@@ -414,10 +417,11 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
}
/*
- * Setup the select read fd set.
+ * Setup the select fd sets.
*/
- FD_ZERO(&fds);
+ FD_ZERO(&r_fds);
+ FD_ZERO(&w_fds);
/*
* Ensure we process oplock break messages by preference.
@@ -428,9 +432,9 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
* This is hideously complex - *MUST* be simplified for 3.0 ! JRA.
*/
- if (oplock_message_waiting(&fds)) {
+ if (oplock_message_waiting(&r_fds)) {
DEBUG(10,("receive_message_or_smb: oplock_message is waiting.\n"));
- async_processing(&fds);
+ async_processing(&r_fds);
/*
* After async processing we must go and do the select again, as
* the state of the flag in fds for the server file descriptor is
@@ -445,15 +449,17 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
*/
{
- struct timeval tmp;
- struct timeval *tp = get_timed_events_timeout(&tmp);
-
- if (tp) {
- to = timeval_min(&to, tp);
- if (timeval_is_zero(&to)) {
- /* Process a timed event now... */
- run_events();
- }
+ struct timeval now;
+ GetTimeOfDay(&now);
+
+ event_add_to_select_args(smbd_event_context(), &now,
+ &r_fds, &w_fds, &to, &maxfd);
+ }
+
+ if (timeval_is_zero(&to)) {
+ /* Process a timed event now... */
+ if (run_events(smbd_event_context(), 0, NULL, NULL)) {
+ goto again;
}
}
@@ -461,23 +467,27 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
int sav;
START_PROFILE(smbd_idle);
- maxfd = select_on_fd(smbd_server_fd(), maxfd, &fds);
- maxfd = select_on_fd(change_notify_fd(), maxfd, &fds);
- maxfd = select_on_fd(oplock_notify_fd(), maxfd, &fds);
+ maxfd = select_on_fd(smbd_server_fd(), maxfd, &r_fds);
+ maxfd = select_on_fd(change_notify_fd(), maxfd, &r_fds);
+ maxfd = select_on_fd(oplock_notify_fd(), maxfd, &r_fds);
- selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&to);
+ selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&to);
sav = errno;
END_PROFILE(smbd_idle);
errno = sav;
}
+ if (run_events(smbd_event_context(), selrtn, &r_fds, &w_fds)) {
+ goto again;
+ }
+
/* if we get EINTR then maybe we have received an oplock
signal - treat this as select returning 1. This is ugly, but
is the best we can do until the oplock code knows more about
signals */
if (selrtn == -1 && errno == EINTR) {
- async_processing(&fds);
+ async_processing(&r_fds);
/*
* After async processing we must go and do the select again, as
* the state of the flag in fds for the server file descriptor is
@@ -505,8 +515,8 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
* sending us an oplock break message. JRA.
*/
- if (oplock_message_waiting(&fds)) {
- async_processing(&fds);
+ if (oplock_message_waiting(&r_fds)) {
+ async_processing(&r_fds);
/*
* After async processing we must go and do the select again, as
* the state of the flag in fds for the server file descriptor is
@@ -515,7 +525,8 @@ static BOOL receive_message_or_smb(char *buffer, int buffer_len, int timeout)
goto again;
}
- if ((change_notify_fd() >= 0) && FD_ISSET(change_notify_fd(), &fds)) {
+ if ((change_notify_fd() >= 0) && FD_ISSET(change_notify_fd(),
+ &r_fds)) {
process_pending_change_notify_queue((time_t)0);
@@ -1603,7 +1614,7 @@ void smbd_process(void)
num_smbs = 0; /* Reset smb counter. */
}
- run_events();
+ run_events(smbd_event_context(), 0, NULL, NULL);
#if defined(DEVELOPER)
clobber_region(SAFE_STRING_FUNCTION_NAME, SAFE_STRING_LINE, InBuffer, total_buffer_size);
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 5ee9320fb3..4a242488da 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -61,6 +61,16 @@ static void smbd_set_server_fd(int fd)
client_setfd(fd);
}
+struct event_context *smbd_event_context(void)
+{
+ static struct event_context *ctx;
+
+ if (!ctx && !(ctx = event_context_init(NULL))) {
+ smb_panic("Could not init smbd event context\n");
+ }
+ return ctx;
+}
+
/*******************************************************************
What to do when smb.conf is updated.
********************************************************************/