fde->flags &= ~EVENT_FD_READ;
}
-void event_add_to_select_args(struct event_context *event_ctx,
+/*
+ * Return if there's something in the queue
+ */
+
+BOOL event_add_to_select_args(struct event_context *event_ctx,
const struct timeval *now,
fd_set *read_fds, fd_set *write_fds,
struct timeval *timeout, int *maxfd)
{
struct fd_event *fde;
struct timeval diff;
+ BOOL ret = False;
for (fde = event_ctx->fd_events; fde; fde = fde->next) {
if (fde->flags & EVENT_FD_READ) {
FD_SET(fde->fd, read_fds);
+ ret = True;
}
if (fde->flags & EVENT_FD_WRITE) {
FD_SET(fde->fd, write_fds);
+ ret = True;
}
if ((fde->flags & (EVENT_FD_READ|EVENT_FD_WRITE))
}
if (event_ctx->timed_events == NULL) {
- return;
+ return ret;
}
diff = timeval_until(now, &event_ctx->timed_events->when);
*timeout = timeval_min(timeout, &diff);
+
+ return True;
}
BOOL run_events(struct event_context *event_ctx,
return to_ret;
}
+int event_loop_once(struct event_context *ev)
+{
+ struct timeval now, to;
+ fd_set r_fds, w_fds;
+ int maxfd = 0;
+ int ret;
+
+ FD_ZERO(&r_fds);
+ FD_ZERO(&w_fds);
+
+ to.tv_sec = 9999; /* Max timeout */
+ to.tv_usec = 0;
+
+ GetTimeOfDay(&now);
+
+ if (!event_add_to_select_args(ev, &now, &r_fds, &w_fds, &to, &maxfd)) {
+ return -1;
+ }
+
+ if (timeval_is_zero(&to)) {
+ run_events(ev, 0, NULL, NULL);
+ return 0;
+ }
+
+ ret = sys_select(maxfd, &r_fds, &w_fds, NULL, &to);
+
+ if (ret == -1 && errno != EINTR) {
+ return -1;
+ }
+
+ run_events(ev, ret, &r_fds, &w_fds);
+ return 0;
+}
+
struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
{
return TALLOC_ZERO_P(NULL, struct event_context);
/* Wait for one or more reply messages */
-static void wait_replies(BOOL multiple_replies)
+static void wait_replies(struct messaging_context *msg_ctx,
+ BOOL multiple_replies)
{
time_t start_time = time(NULL);
do {
message_dispatch();
+ event_loop_once(messaging_event_context(msg_ctx));
if (num_replies > 0 && !multiple_replies)
break;
sleep(1);
/* Message handler callback that displays the PID and a string on stdout */
-static void print_pid_string_cb(int msg_type, struct server_id pid, void *buf,
- size_t len, void *private_data)
+static void print_pid_string_cb(struct messaging_context *msg,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id pid,
+ DATA_BLOB *data)
{
printf("PID %u: %.*s", (unsigned int)procid_to_pid(&pid),
- (int)len, (const char *)buf);
+ (int)data->length, (const char *)data->data);
num_replies++;
}
/* Message handler callback that displays a string on stdout */
-static void print_string_cb(int msg_type, struct server_id pid,
- void *buf, size_t len, void *private_data)
+static void print_string_cb(struct messaging_context *msg,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id pid,
+ DATA_BLOB *data)
{
- printf("%.*s", (int)len, (const char *)buf);
+ printf("%.*s", (int)data->length, (const char *)data->data);
num_replies++;
}
/* Ping a samba daemon process */
-static void pong_cb(int msg_type, struct server_id pid, void *buf,
- size_t len, void *private_data)
+static void pong_cb(struct messaging_context *msg,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id pid,
+ DATA_BLOB *data)
{
char *src_string = procid_str(NULL, &pid);
printf("PONG from pid %s\n", src_string);
if (!send_message(msg_ctx, pid, MSG_PING, NULL, 0, False))
return False;
- message_register(MSG_PONG, pong_cb, NULL);
+ messaging_register(msg_ctx, NULL, MSG_PONG, pong_cb);
- wait_replies(procid_to_pid(&pid) == 0);
+ wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- message_deregister(MSG_PONG);
+ messaging_deregister(msg_ctx, MSG_PONG, NULL);
return num_replies;
}
messaging_register(msg_ctx, NULL, MSG_REQ_PROFILELEVEL,
profilelevel_rqst);
- wait_replies(procid_to_pid(&pid) == 0);
+ wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- message_deregister(MSG_PROFILE);
+ messaging_deregister(msg_ctx, MSG_PROFILE, NULL);
return num_replies;
}
if (!send_message(msg_ctx, pid, MSG_REQ_DEBUGLEVEL, NULL, 0, False))
return False;
- message_register(MSG_DEBUGLEVEL, print_pid_string_cb, NULL);
+ messaging_register(msg_ctx, NULL, MSG_DEBUGLEVEL, print_pid_string_cb);
- wait_replies(procid_to_pid(&pid) == 0);
+ wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- message_deregister(MSG_DEBUGLEVEL);
+ messaging_deregister(msg_ctx, MSG_DEBUGLEVEL, NULL);
return num_replies;
}
return False;
}
- message_register(MSG_POOL_USAGE, print_string_cb, NULL);
+ messaging_register(msg_ctx, NULL, MSG_POOL_USAGE, print_string_cb);
/* Send a message and register our interest in a reply */
if (!send_message(msg_ctx, pid, MSG_REQ_POOL_USAGE, NULL, 0, False))
return False;
- wait_replies(procid_to_pid(&pid) == 0);
+ wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- message_deregister(MSG_POOL_USAGE);
+ messaging_deregister(msg_ctx, MSG_POOL_USAGE, NULL);
return num_replies;
}
return False;
}
- message_register(MSG_WINBIND_ONLINESTATUS, print_pid_string_cb, NULL);
+ messaging_register(msg_ctx, NULL, MSG_WINBIND_ONLINESTATUS,
+ print_pid_string_cb);
if (!send_message(msg_ctx, pid, MSG_WINBIND_ONLINESTATUS, &myid,
sizeof(myid), False))
return False;
- wait_replies(procid_to_pid(&pid) == 0);
+ wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
/* No replies were received within the timeout period */
if (num_replies == 0)
printf("No replies received\n");
- message_deregister(MSG_WINBIND_ONLINESTATUS);
+ messaging_deregister(msg_ctx, MSG_WINBIND_ONLINESTATUS, NULL);
return num_replies;
}