LCOV - code coverage report
Current view: top level - waltz/quic - fd_quic_stream.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 52 0.0 %
Date: 2026-10-22 18:10:43 Functions: 0 4 0.0 %

          Line data    Source code
       1             : #include "fd_quic_stream.h"
       2             : #include "fd_quic_enum.h"
       3             : 
       4             : /* buffer helper functions */
       5             : /* fd_quic_buffer_store
       6             :    store data into circular buffer */
       7             : void
       8             : fd_quic_buffer_store( fd_quic_buffer_t * buf,
       9             :                       uchar const *      data,
      10           0 :                       ulong              data_sz ) {
      11             :   /* do we have space to buffer data? */
      12             :   /* see fd_quic_stream.h for invariants */
      13           0 :   uchar * raw   = buf->buf;
      14           0 :   ulong   cap   = buf->cap;
      15           0 :   ulong   head  = buf->head;
      16           0 :   ulong   free  = cap - head;
      17             : 
      18             :   /* not enough room - caller responsible for checking available space */
      19           0 :   if( data_sz > free ) {
      20           0 :     return;
      21           0 :   }
      22             : 
      23           0 :   fd_memcpy( raw + head, data, data_sz );
      24             : 
      25           0 :   buf->head += data_sz;
      26           0 : }
      27             : 
      28             : /* fd_quic_buffer_load
      29             :    load data from circular buffer */
      30             : void
      31             : fd_quic_buffer_load( fd_quic_buffer_t * buf,
      32             :                      ulong              offs,
      33             :                      uchar *            data,
      34           0 :                      ulong              data_sz ) {
      35           0 :   uchar * raw   = buf->buf;
      36           0 :   ulong   head  = buf->head;
      37             : 
      38             :   /* caller responsible for checking operation valid */
      39           0 :   if( FD_UNLIKELY( offs+data_sz > head ) ) return;
      40             : 
      41             :   /* two cases:
      42             :      1. data fits within free contiguous space at m_tail
      43             :      2. data is split
      44             : 
      45             :      used is in [offs,head) */
      46             : 
      47           0 :   fd_memcpy( data, raw + offs, data_sz );
      48           0 : }
      49             : 
      50             : 
      51             : extern
      52             : ulong
      53             : fd_quic_stream_align( void );
      54             : 
      55             : ulong
      56           0 : fd_quic_stream_footprint( ulong tx_buf_sz ) {
      57           0 :   ulong align           = fd_quic_stream_align();
      58           0 :   ulong offs            = 0ul;
      59             : 
      60           0 :   ulong tx_ack_sz       = fd_quic_tx_ack_bufsz( tx_buf_sz );
      61           0 :   ulong align_stream_sz = fd_ulong_align_up( sizeof( fd_quic_stream_t ), align );
      62           0 :   ulong align_tx_ack_sz = fd_ulong_align_up( tx_ack_sz, align );
      63           0 :   ulong align_tx_buf_sz = fd_ulong_align_up( tx_buf_sz, align );
      64             : 
      65           0 :   offs += align_stream_sz; /* space for stream instance */
      66           0 :   offs += align_tx_buf_sz; /* space for tx_buf */
      67           0 :   offs += align_tx_ack_sz; /* space for tx_ack */
      68             : 
      69           0 :   return offs;
      70           0 : }
      71             : 
      72             : fd_quic_stream_t *
      73           0 : fd_quic_stream_new( void * mem, fd_quic_conn_t * conn, ulong tx_buf_sz ) {
      74           0 :   ulong align = fd_quic_stream_align();
      75             : 
      76           0 :   ulong tx_ack_sz       = fd_quic_tx_ack_bufsz( tx_buf_sz );
      77           0 :   ulong align_stream_sz = fd_ulong_align_up( sizeof( fd_quic_stream_t ), align );
      78           0 :   ulong align_tx_buf_sz = fd_ulong_align_up( tx_buf_sz, align );
      79           0 :   ulong align_tx_ack_sz = fd_ulong_align_up( tx_ack_sz, align );
      80             : 
      81           0 :   ulong offs = 0;
      82           0 :   ulong base = (ulong)mem;
      83             : 
      84             :   /* allocate memory for the stream */
      85           0 :   fd_quic_stream_t * stream = (fd_quic_stream_t*)mem;
      86             : 
      87           0 :   offs += align_stream_sz;
      88             : 
      89             :   /* allocate memory for the tx buffer */
      90           0 :   stream->tx_buf.buf = (uchar*)( base + offs );
      91           0 :   stream->tx_buf.cap = tx_buf_sz;
      92             : 
      93           0 :   offs += align_tx_buf_sz;
      94             : 
      95             :   /* allocate memory for the tx ack buffer */
      96           0 :   stream->tx_ack = (uchar*)( base + offs );
      97             : 
      98           0 :   offs += align_tx_ack_sz;
      99             : 
     100           0 :   if( offs != fd_quic_stream_footprint( tx_buf_sz ) ) {
     101           0 :     FD_LOG_ERR(( "fd_quic_stream_new : allocated size of stream does not match footprint" ));
     102           0 :   }
     103             : 
     104           0 :   stream->conn      = conn;
     105           0 :   stream->stream_id = FD_QUIC_STREAM_ID_UNUSED;
     106             : 
     107             :   /* stream pointing to itself is not a member of any list */
     108           0 :   stream->next = stream->prev = stream;
     109             : 
     110           0 :   return stream;
     111           0 : }

Generated by: LCOV version 1.14