module Socket:Buffered sockets (Pervasive like functions for sockets working on all platforms).sig
..end
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.
Author(s): Christophe Troestler
Version: 0.8
type
in_channel
type
out_channel
val in_channel_of_descr : Unix.file_descr -> in_channel
val out_channel_of_descr : Unix.file_descr -> out_channel
val descr_of_in_channel : in_channel -> Unix.file_descr
val descr_of_out_channel : out_channel -> Unix.file_descr
val open_connection : Unix.sockaddr -> in_channel * out_channel
Unix.open_connection
.val shutdown_connection : in_channel -> unit
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 -> string -> int -> int -> unit
output oc buf pos len
writes len
characters from string
buf
, starting at offset pos
, to the given buffered socket oc
.Invalid_argument
"Socket.output" if pos
and len
do not
designate a valid substring of buf
.Sys_blocked_io
if we are in non-blocking mode and output
would block.val output_char : out_channel -> char -> unit
val output_string : out_channel -> string -> unit
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
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 -> string -> 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.
Raises
Invalid_argument
"Socket.input" if pos
and len
do not
designate a valid substring of buf
.Sys_blocked_io
if we are in non-blocking mode and input
would block (no characters are then read).val input_char : in_channel -> char
End_of_file
if there are no more characters to read.Sys_blocked_io
if we are in non-blocking mode and input_char
would block (no characters are then read).val really_input : in_channel -> string -> 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
.End_of_file
if the end of file is reached before len
characters have been read.Invalid_argument
"Socket.really_read" if pos
and len
do not designate a valid substring of buf
.Sys_blocked_io
if we are in non-blocking mode and really_input
would block (the characters that may have been read are lost).val input_line : in_channel -> string
input_line ic
returns the next line from the socket ic
without the final '\n'.End_of_file
if the end of the file is reached.Sys_blocked_io
if we are in non-blocking mode and
input_line
would block (the characters that may have been read
are lost).val input_till : char -> in_channel -> string -> 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
.End_of_file
if the end of the file is reached (i.e.,
there are no more characters to read). This is different from the
return value being 0
-- the latter indicating that the first
character in the stream is c
.Invalid_argument
"Socket.input_till" if pos
and len
do not designate a valid substring of buf
.Sys_blocked_io
if we are in non-blocking mode and input_till
would block (no characters are then read).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 characted c
is read and discarded.End_of_file
if the end of the file is reached before any
character can be read. (This is different from an empty string
being returned which indicates that c
is the first character in
the input stream.)Sys_blocked_io
if we are in non-blocking mode and input_all_till
would block (the characters that may have been read are lost).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).class out_channel_obj :out_channel ->
object
..end
class in_channel_obj :in_channel ->
object
..end