Skip to content

Commit

Permalink
1.10.2: Don't go over limit when creating delayed streams
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitri Tikhonov committed Aug 9, 2018
1 parent 81a42a8 commit c6457e4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2018-08-09

- 1.10.2
- [BUGFIX] Don't go over limit when creating delayed streams

2018-07-10

- 1.10.1
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ to the LiteSpeed Client Library:
- Amol Desphande -- Windows support
- Alexis La Goutte -- Travis-CI integration
- Bernhard Jaeger -- DNS Resolution
- Zhang Chi -- libevent build fix on Darwin

Thank you!

Expand Down
7 changes: 6 additions & 1 deletion include/lsquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C" {

#define LSQUIC_MAJOR_VERSION 1
#define LSQUIC_MINOR_VERSION 10
#define LSQUIC_PATCH_VERSION 1
#define LSQUIC_PATCH_VERSION 2

/**
* Engine flags:
Expand Down Expand Up @@ -110,6 +110,11 @@ enum lsquic_version

#define LSQUIC_DEPRECATED_VERSIONS 0

/**
* List of version in which the server does not include CID in short packets.
*/
#define LSQUIC_FORCED_TCID0_VERSIONS 0

/**
* @struct lsquic_stream_if
* @brief The definition of callback functions call by lsquic_stream to
Expand Down
63 changes: 47 additions & 16 deletions src/liblsquic/lsquic_full_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2348,12 +2348,52 @@ packetize_standalone_stream_resets (struct full_conn *conn)
}


static void
create_delayed_streams (struct full_conn *conn)
{
unsigned stream_count, avail, i;

stream_count = count_streams(conn, 0);

if (stream_count >= conn->fc_cfg.max_streams_out)
return;

avail = conn->fc_cfg.max_streams_out - stream_count;
if (conn->fc_n_delayed_streams < avail)
avail = conn->fc_n_delayed_streams;

struct lsquic_stream *new_streams[ avail ];

LSQ_DEBUG("creating delayed streams");
for (i = 0; i < avail; ++i)
{
/* Delay calling on_new in order not to let the user screw up
* the counts by making more streams.
*/
new_streams[i] = new_stream(conn, generate_stream_id(conn), 0);
if (!new_streams[i])
{
ABORT_ERROR("%s: cannot create new stream: %s", __func__,
strerror(errno));
return;
}
}
LSQ_DEBUG("created %u delayed stream%.*s", avail, avail != 1, "s");

assert(count_streams(conn, 0) <= conn->fc_cfg.max_streams_out);
conn->fc_n_delayed_streams -= avail;

for (i = 0; i < avail; ++i)
lsquic_stream_call_on_new(new_streams[i]);
}


static void
service_streams (struct full_conn *conn)
{
struct lsquic_hash_elem *el;
lsquic_stream_t *stream, *next;
int n_our_destroyed = 0;
int closed_some = 0;

for (stream = TAILQ_FIRST(&conn->fc_pub.service_streams); stream; stream = next)
{
Expand All @@ -2364,15 +2404,17 @@ service_streams (struct full_conn *conn)
*/
ABORT_ERROR("aborted due to error in stream %"PRIu32, stream->id);
if (stream->stream_flags & STREAM_CALL_ONCLOSE)
{
lsquic_stream_call_on_close(stream);
closed_some |= is_our_stream(conn, stream);
conn_mark_stream_closed(conn, stream->id);
}
if (stream->stream_flags & STREAM_FREE_STREAM)
{
n_our_destroyed += is_our_stream(conn, stream);
TAILQ_REMOVE(&conn->fc_pub.service_streams, stream, next_service_stream);
el = lsquic_hash_find(conn->fc_pub.all_streams, &stream->id, sizeof(stream->id));
if (el)
lsquic_hash_erase(conn->fc_pub.all_streams, el);
conn_mark_stream_closed(conn, stream->id);
SAVE_STREAM_HISTORY(conn, stream);
lsquic_stream_destroy(stream);
}
Expand All @@ -2387,19 +2429,8 @@ service_streams (struct full_conn *conn)
conn->fc_stream_ifs[STREAM_IF_STD].stream_if_ctx, NULL);
}
else
while (n_our_destroyed && conn->fc_n_delayed_streams)
{
--n_our_destroyed;
--conn->fc_n_delayed_streams;
LSQ_DEBUG("creating delayed stream");
if (!new_stream(conn, generate_stream_id(conn), SCF_CALL_ON_NEW))
{
ABORT_ERROR("%s: cannot create new stream: %s", __func__,
strerror(errno));
break;
}
assert(count_streams(conn, 0) <= conn->fc_cfg.max_streams_out);
}
if (closed_some && conn->fc_n_delayed_streams)
create_delayed_streams(conn);
}


Expand Down

0 comments on commit c6457e4

Please sign in to comment.