void wait_for_async(SSL *s)
{
    int width = 0;
    fd_set asyncfds;
    OSSL_ASYNC_FD *fds;
    size_t numfds;

    if (!SSL_get_all_async_fds(s, NULL, &numfds))
        return;
    if (numfds == 0)
        return;
    fds = OPENSSL_malloc(sizeof(OSSL_ASYNC_FD) * numfds);
    if (!SSL_get_all_async_fds(s, fds, &numfds)) {
        OPENSSL_free(fds);
    }

    FD_ZERO(&asyncfds);
    while (numfds > 0) {
        if (width <= (int)*fds)
            width = (int)*fds + 1;
        openssl_fdset((int)*fds, &asyncfds);
        numfds--;
        fds++;
    }
    select(width, (void *)&asyncfds, NULL, NULL, NULL);
}