Skip to content

Commit

Permalink
QUIC APL: Support blocking connection acceptance
Browse files Browse the repository at this point in the history
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #24037)
  • Loading branch information
hlandau committed Apr 19, 2024
1 parent a0fbdcc commit bb69157
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/internal/quic_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ QUIC_CHANNEL *ossl_quic_port_create_incoming(QUIC_PORT *port, SSL *tls);
*/
QUIC_CHANNEL *ossl_quic_port_pop_incoming(QUIC_PORT *port);

/* Returns 1 if there is at least one connection incoming. */
int ossl_quic_port_have_incoming(QUIC_PORT *port);

/*
* Delete any channels which are pending acceptance.
*/
Expand Down
37 changes: 33 additions & 4 deletions ssl/quic/quic_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4200,12 +4200,27 @@ int ossl_quic_listen(SSL *ssl)
* SSL_accept_connection
* ---------------------
*/
static int quic_accept_connection_wait(void *arg)
{
QUIC_PORT *port = arg;

if (!ossl_quic_port_is_running(port))
return -1;

if (ossl_quic_port_have_incoming(port))
return 1;

return 0;
}

QUIC_TAKES_LOCK
SSL *ossl_quic_accept_connection(SSL *ssl, uint64_t flags)
{
int ret;
QCTX ctx;
QUIC_CONNECTION *qc = NULL;
QUIC_CHANNEL *new_ch = NULL;
int no_block = ((flags & SSL_ACCEPT_CONNECTION_NO_BLOCK) != 0);

if (!expect_quic_listener(ssl, &ctx))
return NULL;
Expand All @@ -4215,11 +4230,25 @@ SSL *ossl_quic_accept_connection(SSL *ssl, uint64_t flags)
if (!ql_listen(ctx.ql))
goto out;

/* TODO(QUIC SERVER): Autotick */
/* TODO(QUIC SERVER): Implement blocking and SSL_ACCEPT_CONNECTION_NO_BLOCK */

/* Wait for an incoming connection if needed. */
new_ch = ossl_quic_port_pop_incoming(ctx.ql->port);
if (new_ch == NULL) {
if (new_ch == NULL && ossl_quic_port_is_running(ctx.ql->port)) {
if (!no_block && qctx_blocking(&ctx)) {
ret = block_until_pred(&ctx, quic_accept_connection_wait,
ctx.ql->port, 0);
if (ret < 1)
goto out;
} else {
qctx_maybe_autotick(&ctx);
}

if (!ossl_quic_port_is_running(ctx.ql->port))
goto out;

new_ch = ossl_quic_port_pop_incoming(ctx.ql->port);
}

if (new_ch == NULL && ossl_quic_port_is_running(ctx.ql->port)) {
/* No connections already queued. */
ossl_quic_reactor_tick(ossl_quic_engine_get0_reactor(ctx.ql->engine), 0);

Expand Down
5 changes: 5 additions & 0 deletions ssl/quic/quic_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@ QUIC_CHANNEL *ossl_quic_port_pop_incoming(QUIC_PORT *port)
return ch;
}

int ossl_quic_port_have_incoming(QUIC_PORT *port)
{
return ossl_list_incoming_ch_head(&port->incoming_channel_list) != NULL;
}

void ossl_quic_port_drop_incoming(QUIC_PORT *port)
{
QUIC_CHANNEL *ch;
Expand Down

0 comments on commit bb69157

Please sign in to comment.