tracefile: string option; (* old xenstored compatibility *)
restart: bool;
disable_socket: bool;
+ use_select: bool;
}
let do_argv =
and reraise_top_level = ref false
and config_file = ref ""
and restart = ref false
- and disable_socket = ref false in
+ and disable_socket = ref false
+ and use_select = ref false in
let speclist =
[ ("--no-domain-init", Arg.Unit (fun () -> domain_init := false),
("-T", Arg.Set_string tracefile, ""); (* for compatibility *)
("--restart", Arg.Set restart, "Read database on starting");
("--disable-socket", Arg.Unit (fun () -> disable_socket := true), "Disable socket");
+ ("--use-select", Arg.Unit (fun () -> use_select := true), "Use select instead of poll"); (* for backward compatibility and testing *)
] in
- let usage_msg = "usage : xenstored [--config-file <filename>] [--no-domain-init] [--help] [--no-fork] [--reraise-top-level] [--restart] [--disable-socket]" in
+ let usage_msg = "usage : xenstored [--config-file <filename>] [--no-domain-init] [--help] [--no-fork] [--reraise-top-level] [--restart] [--disable-socket] [--use-select]" in
Arg.parse speclist (fun s -> ()) usage_msg;
{
domain_init = !domain_init;
tracefile = if !tracefile <> "" then Some !tracefile else None;
restart = !restart;
disable_socket = !disable_socket;
+ use_select = !use_select;
}
let init_event () = {read = false; write = false; except = false}
-let select in_fds out_fds exc_fds timeout =
+let poll_select in_fds out_fds exc_fds timeout =
let h = Hashtbl.create 57 in
let add_event event_set fd =
let e =
(if event.write then fd :: w else w),
(if event.except then fd :: x else x))
a r
+
+(* If the use_poll function is not called at all, we default to the original Unix.select behavior *)
+let select_fun = ref Unix.select
+
+let use_poll yes =
+ let sel_fun, max_fd =
+ if yes then poll_select, get_sys_fs_nr_open ()
+ else Unix.select, 1024 in
+ select_fun := sel_fun;
+ set_fd_limit max_fd
+
+let select in_fds out_fds exc_fds timeout =
+ (!select_fun) in_fds out_fds exc_fds timeout
(** Same interface and semantics as [Unix.select] but with an extra alternative
- implementation based on poll. *)
+ implementation based on poll. Switching implementations is done by calling
+ the [use_poll] function. *)
val select:
Unix.file_descr list -> Unix.file_descr list -> Unix.file_descr list -> float
-> Unix.file_descr list * Unix.file_descr list * Unix.file_descr list
+
+(** [use_poll true] will use poll based select with max fds number limitation
+ eliminated; [use_poll false] will use standard [Unix.select] with max fd
+ number set to 1024; not calling this function at all equals to use the
+ standard [Unix.select] with max fd number setting untouched. *)
+val use_poll: bool -> unit
);
);
+ Select.use_poll (not cf.use_select);
+
Sys.set_signal Sys.sighup (Sys.Signal_handle sighup_handler);
Sys.set_signal Sys.sigterm (Sys.Signal_handle (fun i -> quit := true));
Sys.set_signal Sys.sigusr1 (Sys.Signal_handle (fun i -> sigusr1_handler store));