module Io:sig
..end
Unix.file_descr
.
With Duppy.Io.read
, you can pass a file descriptor to the scheduler,
along with a marker, and have it run the associated function when the
marker is found.
With Duppy.Io.write
, the schdeduler will try to write recursively to the file descriptor
the given string.
type
marker =
| |
Length of |
| |
Split of |
Split s
recognizes all regexp allowed by the
Pcre
module.
type
failure =
| |
Int of |
| |
Unix of |
| |
Unknown of |
Int d
is raised when reading or writing failed.
the returned value is respectively the ammount of
data read or written
val read : ?recursive:bool ->
?init:string ->
?on_error:(failure -> unit) ->
priority:'a ->
'a Duppy.scheduler ->
Unix.file_descr -> marker -> (string list -> unit) -> unit
Can be used recursively or not, depending on the way you process strings. Because of Unix's semantic, it is not possible to stop reading at first marker, so there can be a remaining string. If not used recursively, this string will be the last string passed in the list. You should then initiate the next read with this value.
The on_error
function is used when reading failed on the socket.
Depending on your usage, it can be a hard failure, or simply a lost client.
recursive
: recursively read and process, default: true
init
: initial string for reading, default: ""
on_error
: function used when read failed, default: fun _ -> ()
val write : ?exec:(unit -> unit) ->
?on_error:(failure -> unit) ->
priority:'a -> 'a Duppy.scheduler -> Unix.file_descr -> string -> unit
read
but less complex.
Simply write a string to the socket, and then launch some callback.
exec
: function to execute after writing, default: fun () -> ()