123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108(*
* Copyright (c) 2011-2015 Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2013-2015 Thomas Gazagnaire <thomas@gazagnaire.org>
* Copyright (c) 2013 Citrix Systems Inc
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)(** MirageOS signature for channel devices.
Channels are buffered byte-streams which are attached to an
unbuffered flow (e.g. a TCPv4 connection).
{e Release v3.1.0 } *)openResultmoduletypeS=sigtypeerror(** The type for errors. *)valpp_error:errorFmt.t(** [pp_error] is the pretty-printer for errors. *)typewrite_error=private[>Mirage_flow.write_error](** The type for write errors. *)valpp_write_error:write_errorFmt.t(** [pp_write_error] is the pretty-printer for write errors. *)typebuffer(** The type for memory buffers. *)typeflow(** The type for unbuffered network flow. *)typet(** The type for the state associated with channels, such as the
inflight buffers. *)type+'aio(** The type for potentially blocking I/O operation *)valcreate:flow->t(** [create flow] allocates send and receive buffers and
associates them with the given unbuffered [flow]. *)valto_flow:t->flow(** [to_flow t] returns the flow that backs this channel. *)valread_char:t->(charMirage_flow.or_eof,error)resultio(** Reads a single character from the channel, blocking if there is
no immediately available input data. *)valread_some:?len:int->t->(bufferMirage_flow.or_eof,error)resultio(** [read_some ?len t] reads up to [len] characters from the
input channel and at most a full [buffer]. If [len] is not
specified, it reads all available data and returns that
buffer. *)valread_exactly:len:int->t->(bufferlistMirage_flow.or_eof,error)resultio(** [read_exactly len t] reads [len] bytes from the channel [t] or fails
with [Eof]. *)valread_line:t->(bufferlistMirage_flow.or_eof,error)resultio(** [read_line t] reads a line of input, which is terminated
either by a CRLF sequence, or the end of the channel (which
counts as a line). @return Returns a list of views that
terminates at EOF. *)valwrite_char:t->char->unit(** [write_char t ch] writes a single character to the output
channel. *)valwrite_string:t->string->int->int->unit(** [write_string t buf off len] writes [len] bytes from a string
[buf], starting from from offset [off]. *)valwrite_buffer:t->buffer->unit(** [write_buffer t buf] copies the buffer to the channel's
output buffer. The buffer should not be modified after being
written, and it will be recycled into the buffer allocation pool
at some future point. *)valwrite_line:t->string->unit(** [write_line t buf] writes the string [buf] to the output
channel and append a newline character afterwards. *)valflush:t->(unit,write_error)resultio(** [flush t] flushes the output buffer and block if necessary
until it is all written out to the flow. *)valclose:t->(unit,write_error)resultio(** [close t] calls {!flush} and then close the underlying
flow. *)end