package octez-shell-libs
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=dbc3b675aee59c2c574e5d0a771193a2ecfca31e7a5bc5aed66598080596ce1c
sha512=b97ed762b9d24744305c358af0d20f394376b64bfdd758dd4a81775326caf445caa57c4f6445da3dd6468ff492de18e4c14af6f374dfcbb7e4d64b7b720e5e2a
doc/octez-shell-libs.p2p/Tezos_p2p/P2p_buffer_reader/index.html
Module Tezos_p2p.P2p_buffer_readerSource
This module takes care of reading data from a readable into a buffer.
Its purpose is to take care - via those abstract types - of the tedious tracking of byte positions and lengths when copying data around, as well as ensuring invariants for safety of call sites, e.g. "do not read too much" or "wait if no data is readable right now".
A data source. Reading functions read data from it.
A data destination. Reading functions copy data into it.
val mk_readable :
read_buffer:Tezos_stdlib.Circular_buffer.t ->
read_queue:
Tezos_stdlib.Circular_buffer.data Tezos_base.TzPervasives.tzresult
Tezos_stdlib.Lwt_pipe.Maybe_bounded.t ->
readablemk_readable ~read_buffer ~read_queue creates a readable that uses read_buffer to store data and read_queue to notify asynchronously that data was written.
val mk_buffer :
?pos:int ->
?length_to_copy:int ->
bytes ->
buffer Tezos_base.TzPervasives.tzresultmk_buffer ?pos ?length_to_copy bytes creates a buffer for copying length_to_copy bytes into bytes starting at position pos.
posdefaults to0.length_to_copydefaults toBytes.length bytes - pos.
If you neither specify pos nor length_to_copy, prefer using mk_buffer_safe which cannot fail.
If invalid values are passed, fails with Invalid_read_request.
val read :
?canceler:Lwt_canceler.t ->
readable ->
buffer ->
int Tezos_base.TzPervasives.tzresult Lwt.tread readable buffer reads the next segment of data from readable and copies it into buffer, returning the number of read bytes.
- If
readabledoes not currently contain any data, it waits for a segment then reads it. - If
readablealready contains data, it reads immediately.
Note: Even if buffer size is 0, this function still waits for data in readable before returning.
Invariants:
- The returned number of bytes is lower than or equal to the current value of
buffer.length_to_copy. - If the next
readablesegment is smaller than the current value ofbuffer.length_to_copythen only this segment is copied intobuffer(i.e. afterread,buffer.length_to_copymay or may not be0) - If the next
readablesegment is bigger than the current value ofbuffer.length_to_copythen the unused data of that segment is kept for the next read (i.e.readabledoes not lose data).
val read_full :
?canceler:Lwt_canceler.t ->
readable ->
buffer ->
unit Tezos_base.TzPervasives.tzresult Lwt.tread_full readable buffer reads from readable and copies into buffer until buffer is full.
- If
readabledoes not currently contain enough data to fillbuffer, it waits for additional segments and reads them. - If
readablealready contains data, it reads immediately.
Invariants:
buffer.length_to_copyafterread_fullis guaranteed to be0(i.e. it is useless to read intobufferafterwards).- If the last read segment of
readableis bigger than the remaining length ofbufferthen the unused data of that segment is kept for the next read (i.e.readabledoes not lose data).