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.
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
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.
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.)
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.
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.
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
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.
monitor t
returns a monitor which will listen to errors arising from the
internal writer used by t
.
debug_snapshot ()
returns an s-expression containing details of the current
state of the Tcp_file server.