holepunchto / libudx

udx is reliable, multiplexed, and congestion-controlled streams over udp
MIT License
63 stars 16 forks source link

Feature/combined writes with writev #177

Closed jthomas43 closed 5 months ago

jthomas43 commented 6 months ago

this PR supports

  1. combining multiple adjacent writes into a single packet and
  2. passing a vector of writes to udx_stream_write instead of a single write at a time.

Details

  1. introduces a write-buf udx_stream_write_buf_t in between the udx_stream_write_t and the packet buffers in udx_packet_t. a write may be split into 1 or more wbufs, and a single packet may carry multiple whole or fragmented wbufs.
  2. the udx_packet_t used to have a hardcoded space for 3 uv_buf_t buffers, now there is an implicit uv_buf_t buf[pkt->nbufs] allocated after the packet. Furthermore stream packets have an array of wbuf's after the array of payload buffers. There may be a better way to do this.
  3. returns to measuring cwnd in npackets instead of nbytes. measuring in bytes was a performance optimization to prevent two small packets from "filling" the congestion window. since adjacent writes will now be combined into a single packet this extra complexity is no longer necessary.
  4. finally it also sets remote_acked == seq when setting the (initial?) seq value with stream_set_seq which prevents a bug due to sequence wrap-around when a high sequence number is set.