Library
Module
Module type
Parameter
Class
Class type
Buffered sockets (Pervasive like functions for sockets working on all platforms).
This library is distributed under the terms of the GNU Lesser General Public License, with the special exception on linking as for the OCaml Library.
val in_channel_of_descr : Unix.file_descr -> in_channel
Create an input channel reading from the given descriptor.
val out_channel_of_descr : Unix.file_descr -> out_channel
Create an output channel writing on the given descriptor.
val descr_of_in_channel : in_channel -> Unix.file_descr
Return the descriptor corresponding to an input channel.
val descr_of_out_channel : out_channel -> Unix.file_descr
Return the descriptor corresponding to an output channel.
val open_connection : Unix.sockaddr -> in_channel * out_channel
Connect to a server at the given address. Return a buffered socket. Can raise the same exceptions as Unix.open_connection
.
val shutdown_connection : in_channel -> unit
``Shut down'' a connection established with Socket.open_connection
; that is, transmit an end-of-file condition to the server reading on the other side of the connection. (You should flush the out_channels connected to the same socket if you want to make sure all data is transmitted.)
val output : out_channel -> Bytes.t -> int -> int -> unit
output oc buf pos len
writes len
characters from string buf
, starting at offset pos
, to the given buffered socket oc
.
val output_char : out_channel -> char -> unit
Write the character on the given buffered socket.
val output_string : out_channel -> string -> unit
Write the string on the given buffered socket.
val fprintf : out_channel -> ('a, unit, string, unit) format4 -> 'a
fprintf oc format arguments
is like Printf.fprintf
except that oc
is a buffered socket.
val flush : out_channel -> unit
Flush the output buffer associated with the given buffered socket.
val close_out : out_channel -> unit
close_out oc
closes the socket oc
, flushing all buffered write operations. (This closes the underlying file descriptor as well.) Output functions raise a Sys_error
exception when they are applied to a closed output channel, except close_out
and flush
which do nothing.
val input : in_channel -> Bytes.t -> int -> int -> int
input ic buf pos len
reads up to len
characters from the given socket ic
, storing them in string buf
, starting at character number pos
. It returns the actual number of characters read, between 0 and len
(inclusive).
A return value of 0 means that the end of file was reached.
val input_char : in_channel -> char
Read one character from the given input channel.
val really_input : in_channel -> Bytes.t -> int -> int -> unit
really_input ic buf pos len
reads len
characters from the buffered socket ic
, storing them in string buf
, starting at character number pos
.
val input_line : in_channel -> string
input_line ic
returns the next line from the socket ic
without the final '\n'.
val input_till : char -> in_channel -> Bytes.t -> int -> int -> int
input_till c ic buf pos len
reads up to len
characters different from c
from the socket ic
, storing them in string buf
, starting at character number pos
. The return value is the actual number of characters read (different from c
), between 0 and len
(inclusive). If c
is encountered, the reading stops. c
is left in the input stream; thus all further input_till
commands will return 0
.
val input_all_till : char -> in_channel -> string
input_all_till c ic
returns the next chunk from the socket ic
from the current position to the character c
(excluded) or the end of the file. The character c
is read and discarded.
val close_in : in_channel -> unit
close_in ic
closes the socket ic
. (This closes the underlying file descriptor as well.) Input functions raise a Sys_error
exception when they are applied to a closed input channel, except close_in
, which does nothing when applied to an already closed channel.
val select :
in_channel list ->
out_channel list ->
float ->
in_channel list * out_channel list
select inl outl t
waits at most t
seconds until some input/output operations become possible on some channels among inl
and outl
. A negative t
means unbounded wait. The result is composed of two sets of channels: those ready for reading (first component) and those ready for writing (second component).
I/O objects for the channels respecting the conventions for IO-Classes. The objects only give another access to the channels and their methods can be interspersed with the above function calls.
class out_channel_obj : out_channel -> object ... end
class in_channel_obj : in_channel -> object ... end