package octez-shell-libs
Install
    
    dune-project
 Dependency
Authors
Maintainers
Sources
sha256=55ea1fb8bb3273a7fc270ca8f650d45c56449665619482aad9bc12f3ea736b7e
    
    
  sha512=fec850fc2d17d7490bbabd5147d62aad13b3aaed8774270f8a38ab419670ed03e0fd30cf8642a97984eca5c2446726fe590ad99c015f7ec50919dc7652f25053
    
    
  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 to- 0.
- length_to_copydefaults to- Bytes.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_copyafter- read_fullis guaranteed to be- 0(i.e. it is useless to read into- bufferafterwards).
- 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).