Rpc_client) there is usually a sub module
M.Debugproviding functions controlling the debug messages. These functions send the messages to this
Debugmodule, and from here they are forwarded to
Netlog.log(with a level of
In this module everything is by default initialized to enable
debug messages (i.e.,
current_dlogger is set to
and this function sends the messages to
current_logger where they are
channel_logger stderr `Debug). However, the debugged
modules also need to be enabled individually. One can do this
by setting the variable
true, or by calling
enable_all (see below).
Although this debug interface is mainly intended for Ocamlnet
itself, it is not restricted to this. In order to use it for
a user module, one has to register the boolean variable that
controls whether debug messages are enabled (see
below). This should be done at module initialization time, and
before any thread is spawned.
val fwd_dlogger :
val null_dlogger :
val current_dlogger :
fwd_dloggerat program startup. Set this variable to
null_loggerto completely turn off debug logging of Ocamlnet.
enable_module "Rpc_client"). No exception is raised when the module name is invalid! Because of this, it is usually safer to change the variable
Rpc_client.Debug.enable := true).
enablevariable of the named module
let dlog = mk_dlog "M" enable: The conditional debug function
let dlogr = mk_dlog "M" enable: The conditional debug function
Netlog.Debugalso has a little hash table that maps file descriptors to an info record. This allows it to track file descriptors more easily, and to find file descriptor leaks, and "double close" bugs. All long-living descriptors managed by Ocamlnet should go into this table.
val new_serial :
unit -> serial
val track_fd :
owner:string -> descr:string -> Unix.file_descr -> unit
track_fd ~owner ~descr fd: Enters the descriptor
fdinto the descriptor table. The
ownerstring should be set to the module name. In
descrone can give additional information, e.g. about the purpose, and details like the file name.
It is not an error if there is also an entry for the descriptor
fd. However, a warning is emitted (using the debug logger).
true, this warning can be suppressed.
The old entry is overwritten by the new one.
anchor can be an arbitrary boxed value. When the garbage
collector calls the finaliser for
anchor the descriptor is
marked as dead, and will be tagged in the
fd_table as such.
sn to a new serial number, the knowledge of this
number is required to update the descriptor entry later,
and to release the descriptor. If the entry is tried to be
updated or released with the wrong serial number, a warning
is emitted (to the debug logger).
val release_fd :
?sn:serial -> ?force:bool -> Unix.file_descr -> unit
It is not an error if the descriptor does not exist in the table. However, a warning is emitted (using the debug logger).
release_fd must be invoked before the descriptor is actually
force: If set, all warnings are suppressed
owner is set to true, the string also includes the owner.
descr is set to true, the string also includes the description.
The full version of this string looks like
"76(Http_client - 184.108.40.206:80)". An untracked descriptor
looks like "76(?)".
List.iter print_endline (fd_table()).