Skip to content

Commit

Permalink
QUIC DDD: ddd-04-fd-nonblocking: Unplanned changes
Browse files Browse the repository at this point in the history
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #21715)
  • Loading branch information
hlandau committed Sep 1, 2023
1 parent b3e71db commit 92db6d6
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions doc/designs/ddd/ddd-04-fd-nonblocking.c
Expand Up @@ -28,7 +28,7 @@ SSL_CTX *create_ssl_ctx(void)
SSL_CTX *ctx;

#ifdef USE_QUIC
ctx = SSL_CTX_new(QUIC_client_method());
ctx = SSL_CTX_new(OSSL_QUIC_client_method());
#else
ctx = SSL_CTX_new(TLS_client_method());
#endif
Expand Down Expand Up @@ -57,6 +57,9 @@ APP_CONN *new_conn(SSL_CTX *ctx, int fd, const char *bare_hostname)
{
APP_CONN *conn;
SSL *ssl;
#ifdef USE_QUIC
static const unsigned char alpn[] = {5, 'd', 'u', 'm', 'm', 'y'};
#endif

conn = calloc(1, sizeof(APP_CONN));
if (conn == NULL)
Expand Down Expand Up @@ -88,6 +91,16 @@ APP_CONN *new_conn(SSL_CTX *ctx, int fd, const char *bare_hostname)
return NULL;
}

#ifdef USE_QUIC
/* Configure ALPN, which is required for QUIC. */
if (SSL_set_alpn_protos(ssl, alpn, sizeof(alpn))) {
/* Note: SSL_set_alpn_protos returns 1 for failure. */
SSL_free(ssl);
free(conn);
return NULL;
}
#endif

conn->fd = fd;
return conn;
}
Expand Down Expand Up @@ -185,15 +198,17 @@ int get_conn_fd(APP_CONN *conn)
int get_conn_pending_tx(APP_CONN *conn)
{
#ifdef USE_QUIC
return POLLIN | POLLOUT | POLLERR;
return (SSL_net_read_desired(conn->ssl) ? POLLIN : 0)
| (SSL_net_write_desired(conn->ssl) ? POLLOUT : 0)
| POLLERR;
#else
return (conn->tx_need_rx ? POLLIN : 0) | POLLOUT | POLLERR;
#endif
}

int get_conn_pending_rx(APP_CONN *conn)
{
return (conn->rx_need_tx ? POLLOUT : 0) | POLLIN | POLLERR;
return get_conn_pending_tx(conn);
}

#ifdef USE_QUIC
Expand All @@ -203,9 +218,17 @@ int get_conn_pending_rx(APP_CONN *conn)
* no need for such a call. This may change after the next call
* to libssl.
*/
static inline int timeval_to_ms(const struct timeval *t);

int get_conn_pump_timeout(APP_CONN *conn)
{
return SSL_get_timeout(conn->ssl);
struct timeval tv;
int is_infinite;

if (!SSL_get_event_timeout(conn->ssl, &tv, &is_infinite))
return -1;

return is_infinite ? -1 : timeval_to_ms(&tv);
}

/*
Expand All @@ -214,7 +237,7 @@ int get_conn_pump_timeout(APP_CONN *conn)
*/
void pump(APP_CONN *conn)
{
SSL_pump(conn->ssl);
SSL_handle_events(conn->ssl);
}
#endif

Expand Down

0 comments on commit 92db6d6

Please sign in to comment.