Page
Library
Module
Module type
Parameter
Class
Class type
Source
Socket
SourceBuffered 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.
Abstract types for buffered sockets.
Create an input channel reading from the given descriptor.
Create an output channel writing on the given descriptor.
Return the descriptor corresponding to an input channel.
Return the descriptor corresponding to an output channel.
Connect to a server at the given address. Return a buffered socket. Can raise the same exceptions as Unix.open_connection
.
``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.)
output oc buf pos len
writes len
characters from string buf
, starting at offset pos
, to the given buffered socket oc
.
Write the character on the given buffered socket.
Write the string on the given buffered socket.
fprintf oc format arguments
is like Printf.fprintf
except that oc
is a buffered socket.
Flush the output buffer associated with the given buffered socket.
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.
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.
Read one character from the given input channel.
really_input ic buf pos len
reads len
characters from the buffered socket ic
, storing them in string buf
, starting at character number pos
.
input_line ic
returns the next line from the socket ic
without the final '\n'.
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
.
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.
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.