LCOV - code coverage report
Current view: top level - waltz/quic - fd_quic_stream.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 48 52 92.3 %
Date: 2026-05-22 08:05:30 Functions: 4 4 100.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    31299233 :                       ulong              data_sz ) {
      11             :   /* do we have space to buffer data? */
      12             :   /* see fd_quic_stream.h for invariants */
      13    31299233 :   uchar * raw   = buf->buf;
      14    31299233 :   ulong   cap   = buf->cap;
      15    31299233 :   ulong   head  = buf->head;
      16    31299233 :   ulong   free  = cap - head;
      17             : 
      18             :   /* not enough room - caller responsible for checking available space */
      19    31299233 :   if( data_sz > free ) {
      20           0 :     return;
      21           0 :   }
      22             : 
      23    31299233 :   fd_memcpy( raw + head, data, data_sz );
      24             : 
      25    31299233 :   buf->head += data_sz;
      26    31299233 : }
      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    31310099 :                      ulong              data_sz ) {
      35    31310099 :   uchar * raw   = buf->buf;
      36    31310099 :   ulong   head  = buf->head;
      37             : 
      38             :   /* caller responsible for checking operation valid */
      39    31310099 :   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    31310099 :   fd_memcpy( data, raw + offs, data_sz );
      48    31310099 : }
      49             : 
      50             : 
      51             : extern
      52             : ulong
      53             : fd_quic_stream_align( void );
      54             : 
      55             : ulong
      56       31134 : fd_quic_stream_footprint( ulong tx_buf_sz ) {
      57       31134 :   ulong align           = fd_quic_stream_align();
      58       31134 :   ulong offs            = 0ul;
      59             : 
      60       31134 :   ulong tx_ack_sz       = fd_quic_tx_ack_bufsz( tx_buf_sz );
      61       31134 :   ulong align_stream_sz = fd_ulong_align_up( sizeof( fd_quic_stream_t ), align );
      62       31134 :   ulong align_tx_ack_sz = fd_ulong_align_up( tx_ack_sz, align );
      63       31134 :   ulong align_tx_buf_sz = fd_ulong_align_up( tx_buf_sz, align );
      64             : 
      65       31134 :   offs += align_stream_sz; /* space for stream instance */
      66       31134 :   offs += align_tx_buf_sz; /* space for tx_buf */
      67       31134 :   offs += align_tx_ack_sz; /* space for tx_ack */
      68             : 
      69       31134 :   return offs;
      70       31134 : }
      71             : 
      72             : fd_quic_stream_t *
      73       30642 : fd_quic_stream_new( void * mem, fd_quic_conn_t * conn, ulong tx_buf_sz ) {
      74       30642 :   ulong align = fd_quic_stream_align();
      75             : 
      76       30642 :   ulong tx_ack_sz       = fd_quic_tx_ack_bufsz( tx_buf_sz );
      77       30642 :   ulong align_stream_sz = fd_ulong_align_up( sizeof( fd_quic_stream_t ), align );
      78       30642 :   ulong align_tx_buf_sz = fd_ulong_align_up( tx_buf_sz, align );
      79       30642 :   ulong align_tx_ack_sz = fd_ulong_align_up( tx_ack_sz, align );
      80             : 
      81       30642 :   ulong offs = 0;
      82       30642 :   ulong base = (ulong)mem;
      83             : 
      84             :   /* allocate memory for the stream */
      85       30642 :   fd_quic_stream_t * stream = (fd_quic_stream_t*)mem;
      86             : 
      87       30642 :   offs += align_stream_sz;
      88             : 
      89             :   /* allocate memory for the tx buffer */
      90       30642 :   stream->tx_buf.buf = (uchar*)( base + offs );
      91       30642 :   stream->tx_buf.cap = tx_buf_sz;
      92             : 
      93       30642 :   offs += align_tx_buf_sz;
      94             : 
      95             :   /* allocate memory for the tx ack buffer */
      96       30642 :   stream->tx_ack = (uchar*)( base + offs );
      97             : 
      98       30642 :   offs += align_tx_ack_sz;
      99             : 
     100       30642 :   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       30642 :   stream->conn      = conn;
     105       30642 :   stream->stream_id = FD_QUIC_STREAM_ID_UNUSED;
     106             : 
     107             :   /* stream pointing to itself is not a member of any list */
     108       30642 :   stream->next = stream->prev = stream;
     109             : 
     110       30642 :   return stream;
     111       30642 : }

Generated by: LCOV version 1.14