| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,13 +27,15 @@ | |||
| 27 | 27 | 'ngtcp2/lib/ngtcp2_objalloc.c', | |
| 28 | 28 | 'ngtcp2/lib/ngtcp2_opl.c', | |
| 29 | 29 | 'ngtcp2/lib/ngtcp2_path.c', | |
| 30 | + 'ngtcp2/lib/ngtcp2_pcg.c', | ||
| 30 | 31 | 'ngtcp2/lib/ngtcp2_pkt.c', | |
| 31 | 32 | 'ngtcp2/lib/ngtcp2_pmtud.c', | |
| 32 | 33 | 'ngtcp2/lib/ngtcp2_ppe.c', | |
| 33 | 34 | 'ngtcp2/lib/ngtcp2_pq.c', | |
| 34 | 35 | 'ngtcp2/lib/ngtcp2_pv.c', | |
| 35 | 36 | 'ngtcp2/lib/ngtcp2_qlog.c', | |
| 36 | 37 | 'ngtcp2/lib/ngtcp2_range.c', | |
| 38 | + 'ngtcp2/lib/ngtcp2_ratelim.c', | ||
| 37 | 39 | 'ngtcp2/lib/ngtcp2_ringbuf.c', | |
| 38 | 40 | 'ngtcp2/lib/ngtcp2_rob.c', | |
| 39 | 41 | 'ngtcp2/lib/ngtcp2_rst.c', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1704,7 +1704,8 @@ typedef enum ngtcp2_token_type { | |||
| 1704 | 1704 | ||
| 1705 | 1705 | #define NGTCP2_SETTINGS_V1 1 | |
| 1706 | 1706 | #define NGTCP2_SETTINGS_V2 2 | |
| 1707 | - #define NGTCP2_SETTINGS_VERSION NGTCP2_SETTINGS_V2 | ||
| 1707 | + #define NGTCP2_SETTINGS_V3 3 | ||
| 1708 | + #define NGTCP2_SETTINGS_VERSION NGTCP2_SETTINGS_V3 | ||
| 1708 | 1709 | ||
| 1709 | 1710 | /** | |
| 1710 | 1711 | * @struct | |
@@ -1917,6 +1918,23 @@ typedef struct ngtcp2_settings { | |||
| 1917 | 1918 | * field has been available since v1.4.0. | |
| 1918 | 1919 | */ | |
| 1919 | 1920 | size_t pmtud_probeslen; | |
| 1921 | + /* The following fields have been added since NGTCP2_SETTINGS_V3. */ | ||
| 1922 | + /** | ||
| 1923 | + * :member:`glitch_ratelim_burst` is the maximum number of tokens | ||
| 1924 | + * available to "glitch" rate limiter. "glitch" is a suspicious | ||
| 1925 | + * activity from a remote endpoint. If detected, certain amount of | ||
| 1926 | + * tokens are consumed. If no tokens are available to consume, the | ||
| 1927 | + * connection is closed. The rate of token generation is specified | ||
| 1928 | + * by :member:`glitch_ratelim_rate`. This field has been available | ||
| 1929 | + * since v1.15.0. | ||
| 1930 | + */ | ||
| 1931 | + uint64_t glitch_ratelim_burst; | ||
| 1932 | + /** | ||
| 1933 | + * :member:`glitch_ratelim_rate` is the number of tokens generated | ||
| 1934 | + * per second. See :member:`glitch_ratelim_burst` for "glitch" rate | ||
| 1935 | + * limiter. This field has been available since v1.15.0. | ||
| 1936 | + */ | ||
| 1937 | + uint64_t glitch_ratelim_rate; | ||
| 1920 | 1938 | } ngtcp2_settings; | |
| 1921 | 1939 | ||
| 1922 | 1940 | /** | |
@@ -3000,9 +3018,8 @@ typedef int (*ngtcp2_begin_path_validation)(ngtcp2_conn *conn, uint32_t flags, | |||
| 3000 | 3018 | * an application the outcome of path validation. |flags| is zero or | |
| 3001 | 3019 | * more of :macro:`NGTCP2_PATH_VALIDATION_FLAG_* | |
| 3002 | 3020 | * <NGTCP2_PATH_VALIDATION_FLAG_NONE>`. |path| is the path that was | |
| 3003 | - * validated. |old_path| is the path that is previously used before a | ||
| 3004 | - * local endpoint has migrated to |path| if |old_path| is not NULL. | ||
| 3005 | - * If |res| is | ||
| 3021 | + * validated. |fallback_path|, if not NULL, is the path that is used | ||
| 3022 | + * if the path validation failed. If |res| is | ||
| 3006 | 3023 | * :enum:`ngtcp2_path_validation_result.NGTCP2_PATH_VALIDATION_RESULT_SUCCESS`, | |
| 3007 | 3024 | * the path validation succeeded. If |res| is | |
| 3008 | 3025 | * :enum:`ngtcp2_path_validation_result.NGTCP2_PATH_VALIDATION_RESULT_FAILURE`, | |
@@ -3014,7 +3031,7 @@ typedef int (*ngtcp2_begin_path_validation)(ngtcp2_conn *conn, uint32_t flags, | |||
| 3014 | 3031 | */ | |
| 3015 | 3032 | typedef int (*ngtcp2_path_validation)(ngtcp2_conn *conn, uint32_t flags, | |
| 3016 | 3033 | const ngtcp2_path *path, | |
| 3017 | - const ngtcp2_path *old_path, | ||
| 3034 | + const ngtcp2_path *fallback_path, | ||
| 3018 | 3035 | ngtcp2_path_validation_result res, | |
| 3019 | 3036 | void *user_data); | |
| 3020 | 3037 | ||
@@ -5598,6 +5615,77 @@ NGTCP2_EXTERN size_t ngtcp2_conn_get_send_quantum(ngtcp2_conn *conn); | |||
| 5598 | 5615 | NGTCP2_EXTERN size_t ngtcp2_conn_get_stream_loss_count(ngtcp2_conn *conn, | |
| 5599 | 5616 | int64_t stream_id); | |
| 5600 | 5617 | ||
| 5618 | + /** | ||
| 5619 | + * @functypedef | ||
| 5620 | + * | ||
| 5621 | + * :type:`ngtcp2_write_pkt` is a callback function to write a single | ||
| 5622 | + * packet in the buffer pointed by |dest| of length |destlen|. The | ||
| 5623 | + * implementation should use `ngtcp2_conn_write_pkt`, | ||
| 5624 | + * `ngtcp2_conn_writev_stream`, `ngtcp2_conn_writev_datagram`, or | ||
| 5625 | + * their variants to write the packet. |path|, |pi|, |dest|, | ||
| 5626 | + * |destlen|, and |ts| should be directly passed to those functions. | ||
| 5627 | + * If the callback succeeds, it should return the number of bytes | ||
| 5628 | + * written to the buffer. In general, this callback function should | ||
| 5629 | + * return the value that the above mentioned functions returned except | ||
| 5630 | + * for the following error codes: | ||
| 5631 | + * | ||
| 5632 | + * - :macro:`NGTCP2_ERR_STREAM_DATA_BLOCKED` | ||
| 5633 | + * - :macro:`NGTCP2_ERR_STREAM_SHUT_WR` | ||
| 5634 | + * - :macro:`NGTCP2_ERR_STREAM_NOT_FOUND` | ||
| 5635 | + * | ||
| 5636 | + * Those error codes should be handled by an application. If any | ||
| 5637 | + * error occurred outside those functions, return | ||
| 5638 | + * :macro:`NGTCP2_ERR_CALLBACK_FAILURE`. If no packet is produced, | ||
| 5639 | + * return 0. | ||
| 5640 | + * | ||
| 5641 | + * Because GSO requires that the aggregated packets have the same | ||
| 5642 | + * length, :macro:`NGTCP2_WRITE_STREAM_FLAG_PADDING` (or | ||
| 5643 | + * :macro:`NGTCP2_WRITE_DATAGRAM_FLAG_PADDING` if | ||
| 5644 | + * `ngtcp2_conn_writev_datagram` is used) is recommended. | ||
| 5645 | + * | ||
| 5646 | + * This callback function has been available since v1.15.0. | ||
| 5647 | + */ | ||
| 5648 | + typedef ngtcp2_ssize (*ngtcp2_write_pkt)(ngtcp2_conn *conn, ngtcp2_path *path, | ||
| 5649 | + ngtcp2_pkt_info *pi, uint8_t *dest, | ||
| 5650 | + size_t destlen, ngtcp2_tstamp ts, | ||
| 5651 | + void *user_data); | ||
| 5652 | + | ||
| 5653 | + /** | ||
| 5654 | + * @function | ||
| 5655 | + * | ||
| 5656 | + * `ngtcp2_conn_write_aggregate_pkt` is a helper function to write | ||
| 5657 | + * multiple packets in the provided buffer, which is suitable to be | ||
| 5658 | + * sent at once in GSO. This function returns the number of bytes | ||
| 5659 | + * written to the buffer pointed by |buf| of length |buflen|. | ||
| 5660 | + * |buflen| must be at least | ||
| 5661 | + * `ngtcp2_conn_get_path_max_tx_udp_payload_size(conn) | ||
| 5662 | + * <ngtcp2_conn_get_path_max_tx_udp_payload_size>` bytes long. It is | ||
| 5663 | + * recommended to pass the buffer at least | ||
| 5664 | + * `ngtcp2_conn_get_max_tx_udp_payload_size(conn) | ||
| 5665 | + * <ngtcp2_conn_get_max_tx_udp_payload_size>` bytes in order to send a | ||
| 5666 | + * PMTUD packet. This function only writes multiple packets if the | ||
| 5667 | + * first packet is `ngtcp2_conn_get_path_max_tx_udp_payload_size(conn) | ||
| 5668 | + * <ngtcp2_conn_get_path_max_tx_udp_payload_size>` bytes long. The | ||
| 5669 | + * application can adjust the length of the buffer to limit the number | ||
| 5670 | + * of packets to aggregate. If this function returns positive | ||
| 5671 | + * integer, all packets share the same :type:`ngtcp2_path` and | ||
| 5672 | + * :type:`ngtcp2_pkt_info` values, and they are assigned to the | ||
| 5673 | + * objects pointed by |path| and |pi| respectively. The length of all | ||
| 5674 | + * packets other than the last packet is assigned to |*pgsolen|. The | ||
| 5675 | + * length of last packet is equal to or less than |*pgsolen|. | ||
| 5676 | + * |write_pkt| must write a single packet. After all packets are | ||
| 5677 | + * written, this function calls `ngtcp2_conn_update_pkt_tx_time`. | ||
| 5678 | + * | ||
| 5679 | + * This function returns the number of bytes written to the buffer, or | ||
| 5680 | + * a negative error code returned by |write_pkt|. | ||
| 5681 | + * | ||
| 5682 | + * This function has been available since v1.15.0. | ||
| 5683 | + */ | ||
| 5684 | + NGTCP2_EXTERN ngtcp2_ssize ngtcp2_conn_write_aggregate_pkt_versioned( | ||
| 5685 | + ngtcp2_conn *conn, ngtcp2_path *path, int pkt_info_version, | ||
| 5686 | + ngtcp2_pkt_info *pi, uint8_t *buf, size_t buflen, size_t *pgsolen, | ||
| 5687 | + ngtcp2_write_pkt write_pkt, ngtcp2_tstamp ts); | ||
| 5688 | + | ||
| 5601 | 5689 | /** | |
| 5602 | 5690 | * @function | |
| 5603 | 5691 | * | |
@@ -5680,15 +5768,19 @@ NGTCP2_EXTERN void ngtcp2_path_storage_zero(ngtcp2_path_storage *ps); | |||
| 5680 | 5768 | * values. First this function fills |settings| with 0, and set the | |
| 5681 | 5769 | * default value to the following fields: | |
| 5682 | 5770 | * | |
| 5683 | - * * :type:`cc_algo <ngtcp2_settings.cc_algo>` = | ||
| 5771 | + * * :member:`cc_algo <ngtcp2_settings.cc_algo>` = | ||
| 5684 | 5772 | * :enum:`ngtcp2_cc_algo.NGTCP2_CC_ALGO_CUBIC` | |
| 5685 | - * * :type:`initial_rtt <ngtcp2_settings.initial_rtt>` = | ||
| 5773 | + * * :member:`initial_rtt <ngtcp2_settings.initial_rtt>` = | ||
| 5686 | 5774 | * :macro:`NGTCP2_DEFAULT_INITIAL_RTT` | |
| 5687 | - * * :type:`ack_thresh <ngtcp2_settings.ack_thresh>` = 2 | ||
| 5688 | - * * :type:`max_tx_udp_payload_size | ||
| 5775 | + * * :member:`ack_thresh <ngtcp2_settings.ack_thresh>` = 2 | ||
| 5776 | + * * :member:`max_tx_udp_payload_size | ||
| 5689 | 5777 | * <ngtcp2_settings.max_tx_udp_payload_size>` = 1452 | |
| 5690 | - * * :type:`handshake_timeout <ngtcp2_settings.handshake_timeout>` = | ||
| 5778 | + * * :member:`handshake_timeout <ngtcp2_settings.handshake_timeout>` = | ||
| 5691 | 5779 | * ``UINT64_MAX`` | |
| 5780 | + * * :member:`glitch_ratelim_burst | ||
| 5781 | + * <ngtcp2_settings.glitch_ratelim_burst>` = 1000 | ||
| 5782 | + * * :member:`glitch_ratelim_rate | ||
| 5783 | + * <ngtcp2_settings.glitch_ratelim_rate>` = 33 | ||
| 5692 | 5784 | */ | |
| 5693 | 5785 | NGTCP2_EXTERN void ngtcp2_settings_default_versioned(int settings_version, | |
| 5694 | 5786 | ngtcp2_settings *settings); | |
@@ -5700,15 +5792,15 @@ NGTCP2_EXTERN void ngtcp2_settings_default_versioned(int settings_version, | |||
| 5700 | 5792 | * default values. First this function fills |params| with 0, and set | |
| 5701 | 5793 | * the default value to the following fields: | |
| 5702 | 5794 | * | |
| 5703 | - * * :type:`max_udp_payload_size | ||
| 5795 | + * * :member:`max_udp_payload_size | ||
| 5704 | 5796 | * <ngtcp2_transport_params.max_udp_payload_size>` = | |
| 5705 | 5797 | * :macro:`NGTCP2_DEFAULT_MAX_RECV_UDP_PAYLOAD_SIZE` | |
| 5706 | - * * :type:`ack_delay_exponent | ||
| 5798 | + * * :member:`ack_delay_exponent | ||
| 5707 | 5799 | * <ngtcp2_transport_params.ack_delay_exponent>` = | |
| 5708 | 5800 | * :macro:`NGTCP2_DEFAULT_ACK_DELAY_EXPONENT` | |
| 5709 | - * * :type:`max_ack_delay <ngtcp2_transport_params.max_ack_delay>` = | ||
| 5801 | + * * :member:`max_ack_delay <ngtcp2_transport_params.max_ack_delay>` = | ||
| 5710 | 5802 | * :macro:`NGTCP2_DEFAULT_MAX_ACK_DELAY` | |
| 5711 | - * * :type:`active_connection_id_limit | ||
| 5803 | + * * :member:`active_connection_id_limit | ||
| 5712 | 5804 | * <ngtcp2_transport_params.active_connection_id_limit>` = | |
| 5713 | 5805 | * :macro:`NGTCP2_DEFAULT_ACTIVE_CONNECTION_ID_LIMIT` | |
| 5714 | 5806 | */ | |
@@ -5980,6 +6072,17 @@ NGTCP2_EXTERN uint32_t ngtcp2_select_version(const uint32_t *preferred_versions, | |||
| 5980 | 6072 | #define ngtcp2_conn_get_conn_info(CONN, CINFO) \ | |
| 5981 | 6073 | ngtcp2_conn_get_conn_info_versioned((CONN), NGTCP2_CONN_INFO_VERSION, (CINFO)) | |
| 5982 | 6074 | ||
| 6075 | + /* | ||
| 6076 | + * `ngtcp2_conn_write_aggregate_pkt` is a wrapper around | ||
| 6077 | + * `ngtcp2_conn_write_aggregate_pkt_versioned` to set the correct | ||
| 6078 | + * struct version. | ||
| 6079 | + */ | ||
| 6080 | + #define ngtcp2_conn_write_aggregate_pkt(CONN, PATH, PI, BUF, BUFLEN, PGSOLEN, \ | ||
| 6081 | + WRITE_PKT, TS) \ | ||
| 6082 | + ngtcp2_conn_write_aggregate_pkt_versioned( \ | ||
| 6083 | + (CONN), (PATH), NGTCP2_PKT_INFO_VERSION, (PI), (BUF), (BUFLEN), (PGSOLEN), \ | ||
| 6084 | + (WRITE_PKT), (TS)) | ||
| 6085 | + | ||
| 5983 | 6086 | /* | |
| 5984 | 6087 | * `ngtcp2_settings_default` is a wrapper around | |
| 5985 | 6088 | * `ngtcp2_settings_default_versioned` to set the correct struct | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | * | |
| 37 | 37 | * Version number of the ngtcp2 library release. | |
| 38 | 38 | */ | |
| 39 | - #define NGTCP2_VERSION "1.14.0" | ||
| 39 | + #define NGTCP2_VERSION "1.15.1" | ||
| 40 | 40 | ||
| 41 | 41 | /** | |
| 42 | 42 | * @macro | |
@@ -46,6 +46,6 @@ | |||
| 46 | 46 | * number, 8 bits for minor and 8 bits for patch. Version 1.2.3 | |
| 47 | 47 | * becomes 0x010203. | |
| 48 | 48 | */ | |
| 49 | - #define NGTCP2_VERSION_NUM 0x010e00 | ||
| 49 | + #define NGTCP2_VERSION_NUM 0x010f01 | ||
| 50 | 50 | ||
| 51 | 51 | #endif /* !defined(NGTCP2_VERSION_H) */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -316,9 +316,9 @@ void ngtcp2_acktr_recv_ack(ngtcp2_acktr *acktr, const ngtcp2_ack *fr) { | |||
| 316 | 316 | } | |
| 317 | 317 | ||
| 318 | 318 | void ngtcp2_acktr_commit_ack(ngtcp2_acktr *acktr) { | |
| 319 | - acktr->flags &= (uint16_t) ~(NGTCP2_ACKTR_FLAG_ACTIVE_ACK | | ||
| 320 | - NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK | | ||
| 321 | - NGTCP2_ACKTR_FLAG_CANCEL_TIMER); | ||
| 319 | + acktr->flags &= | ||
| 320 | + (uint16_t)~(NGTCP2_ACKTR_FLAG_ACTIVE_ACK | NGTCP2_ACKTR_FLAG_IMMEDIATE_ACK | | ||
| 321 | + NGTCP2_ACKTR_FLAG_CANCEL_TIMER); | ||
| 322 | 322 | acktr->first_unacked_ts = UINT64_MAX; | |
| 323 | 323 | acktr->rx_npkt = 0; | |
| 324 | 324 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ | |||
| 33 | 33 | #include "ngtcp2_rcvry.h" | |
| 34 | 34 | #include "ngtcp2_rst.h" | |
| 35 | 35 | #include "ngtcp2_conn_stat.h" | |
| 36 | + #include "ngtcp2_pcg.h" | ||
| 36 | 37 | ||
| 37 | 38 | #define NGTCP2_BBR_MAX_BW_FILTERLEN 2 | |
| 38 | 39 | ||
@@ -906,15 +907,9 @@ static int bbr_is_time_to_probe_bw(ngtcp2_cc_bbr *bbr, ngtcp2_conn_stat *cstat, | |||
| 906 | 907 | } | |
| 907 | 908 | ||
| 908 | 909 | static void bbr_pick_probe_wait(ngtcp2_cc_bbr *bbr) { | |
| 909 | - uint8_t rand; | ||
| 910 | - | ||
| 911 | - bbr->rand(&rand, 1, &bbr->rand_ctx); | ||
| 912 | - | ||
| 913 | - bbr->rounds_since_bw_probe = (uint64_t)(rand / 128); | ||
| 914 | - | ||
| 915 | - bbr->rand(&rand, 1, &bbr->rand_ctx); | ||
| 916 | - | ||
| 917 | - bbr->bw_probe_wait = 2 * NGTCP2_SECONDS + NGTCP2_SECONDS * rand / 255; | ||
| 910 | + bbr->rounds_since_bw_probe = ngtcp2_pcg32_rand_n(bbr->pcg, 2); | ||
| 911 | + bbr->bw_probe_wait = | ||
| 912 | + 2 * NGTCP2_SECONDS + ngtcp2_pcg32_rand_n(bbr->pcg, NGTCP2_SECONDS + 1); | ||
| 918 | 913 | } | |
| 919 | 914 | ||
| 920 | 915 | static int bbr_is_reno_coexistence_probe_time(ngtcp2_cc_bbr *bbr, | |
@@ -1388,8 +1383,7 @@ static void bbr_cc_reset(ngtcp2_cc *cc, ngtcp2_conn_stat *cstat, | |||
| 1388 | 1383 | ||
| 1389 | 1384 | void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log, | |
| 1390 | 1385 | ngtcp2_conn_stat *cstat, ngtcp2_rst *rst, | |
| 1391 | - ngtcp2_tstamp initial_ts, ngtcp2_rand rand, | ||
| 1392 | - const ngtcp2_rand_ctx *rand_ctx) { | ||
| 1386 | + ngtcp2_tstamp initial_ts, ngtcp2_pcg32 *pcg) { | ||
| 1393 | 1387 | *bbr = (ngtcp2_cc_bbr){ | |
| 1394 | 1388 | .cc = | |
| 1395 | 1389 | { | |
@@ -1403,8 +1397,7 @@ void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log, | |||
| 1403 | 1397 | .reset = bbr_cc_reset, | |
| 1404 | 1398 | }, | |
| 1405 | 1399 | .rst = rst, | |
| 1406 | - .rand = rand, | ||
| 1407 | - .rand_ctx = *rand_ctx, | ||
| 1400 | + .pcg = pcg, | ||
| 1408 | 1401 | .initial_cwnd = cstat->cwnd, | |
| 1409 | 1402 | }; | |
| 1410 | 1403 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,7 @@ | |||
| 35 | 35 | #include "ngtcp2_window_filter.h" | |
| 36 | 36 | ||
| 37 | 37 | typedef struct ngtcp2_rst ngtcp2_rst; | |
| 38 | + typedef struct ngtcp2_pcg32 ngtcp2_pcg32; | ||
| 38 | 39 | ||
| 39 | 40 | typedef enum ngtcp2_bbr_state { | |
| 40 | 41 | NGTCP2_BBR_STATE_STARTUP, | |
@@ -62,8 +63,7 @@ typedef struct ngtcp2_cc_bbr { | |||
| 62 | 63 | ||
| 63 | 64 | uint64_t initial_cwnd; | |
| 64 | 65 | ngtcp2_rst *rst; | |
| 65 | - ngtcp2_rand rand; | ||
| 66 | - ngtcp2_rand_ctx rand_ctx; | ||
| 66 | + ngtcp2_pcg32 *pcg; | ||
| 67 | 67 | ||
| 68 | 68 | /* max_bw_filter for tracking the maximum recent delivery rate | |
| 69 | 69 | samples for estimating max_bw. */ | |
@@ -136,7 +136,6 @@ typedef struct ngtcp2_cc_bbr { | |||
| 136 | 136 | ||
| 137 | 137 | void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log, | |
| 138 | 138 | ngtcp2_conn_stat *cstat, ngtcp2_rst *rst, | |
| 139 | - ngtcp2_tstamp initial_ts, ngtcp2_rand rand, | ||
| 140 | - const ngtcp2_rand_ctx *rand_ctx); | ||
| 139 | + ngtcp2_tstamp initial_ts, ngtcp2_pcg32 *pcg); | ||
| 141 | 140 | ||
| 142 | 141 | #endif /* !defined(NGTCP2_BBR_H) */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,12 @@ size_t ngtcp2_buf_cap(const ngtcp2_buf *buf) { | |||
| 36 | 36 | return (size_t)(buf->end - buf->begin); | |
| 37 | 37 | } | |
| 38 | 38 | ||
| 39 | + void ngtcp2_buf_trunc(ngtcp2_buf *buf, size_t len) { | ||
| 40 | + if (ngtcp2_buf_len(buf) > len) { | ||
| 41 | + buf->last = buf->pos + len; | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + | ||
| 39 | 45 | int ngtcp2_buf_chain_new(ngtcp2_buf_chain **pbufchain, size_t len, | |
| 40 | 46 | const ngtcp2_mem *mem) { | |
| 41 | 47 | *pbufchain = ngtcp2_mem_malloc(mem, sizeof(ngtcp2_buf_chain) + len); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,16 +70,21 @@ static inline size_t ngtcp2_buf_left(const ngtcp2_buf *buf) { | |||
| 70 | 70 | * ngtcp2_buf_len returns the number of bytes left to read. In other | |
| 71 | 71 | * words, it returns buf->last - buf->pos. | |
| 72 | 72 | */ | |
| 73 | - static inline size_t ngtcp2_buf_len(const ngtcp2_buf *buf) { | ||
| 74 | - return (size_t)(buf->last - buf->pos); | ||
| 75 | - } | ||
| 73 | + #define ngtcp2_buf_len(BUF) (size_t)((BUF)->last - (BUF)->pos) | ||
| 76 | 74 | ||
| 77 | 75 | /* | |
| 78 | 76 | * ngtcp2_buf_cap returns the capacity of the buffer. In other words, | |
| 79 | 77 | * it returns buf->end - buf->begin. | |
| 80 | 78 | */ | |
| 81 | 79 | size_t ngtcp2_buf_cap(const ngtcp2_buf *buf); | |
| 82 | 80 | ||
| 81 | + /* | ||
| 82 | + * ngtcp2_buf_trunc truncates the number of bytes to read to at most | ||
| 83 | + * |len|. In other words, it sets buf->last = buf->pos + len if | ||
| 84 | + * ngtcp2_buf_len(buf) > len. | ||
| 85 | + */ | ||
| 86 | + void ngtcp2_buf_trunc(ngtcp2_buf *buf, size_t len); | ||
| 87 | + | ||
| 83 | 88 | /* | |
| 84 | 89 | * ngtcp2_buf_chain is a linked list of ngtcp2_buf. | |
| 85 | 90 | */ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments