module File : sig ... end
val serve : auth:(Async_extra__.Import.Socket.Address.Inet.t ‑> bool) ‑> Async_extra.Tcp.Where_to_listen.inet ‑> Async_extra.Tcp.Server.inet Async_extra__.Import.Deferred.t
serve ~port ()
must be called before clients will be able to connect. Sets up a
bound tcp socket on port that will be used to serve files to clients. The unit
Deferred will be filled when the server is ready to receive clients.
The auth
function will be called once for every client connection. If it returns
false the client will be disconnected immediately. Further details of auth
can be
found in the documentation for Rpc.serve
.
Once serve
has been called it is a mistake (and will raise) if it is ever called
again.
val open_file : ?append:bool ‑> ?dos_format:bool ‑> string ‑> File.t Async_extra__.Import.Deferred.t
open_file filename
open a file for writing. The filename given should
be a real path on the server, and will create a real file there
val serve_existing_static_file : string ‑> unit Async_extra__.Import.Deferred.t
serve_existing_static_file filename
adds filename
to the list of files
that can be accessed via the Client module. As indicated in the name,
this file must already exist and must not grow or change. When a client
requests the file it will be served from beginning to end.
val stop_serving : File.t ‑> unit
stop_serving t
stops serving the file t to clients. Calling this
function will not close the file if it is open. (A possible use of this
function is if you want to delete the file on the sending side.)
val close : ?stop_serving:bool ‑> File.t ‑> unit Async_extra__.Import.Deferred.t
close t
closes the file t for writing. If stop_serving
is false
(default is true
) the file will be left on disk and will still be served
to clients on a create request.
val write_message : File.t ‑> string ‑> unit
write_message t msg
write msg
to t
. msg
is assumed to contain no
newlines except possibly at the end. A newline will be added to the end
in the file if it is not present. The message may be transmitted to
clients with or without a newline. The string passed to write_message is copied
and so may be freely modified once write_message returns.
val schedule_message : File.t ‑> Core.Bigstring.t ‑> unit
schedule_message t msg
is write, but the message is taken from the
provided bigstring. Once a bigstring has been given to this function it is a
mistake to ever modify the bigstring in the future. This is because it will take an
unknown amount of time to deliver the message to all connected clients
val write_sexp : File.t ‑> Async_extra__.Import.Sexp.t ‑> unit
write_sexp t sexp
writes a Sexp.t as a single message
val flushed : File.t ‑> unit Async_extra__.Import.Deferred.t
flushed t
becomes determined only once all messages written to t
have been
written to disk.
val with_file : ?append:bool ‑> string ‑> f:(File.t ‑> 'a Async_extra__.Import.Deferred.t) ‑> 'a Async_extra__.Import.Deferred.t
with_file filename ~f
opens filename and runs f
, passing the resultant
t
. When the deferred returned by f
is determined, t
will be
closed.
val writer_monitor : File.t ‑> (Async_extra__.Import.Monitor.t, [ `This_is_a_static_file ]) Core.Result.t
monitor t
returns a monitor which will listen to errors arising from the
internal writer used by t
.
val debug_snapshot : unit ‑> Async_extra__.Import.Sexp.t
debug_snapshot ()
returns an s-expression containing details of the current
state of the Tcp_file server.