module Procord_protocol:sig..end
type error =
| |
E_task_not_supported |
| |
E_unexpected_message |
| |
E_ill_formed_message |
| |
E_message_too_long |
| |
E_disconnected |
| |
E_invalid_print_destination |
exception Error of error
val error : error -> 'aval error_message : error -> stringtypecustom_destination =char
Custom destinations are identified by a single character which should
not be 'O' nor 'E'. You can typically use '0', '1', ..., '9'.
type print_destination =
| |
D_stdout |
| |
D_stderr |
| |
D_custom of |
Possible values are:
D_stdout: print to Format.std_formatter;D_stderr: print to Format.err_formatter;D_custom: print to a custom destination.type message =
| |
M_none |
|||
| |
M_value of |
(* | Serialized input or output. | *) |
| |
M_task_name of |
|||
| |
M_exception of |
(* | Serialized exception. | *) |
| |
M_unknown_exception of |
(* | Exception as a string using Printexc. | *) |
| |
M_error of |
|||
| |
M_print of |
(* | Destination, message to print. | *) |
| |
M_flush of |
val set_max_message_size : int -> unit
If you know that your serialized values, exceptions and task names
are never longer than n bytes, consider setting the maximum message
size to n. Otherwise someone can send a ridiculous size, then the
same ridiculous amount of data, and your process will buffer it all,
possibly running out of memory.
By default the maximum size is max_int.
val send : 'a Procord_connection.t -> message -> unitval send_value : 'a Procord_connection.t -> string -> unitval send_task_name : 'a Procord_connection.t -> string -> unitval send_exception : 'a Procord_connection.t -> string -> unitval send_unknown_exception : 'a Procord_connection.t -> string -> unitval send_error : 'a Procord_connection.t -> error -> unitval send_print : 'a Procord_connection.t ->
print_destination -> string -> unitFormat.fprintf.
The worker can use this to make the main program call
Format.fprintf. It is unspecified whether the main program can
send messages like this to the worker.
val send_flush : 'a Procord_connection.t -> print_destination -> unit
The worker can use this to make the main program call
Format.pp_print_flush. It is unspecified whether the main
program can send messages like this to the worker.
val receive : 'a Procord_connection.t -> message
May raise Error E_ill_formed_message.
val blocking_receive : 'a Procord_connection.t -> message
May raise Error.
val blocking_receive_task_name : 'a Procord_connection.t -> string
May raise Error.
val blocking_receive_value : 'a Procord_connection.t -> string
May raise Error.
val register_destination : custom_destination -> Format.formatter -> unitProcord_worker.make_redirected_formatter.
Multiples destinations are not supported: only the last formatter receives the message.
This can be called before Procord_worker.run, although it only
affects the main program. From the worker, you should use
Procord_worker.redirect_formatter or
Procord_worker.formatter_of_destination.
val formatter_of_destination : print_destination -> Format.formatter option
Return None if the destination custom and unregistered.
message.)
Nothing else can be sent, and M_none cannot really be sent either.
Each message is of the form:
SIZE KIND BODY
The SIZE is a sequence of ASCII digits ('0' to '9').
The KIND is a single character which is not a digit.
The BODY is a string of SIZE bytes.
Each message has a specific KIND and a specific way to handle BODY:
M_value:
KIND 'V';
BODY is to be deserialized using the user function read_input
(for the worker) or read_output (for the main program).M_task_name:
KIND 'T';
BODY is the task name.M_exception:
KIND 'X';
BODY is to be deserialized using the user function read_exception.M_unknown_exception:
KIND 'U';
BODY is the exception as a string using Printexc.M_error:
KIND 'E';
BODY is one of those (quotes not included):
"0" - E_task_not_supported;
"1" - E_unexpected_message;
"2" - E_ill_formed_message;
"3" - E_message_too_long;
"4" - E_disconnected;
"5" - E_invalid_print_destination.M_print:
KIND 'P';
BODY starts with the destination, which is one of those
(quotes not included):
"O" - `stdout;
"E" - `stderr;
any other character - custom destination.
BODY continues with the message to be printed.M_flush:
KIND 'F';
BODY is one of those (quotes not included):
"O" - `stdout;
"E" - `stderr;
any other character - custom destination.
"1E2" has SIZE 1, KIND 'E' (M_error),
and BODY "2" (E_disconnected)."5Thelloworld" has SIZE 5, KIND 'T' (M_task_name),
and BODY "hello".
Remainder "world" is not part of the message."8POmessage" has SIZE 8, KIND 'P' (M_print),
and BODY "Omessage".
It is a request to print "message" on Format.std_formatter.