module Rpc_client:RPC clientssig..end
You can push several procedure calls on the event queue at once. The queue serves then as a pipeline; the calls are sent to the server as long as the server accepts new calls. Replies are received in any order, and the return values of the remote procedures are delivered using a callback function.
You can set timeouts and force automatic retransmission if you want this; these features are enabled by default if the underlying transport mechanism is UDP. Timeouts and other exceptions are delivered to the callback functions, too.
The whole mechanism is designed to allow maximum parallelism without needing to use the multi-threading features of O'Caml. Especially, the following parallelisms can be done:
exception Message_lost
exception Message_timeout
exception Communication_error of exn
exception Client_is_down
exception Keep_call
type t
type connector =
| |
Inet of |
(* | Hostname or IP address, port | *) |
| |
Internet of |
(* | The address plus port | *) |
| |
Unix of |
(* | Path to unix dom sock | *) |
| |
Descriptor of |
(* | Pass an already open socket descriptor. The descriptor will not be closed when the client is done! | *) |
| |
Dynamic_descriptor of |
(* | The function is called to get the socket descriptor.
Unlike Descriptor, the descriptor will be closed when the
client is done | *) |
| |
Portmapped of |
(* | The portmapper on this host is queried to get address information | *) |
val shutdown_connector : t -> Rpc_transport.rpc_multiplex_controller -> unitDescriptor this is a no-op,
for the other connector types the socket is closed.val create : ?program_number:Rtypes.uint4 ->
?version_number:Rtypes.uint4 ->
?initial_xid:int ->
?shutdown:(t -> Rpc_transport.rpc_multiplex_controller -> unit) ->
Unixqueue.event_system ->
connector -> Rpc.protocol -> Rpc_program.t -> tconnector.
The server is assumed to implement an RPC program as specified by
the Rpc_program.t argument. (You can override the program and version
numbers stored in this argument by the optional parameters
program_number and version_number.)
All communication to the server is handled using the given queue
Unixqueue.event_system.
If the protocol is Tcp, the communication will be handled stream- oriented. In this case, no timeout is detected and no retransmissions are done.
If the protocol is Udp, a datagram-oriented communication style is used. This works only for Internet UDP sockets because these are bidirectional (Unix domain sockets are unidirectional and do not work). For Udp, there is a timeout of 15 seconds and a maximum of 3 retransmissions (i.e. a total of 4 transmission trials).
Unlike create2, servers made with create always use blocking
connect for backwards compatibility.
program_number : Overrides the program number in Rpc_program.tversion_number : Overrides the version number in Rpc_program.tinitial_xid : The initial value for the session identifier.shutdown : This function is called when the client is shut down
to close the client socket. By default, shutdown_connector is
called.class type socket_config =object..end
`Socket (see below).
val default_socket_config : socket_confignon_blocking_connect = trueclass default_socket_config :socket_config
val blocking_socket_config : socket_confignon_blocking_connect = falseclass blocking_socket_config :socket_config
connect configuration as class
typemode2 =[ `Multiplexer_endpoint of Rpc_transport.rpc_multiplex_controller
| `Socket of Rpc.protocol * connector * socket_config
| `Socket_endpoint of Rpc.protocol * Unix.file_descr ]
create2:
`Socket_endpoint(proto,fd): Socket fd is a connected socket
descriptor used for communication. proto determines the
encapsulation; should be Tcp for stream sockets and Udp for
datagram sockets. The descriptor will be closed when the client
terminates.`Multiplexer_endpoint m: m is an RPC multiplex controller.`Socket(proto, conn, config): Creates and connect a client
socket according to conn. proto determines the
encapsulation; should be Tcp for stream sockets and Udp for
datagram sockets. config specifies configuration details.val create2 : ?program_number:Rtypes.uint4 ->
?version_number:Rtypes.uint4 ->
?initial_xid:int ->
?shutdown:(t -> Rpc_transport.rpc_multiplex_controller -> unit) ->
mode2 -> Rpc_program.t -> Unixqueue.event_system -> tcreate and mode2 for explanations.val configure : t -> int -> float -> unitconfigure client retransmissions timeout:
sets the number of retransmissions and the timeout for the next calls.
(These values are defaults; the actual values are stored with each
call.)
Values of retransmissions > 0 are semantically only valid if the
called procedures are idempotent, i.e. invoking them several times
with the same values has the same effect as only one invocation.
Positive values for retransmissions should only be used for Udp-style
communication.
The timeout value determines how long the client waits until the
next retransmission is done, or, if no more retransmissions are
permitted, a Message_timeout exception is delivered to the receiving
callback function. A timeout value of 0.0 means immediate timeout
and is usually senseless. A negative timeout value means 'no timeout'.
Positive timeout values are possible for both Udp and Tcp connections.
Timeout values are measured in seconds.
There is a special application for the timeout value 0.0: If you
don't expect an answer from the server at all ("batch mode"), this
timeout value will cause that the message handler will get
a Message_timeout exception immediately. You should ignore this
timeout for batch mode. The positive effect from the timeout is that
the internal management routines will remove the remote call from
the list of pending calls such that this list will not become too long.
val set_exception_handler : t -> (exn -> unit) -> unitval add_call : ?when_sent:(unit -> bool) ->
t ->
string -> Xdr.xdr_value -> ((unit -> Xdr.xdr_value) -> unit) -> unitadd_call client proc_name arg f: add the call to the procedure name
with argument arg to the queue of unprocessed calls.
When the reply has arrived or an error situation is detected, the
function f is called back. The argument of f is another function
that will return the result or raise an exception:
let my_f get_result =
try
let result = get_result() in
...
with
exn -> ...
in
add_call client name arg my_f
If f does not catch the exception, the pluggable exception handler
of the client is called (see set_exception_handler). Exceptions are
either Message_lost, Message_timeout, or Communication_error.
The function f can raise the exception Keep_call to indicate
the special handling that a further reply of the call is expected
(batching).
when_sent: This function is called when the call has been fully sent
to the server, but before the reply arrives. The function returns whether
to continue the call. By returning false the call is removed from the
internal bookkeeping. The function f is not called in this case.
val event_system : t -> Unixqueue.event_systemval program : t -> Rpc_program.tval get_socket_name : t -> Unix.sockaddrval get_peer_name : t -> Unix.sockaddrval get_protocol : t -> Rpc.protocolval sync_call : t -> string -> Xdr.xdr_value -> Xdr.xdr_valueval shut_down : t -> unitMessage_lost.class type auth_session =object..end
auth_session object is normally created for every client instance.
class type auth_method =object..end
auth_method object represents a method of authentication.
val auth_none : auth_methodval set_auth_methods : t -> auth_method list -> unit auth_none val verbose : bool -> unit