package eio
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=8ed5c13e6689f31c85dca5f12762d84b8cc0042a7b07d3e464df6eb4b72b3dfc
sha512=46e8f817f32c3316e7f35835a136ad177a295b3306351eb2efa2386482b0169a5b19ed2925b32da2a1f10d40f083fe3d588dd401908f9fec6e4a44cd68535204
doc/eio/Eio/Flow/index.html
Module Eio.FlowSource
A flow can be used to read or write bytes.
Flows are used to represent byte streams, such as open files and network sockets. A source provides a stream of bytes. A sink consumes a stream. A two_way can do both.
To read structured data (e.g. a line at a time), wrap a source using Buf_read.
Types
Sources can offer a list of ways to read them, in order of preference.
type shutdown_command = [ | `Receive(*Indicate that no more reads will be done
*)| `Send(*Indicate that no more writes will be done
*)| `All(*Indicate that no more reads or writes will be done
*)
]Reading
single_read src buf reads one or more bytes into buf.
It returns the number of bytes read (which may be less than the buffer size even if there is more data to be read).
- Use
read_exactinstead if you want to fillbufcompletely. - Use
Buf_read.lineto read complete lines. - Use
copyto stream data directly from a source to a sink.
buf must not be zero-length.
read_exact src dst keeps reading into dst until it is full.
string_source s is a source that gives the bytes of s.
cstruct_source cs is a source that gives the bytes of cs.
type read_method += | Read_source_buffer of 't -> (Cstruct.t list -> int) -> unit(*If a source offers
Read_source_buffer rsbthen the user can callrsb t fnto borrow a view of the source's buffers.fnreturns the number of bytes it consumed.rsbwill raiseEnd_of_fileif no more data will be produced. If no data is currently available,rsbwill wait for some to become available before callingfn.
*)fnmust not continue to use the buffers after it returns.
Writing
single_write dst bufs writes at least one byte from bufs and returns the number of bytes written.
copy src dst copies data from src to dst until end-of-file.
buffer_sink b is a sink that adds anything sent to it to b.
To collect data as a cstruct, use Buf_read instead.
Bidirectional streams
shutdown t cmd indicates that the caller has finished reading or writing t (depending on cmd).
This is useful in some protocols to indicate that you have finished sending the request, and that the remote peer should now send the response.
Closing
Flows are usually attached to switches and closed automatically when the switch finishes. However, it can be useful to close them sooner manually in some cases.
Alias of Resource.close.