module Make:
Make a Line Printer daemon according to the configuration C
.
The functions are splitted to offer various points where threads
can be launched.
Raises Failure
if one if the queue names contains a space.
val socket : ?port:int -> unit -> Unix.file_descr
socket ?port ()
creates a socket for the LPD daemon.
port
: allows to specify on which port the socket
listens. By default it is the standard port for LPD i.e. 515.
val accept : ?thread:((unit -> unit) -> unit) ->
Unix.file_descr ->
(Unix.sockaddr -> Socket.in_channel -> Socket.out_channel -> unit) -> 'a
accept ?thread socket f
listen on socket
and, for each
authorized connection (see C.authorized_host
), runs f
addr inchan outchan
where addr
is the address of the
connecting machine and inchan
, outchan
are buffered
communication channels connected to the client. accept
never returns normally.
thread
: tells how to run f
in a separate thread. A
typical example is to declare it as fun f ->
ignore(Thread.create f ())
but of course one can also arrange
the reuse a thread of a pool. The default is not to create a
new thread. Do not use that function to clone the process
with fork
or file descriptors will leak.
val daemon : Unix.sockaddr -> Socket.in_channel -> Socket.out_channel -> unit
deamon addr inchan outchan
will read LPD queries on inchan
and send replies on outchan
. The particular treatement each
query receives is determined by C.queues
. addr
is the
address of the client. This function is typically used as
accept (socket()) daemon
.