Latest changes

- [API Change] Sendfile-like functionality is gone.  The stream no
  longer opens files and deals with file descriptors.  (Among other
  things, this makes the code more portable.)  Three writing functions
  are provided:

    lsquic_stream_write
    lsquic_stream_writev
    lsquic_stream_writef    (NEW)

  lsquic_stream_writef() is given an abstract reader that has function
  pointers for size() and read() functions which the user can implement.
  This is the most flexible way.  lsquic_stream_write() and
  lsquic_stream_writev() are now both implemented as wrappers around
  lsquic_stream_writef().

- [OPTIMIZATION] When writing to stream, be it within or without the
  on_write() callback, place data directly into packet buffer,
  bypassing auxiliary data structures.  This reduces amount of memory
  required, for the amount of data that can be written is limited
  by the congestion window.

  To support writes outside the on_write() callback, we keep N
  outgoing packet buffers per connection which can be written to
  by any stream.  One half of these are reserved for the highest
  priority stream(s), the other half for all other streams.  This way,
  low-priority streams cannot write instead of high-priority streams
  and, on the other hand, low-priority streams get a chance to send
  their packets out.

  The algorithm is as follows:

  - When user writes to stream outside of the callback:
    - If this is the highest priority stream, place it onto the
      reserved N/2 queue or fail.
        (The actual size of this queue is dynamic -- MAX(N/2, CWND) --
         rather than N/2, allowing high-priority streams to write as
         much as can be sent.)
    - If the stream is not the highest priority, try to place the
      data onto the reserved N/2 queue or fail.
  - When tick occurs *and* more packets can be scheduled:
    - Transfer packets from the high N/2 queue to the scheduled
      queue.
    - If more scheduling is allowed:
      - Call on_write callbacks for highest-priority streams,
        placing resulting packets directly onto the scheduled queue.
    - If more scheduling is allowed:
      - Transfer packets from the low N/2 queue to the scheduled
        queue.
    - If more scheduling is allowed:
      - Call on_write callbacks for non-highest-priority streams,
        placing resulting packets directly onto the scheduled queue

  The number N is currently 20, but it could be varied based on
  resource usage.

- If stream is created due to incoming headers, make headers readable
  from on_new.

- Outgoing packets are no longer marked non-writeable to prevent placing
  more than one STREAM frame from the same stream into a single packet.
  This property is maintained via code flow and an explicit check.
  Packets for stream data are allocated using a special function.

- STREAM frame elision is cheaper, as we only perform it if a reset
  stream has outgoing packets referencing it.

- lsquic_packet_out_t is smaller, as stream_rec elements are now
  inside a union.
This commit is contained in:
Dmitri Tikhonov 2017-10-31 09:35:58 -04:00
parent 0ae3fccd17
commit c51ce3387f
94 changed files with 4769 additions and 3321 deletions

View file

@ -590,37 +590,52 @@ ssize_t lsquic_stream_readv(lsquic_stream_t *s, const struct iovec *,
int lsquic_stream_wantwrite(lsquic_stream_t *s, int is_want);
/**
* Return maximum number of bytes lsquic_stream_write() will write. This
* call is useful if you don't want to perform your own buffering.
*/
size_t lsquic_stream_write_avail (const lsquic_stream_t *s);
/**
* Write `len' bytes to the stream. Returns number of bytes written, which
* may be smaller that `len'. Use lsquic_stream_write_avail() to find out
* maximum size of `len'.
* may be smaller that `len'.
*/
ssize_t lsquic_stream_write(lsquic_stream_t *s, const void *buf, size_t len);
/**
* Returns 0 if `filename' was queued for writing, -1 on error. This
* function queues the size of the file as it was when the function was
* called. The stream will write at most this number of bytes to the
* peer. If the file grows, appended data is not used.
*/
int lsquic_stream_write_file(lsquic_stream_t *s, const char *filename);
ssize_t lsquic_stream_writev(lsquic_stream_t *s, const struct iovec *vec, int count);
/**
* Returns 0 if `fdSrc' was queued for writing, -1 on error. This
* function queues at most `size' bytes to be written. If the file shrinks,
* fewer bytes are written.
* Used as argument to @ref lsquic_stream_writef()
*/
int lsquic_stream_sendfile(lsquic_stream_t *s, int fdSrc, off_t off, size_t size);
struct lsquic_reader
{
/**
* Not a ssize_t because the read function is not supposed to return
* an error. If an error occurs in the read function (for example, when
* reading from a file fails), it is supposed to deal with the error
* itself.
*/
size_t (*lsqr_read) (void *lsqr_ctx, void *buf, size_t count);
/**
* Return number of bytes remaining in the reader.
*/
size_t (*lsqr_size) (void *lsqr_ctx);
void *lsqr_ctx;
};
int lsquic_stream_flush(lsquic_stream_t *s);
/**
* Write to stream using @ref lsquic_reader. This is the most generic of
* the write functions -- @ref lsquic_stream_write() and
* @ref lsquic_stream_writev() utilize the same mechanism.
*
* @retval Number of bytes written or -1 on error.
*/
ssize_t
lsquic_stream_writef (lsquic_stream_t *, struct lsquic_reader *);
/**
* Flush any buffered data. This triggers packetizing even a single byte
* into a separate frame. Flushing a closed stream is an error.
*
* @retval 0 Success
* @retval -1 Failure
*/
int
lsquic_stream_flush (lsquic_stream_t *s);
/**
* @typedef lsquic_http_header_t