| 1559 | } |
| 1560 | |
| 1561 | apr_status_t h2_proxy_session_process(h2_proxy_session *session) |
| 1562 | { |
| 1563 | apr_status_t status; |
| 1564 | int have_written = 0, have_read = 0; |
| 1565 | |
| 1566 | ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c, |
| 1567 | "h2_proxy_session(%s): process", session->id); |
| 1568 | |
| 1569 | run_loop: |
| 1570 | switch (session->state) { |
| 1571 | case H2_PROXYS_ST_INIT: |
| 1572 | status = session_start(session); |
| 1573 | if (status == APR_SUCCESS) { |
| 1574 | dispatch_event(session, H2_PROXYS_EV_INIT, 0, NULL); |
| 1575 | goto run_loop; |
| 1576 | } |
| 1577 | else { |
| 1578 | dispatch_event(session, H2_PROXYS_EV_CONN_ERROR, status, NULL); |
| 1579 | } |
| 1580 | break; |
| 1581 | |
| 1582 | case H2_PROXYS_ST_BUSY: |
| 1583 | case H2_PROXYS_ST_LOCAL_SHUTDOWN: |
| 1584 | case H2_PROXYS_ST_REMOTE_SHUTDOWN: |
| 1585 | have_written = send_loop(session); |
| 1586 | |
| 1587 | if (nghttp2_session_want_read(session->ngh2)) { |
| 1588 | status = h2_proxy_session_read(session, 0, 0); |
| 1589 | if (status == APR_SUCCESS) { |
| 1590 | have_read = 1; |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | if (!have_written && !have_read |
| 1595 | && !nghttp2_session_want_write(session->ngh2)) { |
| 1596 | dispatch_event(session, H2_PROXYS_EV_NO_IO, 0, NULL); |
| 1597 | goto run_loop; |
| 1598 | } |
| 1599 | break; |
| 1600 | |
| 1601 | case H2_PROXYS_ST_WAIT: |
| 1602 | if (is_waiting_for_backend(session)) { |
| 1603 | /* we can do a blocking read with the default timeout (as |
| 1604 | * configured via ProxyTimeout in our socket. There is |
| 1605 | * nothing we want to send or check until we get more data |
| 1606 | * from the backend. */ |
| 1607 | status = h2_proxy_session_read(session, 1, 0); |
| 1608 | if (status == APR_SUCCESS) { |
| 1609 | have_read = 1; |
| 1610 | dispatch_event(session, H2_PROXYS_EV_DATA_READ, 0, NULL); |
| 1611 | } |
| 1612 | else { |
| 1613 | dispatch_event(session, H2_PROXYS_EV_CONN_ERROR, status, NULL); |
| 1614 | return status; |
| 1615 | } |
| 1616 | } |
| 1617 | else if (check_suspended(session) == APR_EAGAIN) { |
| 1618 | /* no stream has become resumed. Do a blocking read with |
no test coverage detected