Exemple #1
0
void h2o_socket__read_on_ready(h2o_socket_t *sock)
{
    int status = 0;

    if ((sock->_flags & H2O_SOCKET_FLAG_IS_ACCEPT) != 0)
        goto Notify;

    if (sock->ssl == NULL || sock->ssl->handshake.cb != NULL) {
        status = on_read_core(sock->fd, &sock->input);
    } else {
        while (1) {
            h2o_buf_t buf = h2o_allocate_input_buffer(&sock->input, 8192);
            int rlen = SSL_read(sock->ssl->ssl, buf.base, (int)buf.len);
            if (rlen == -1) {
                if (SSL_get_error(sock->ssl->ssl, rlen) != SSL_ERROR_WANT_READ) {
                    status = -1;
                }
                break;
            } else if (rlen == 0) {
                break;
            } else {
                sock->input->size += rlen;
            }
        }
    }

Notify:
    sock->_cb.read(sock, status);
}
Exemple #2
0
int decode_ssl_input(h2o_socket_t *sock)
{
    assert(sock->ssl != NULL);
    assert(sock->ssl->handshake.cb == NULL);

    while (1) {
        h2o_buf_t buf = h2o_allocate_input_buffer(&sock->input, 8192);
        int rlen = SSL_read(sock->ssl->ssl, buf.base, (int)buf.len);
        if (rlen == -1) {
            if (SSL_get_error(sock->ssl->ssl, rlen) != SSL_ERROR_WANT_READ) {
                return -1;
            }
            break;
        } else if (rlen == 0) {
            break;
        } else {
            sock->input->size += rlen;
        }
    }

    return 0;
}
Exemple #3
0
static int on_read_core(int fd, h2o_input_buffer_t** input)
{
    int read_any = 0;

    while (1) {
        h2o_buf_t buf = h2o_allocate_input_buffer(input, 8192);
        ssize_t rret;
        while ((rret = read(fd, buf.base, buf.len)) == -1 && errno == EINTR)
            ;
        if (rret == -1) {
            if (errno == EAGAIN)
                break;
            else
                return -1;
        } else if (rret == 0) {
            if (! read_any)
                return -1; /* TODO notify close */
            break;
        }
        (*input)->size += rret;
        read_any = 1;
    }
    return 0;
}