module Channels:sig
..end
exception Too_many_virtual_channels
An exception that may be raised when trying to create a new channel while
the channel count exceed max_virtual_channels
. Note that by default
max_virtual_channels
is set to None
so that the exception is never
raised.
exception Non_unique_channel_name
An exception raised when creating a channel with a name already associated to another channel. It is strictly forbidden to name several channels with the same string.
type
t
The abstract type of server-to-client communication channels.
typechan_id =
string
The type of channel identifier. Channels are uniquely identified by there chan_id value.
val create : ?name:string -> unit -> t
create ()
returns a channel with a freshly baked identifier while
create ~name ()
returns a channel with the identifier name
after
checking for uniqueness. If name
is the identifier of an existing
channel, the exception Non_unique_channel_name
is raised.
val write : t ->
string * Ocsigen_stream.outcome Lwt.u option -> unit
write c (s, u)
sends the string s
on the channel c
. The argument u
allow one to observe the result of the operation. If u
is None
, there
is no way to tell if the sending worked as expected. However if u
is
Some u'
then u'
will be woken up with the outcome (either `Falure
or
`Success
) of the stream writing process.
val listeners : t -> int
listeners c
returns the number of clients currently registered on c
A client is "currently registered" on a channel if an actual
connection is open for the server to push a message onto. Note that this
information is server-based only, and that because it is so, some clients
may still be registered as active while they have in fact closed the
connection. In such a case, the outcome mechanism in write
will report
the failure.
val get_id : t -> chan_id
get_id c
returns the unique identifier associated to c
. The client can
register to c
using the returned identifier.