test_sfcw.c revision 9a690580
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2#include <assert.h> 3#include <stdio.h> 4#include <stdint.h> 5#include <string.h> 6#include <sys/queue.h> 7 8#include "lsquic_types.h" 9#include "lsquic_int_types.h" 10#include "lsquic.h" 11#include "lsquic_conn_flow.h" 12#include "lsquic_rtt.h" 13#include "lsquic_sfcw.h" 14#include "lsquic_varint.h" 15#include "lsquic_hq.h" 16#include "lsquic_hash.h" 17#include "lsquic_stream.h" 18#include "lsquic_conn_public.h" 19#include "lsquic_conn.h" 20 21 22int 23main (void) 24{ 25 lsquic_global_init(LSQUIC_GLOBAL_SERVER); 26 const unsigned INIT_WINDOW_SIZE = 16 * 1024; 27 struct lsquic_sfcw fc; 28 struct lsquic_conn lconn; 29 struct lsquic_conn_public conn_pub; 30 uint64_t recv_off; 31 int s; 32 33 memset(&lconn, 0, sizeof(lconn)); 34 LSCONN_INITIALIZE(&lconn); 35 memset(&conn_pub, 0, sizeof(conn_pub)); 36 conn_pub.lconn = &lconn; 37 lsquic_sfcw_init(&fc, INIT_WINDOW_SIZE, NULL, &conn_pub, 123); 38 39 recv_off = lsquic_sfcw_get_fc_recv_off(&fc); 40 assert(("First send update advertizes offset same as initial window size", 41 INIT_WINDOW_SIZE == recv_off)); 42 43 s = lsquic_sfcw_fc_offsets_changed(&fc); 44 assert(("First time, recv offset has not changed", !s)); 45 46 s = lsquic_sfcw_set_max_recv_off(&fc, recv_off + 1); 47 assert(("Cannot set max recv larger than flow control receive offset", !s)); 48 49 s = lsquic_sfcw_set_max_recv_off(&fc, recv_off); 50 assert(("Set max recv larger to flow control receive offset successfully", s)); 51 52 s = lsquic_sfcw_fc_offsets_changed(&fc); 53 assert(("fc recv offset has not changed: need to consume data", !s)); 54 55 lsquic_sfcw_set_read_off(&fc, INIT_WINDOW_SIZE * 2 / 3); 56 s = lsquic_sfcw_fc_offsets_changed(&fc); 57 assert(("recv offset has now changed", s)); 58 59 recv_off = lsquic_sfcw_get_fc_recv_off(&fc); 60 assert(("Updated flow control receive window checks out", 61 INIT_WINDOW_SIZE * 5 / 3 == recv_off)); 62 63 return 0; 64} 65