{
SSL_CTX *ctx;
+#ifdef USE_QUIC
+ ctx = SSL_CTX_new(QUIC_client_method());
+#else
ctx = SSL_CTX_new(TLS_client_method());
+#endif
if (ctx == NULL)
return NULL;
SSL_set_connect_state(ssl); /* cannot fail */
+#ifdef USE_QUIC
+ if (BIO_new_dgram_pair(&internal_bio, 0, &net_bio, 0) <= 0) {
+#else
if (BIO_new_bio_pair(&internal_bio, 0, &net_bio, 0) <= 0) {
+#endif
SSL_free(ssl);
free(conn);
return NULL;
/*
* Called to get data which has been enqueued for transmission to the network
- * by OpenSSL.
+ * by OpenSSL. For QUIC, this always outputs a single frame.
+ *
+ * IMPORTANT (QUIC): If buf_len is inadequate to hold the frame, it is truncated
+ * (similar to read(2)). A buffer size of at least 1472 must be used by default
+ * to guarantee this does not occur.
*/
int read_net_tx(APP_CONN *conn, void *buf, int buf_len)
{
/*
* Called to feed data which has been received from the network to OpenSSL.
+ *
+ * QUIC: buf must contain the entirety of a single frame. It will be consumed
+ * entirely (return value == buf_len) or not at all.
*/
int write_net_rx(APP_CONN *conn, const void *buf, int buf_len)
{
*/
int get_conn_pending_tx(APP_CONN *conn)
{
+#ifdef USE_QUIC
+ return POLLIN | POLLOUT | POLLERR;
+#else
return (conn->tx_need_rx ? POLLIN : 0) | POLLOUT | POLLERR;
+#endif
}
int get_conn_pending_rx(APP_CONN *conn)
static int pump(APP_CONN *conn, int fd, int events, int timeout)
{
int l, l2;
- char buf[2048];
+ char buf[2048]; /* QUIC: would need to be changed if < 1472 */
size_t wspace;
struct pollfd pfd = {0};
signal(SIGPIPE, SIG_IGN);
+#ifdef USE_QUIC
+ fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+#else
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+#endif
if (fd < 0) {
fprintf(stderr, "cannot create socket\n");
goto fail;