static apr_status_t proxy_wstunnel_transfer(request_rec *r, conn_rec *c_i, conn_rec *c_o,
apr_bucket_brigade *bb, char *name);
-static void proxy_wstunnel_callback(void *b, const apr_pollfd_t *pfd);
+static void proxy_wstunnel_callback(void *b);
-static apr_status_t proxy_wstunnel_pump2(ws_baton_t *baton, const apr_pollfd_t *pfd){
+static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_async) {
request_rec *r = baton->r;
conn_rec *c = r->connection;
proxy_conn_rec *conn = baton->proxy_connrec;
apr_socket_t *sock = conn->sock;
conn_rec *backconn = conn->connection;
- apr_int16_t pollevent;
- apr_socket_t *client_socket = baton->client_soc;
- apr_bucket_brigade *bb = baton->bb;
-
- if (pfd->desc.s == sock) {
- pollevent = pfd->rtnevents;
- if (pollevent & (APR_POLLIN | APR_POLLHUP)) {
- ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02446)
- "sock was readable");
- return proxy_wstunnel_transfer(r, backconn, c, bb, "sock");
- }
- else if (pollevent & APR_POLLERR) {
- ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(02447)
- "error on backconn");
- return APR_EPIPE;
- }
- else {
- ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(02605)
- "unknown event on backconn %d", pollevent);
- return APR_EGENERAL;
- }
- }
- else if (pfd->desc.s == client_socket) {
- pollevent = pfd->rtnevents;
- if (pollevent & (APR_POLLIN | APR_POLLHUP)) {
- ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02448)
- "client was readable");
- return proxy_wstunnel_transfer(r, c, backconn, bb, "client");
- }
- else if (pollevent & APR_POLLERR) {
- ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02607)
- "error on client conn");
- c->aborted = 1;
- return APR_EPIPE;
- }
- else {
- ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(02606)
- "unknown event on client conn %d", pollevent);
- return APR_EGENERAL;
- }
- }
- else {
- ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(02449)
- "unknown socket in pollset");
- return APR_EBADF;
- }
-}
-
-static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_async) {
- request_rec *r = baton->r;
const apr_pollfd_t *signalled;
apr_int32_t pollcnt, pi;
+ apr_int16_t pollevent;
apr_pollset_t *pollset = baton->pollset;
+ apr_socket_t *client_socket = baton->client_soc;
apr_status_t rv;
+ apr_bucket_brigade *bb = baton->bb;
while(1) {
if ((rv = apr_pollset_poll(pollset, timeout, &pollcnt, &signalled))
"woke from poll(), i=%d", pollcnt);
for (pi = 0; pi < pollcnt; pi++) {
- rv = proxy_wstunnel_pump2(baton, &signalled[pi]);
+ const apr_pollfd_t *cur = &signalled[pi];
+
+ if (cur->desc.s == sock) {
+ pollevent = cur->rtnevents;
+ if (pollevent & (APR_POLLIN | APR_POLLHUP)) {
+ ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02446)
+ "sock was readable");
+ rv = proxy_wstunnel_transfer(r, backconn, c, bb, "sock");
+ }
+ else if (pollevent & APR_POLLERR) {
+ rv = APR_EPIPE;
+ ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(02447)
+ "error on backconn");
+ }
+ else {
+ rv = APR_EGENERAL;
+ ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(02605)
+ "unknown event on backconn %d", pollevent);
+ }
+ }
+ else if (cur->desc.s == client_socket) {
+ pollevent = cur->rtnevents;
+ if (pollevent & (APR_POLLIN | APR_POLLHUP)) {
+ ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02448)
+ "client was readable");
+ rv = proxy_wstunnel_transfer(r, c, backconn, bb, "client");
+ }
+ else if (pollevent & APR_POLLERR) {
+ rv = APR_EPIPE;
+ c->aborted = 1;
+ ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02607)
+ "error on client conn");
+ }
+ else {
+ rv = APR_EGENERAL;
+ ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(02606)
+ "unknown event on client conn %d", pollevent);
+ }
+ }
+ else {
+ rv = APR_EBADF;
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(02449)
+ "unknown socket in pollset");
+ }
+
}
if (rv != APR_SUCCESS) {
break;
* We don't need the invoke_mtx, since we never put multiple callback events
* in the queue.
*/
-static void proxy_wstunnel_callback(void *b, const apr_pollfd_t *pfd) {
+static void proxy_wstunnel_callback(void *b) {
+ int status;
apr_socket_t *sockets[3] = {NULL, NULL, NULL};
ws_baton_t *baton = (ws_baton_t*)b;
proxyws_dir_conf *dconf = ap_get_module_config(baton->r->per_dir_config, &proxy_wstunnel_module);
apr_pool_clear(baton->subpool);
- if (proxy_wstunnel_pump2(baton, pfd) == APR_SUCCESS) {
+ status = proxy_wstunnel_pump(baton, dconf->async_delay, dconf->is_async);
+ if (status == SUSPENDED) {
sockets[0] = baton->client_soc;
sockets[1] = baton->server_soc;
ap_mpm_register_socket_callback_timeout(sockets, baton->subpool, 1,
typedef struct
{
- ap_mpm_socket_callback_fn_t *cbfunc;
+ ap_mpm_callback_fn_t *cbfunc;
void *user_baton;
apr_pollfd_t **pfds;
int nsock;
static apr_status_t event_register_socket_callback_ex(apr_socket_t **s,
apr_pool_t *p,
int for_read,
- ap_mpm_socket_callback_fn_t *cbfn,
+ ap_mpm_callback_fn_t *cbfn,
ap_mpm_callback_fn_t *tofn,
void *baton,
apr_time_t timeout)
static apr_status_t event_register_socket_callback(apr_socket_t **s,
apr_pool_t *p,
int for_read,
- ap_mpm_socket_callback_fn_t *cbfn,
+ ap_mpm_callback_fn_t *cbfn,
void *baton)
{
return event_register_socket_callback_ex(s, p, for_read,
apr_thread_mutex_lock(timeout_mutex);
}
-static void socket_callback_wrapper(void *baton){
- const apr_pollfd_t *out_pfd = (const apr_pollfd_t *)baton;
- socket_callback_baton_t *scb_baton = (socket_callback_baton_t *) ((listener_poll_type *) out_pfd->client_data)->baton;
- scb_baton->cbfunc(scb_baton->user_baton, out_pfd);
-}
-
static void * APR_THREAD_FUNC listener_thread(apr_thread_t * thd, void *dummy)
{
apr_status_t rc;
/* We only signal once per N sockets with this baton */
if (!(baton->signaled)) {
- apr_pollfd_t *newpfd = apr_palloc(out_pfd->p, sizeof(apr_pollfd_t));
baton->signaled = 1;
- *newpfd = *out_pfd;
te = event_get_timer_event(-1 /* fake timer */,
- socket_callback_wrapper,
- newpfd,
+ baton->cbfunc,
+ baton->user_baton,
0, /* don't insert it */
NULL /* no associated socket callback */);
/* remove other sockets in my set */
(conn_rec *c),
(c), APR_ENOTIMPL)
AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, mpm_register_socket_callback,
- (apr_socket_t **s, apr_pool_t *p, int for_read, ap_mpm_socket_callback_fn_t *cbfn, void *baton),
+ (apr_socket_t **s, apr_pool_t *p, int for_read, ap_mpm_callback_fn_t *cbfn, void *baton),
(s, p, for_read, cbfn, baton), APR_ENOTIMPL)
AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, mpm_register_socket_callback_timeout,
- (apr_socket_t **s, apr_pool_t *p, int for_read, ap_mpm_socket_callback_fn_t *cbfn, ap_mpm_callback_fn_t *tofn, void *baton, apr_time_t timeout),
+ (apr_socket_t **s, apr_pool_t *p, int for_read, ap_mpm_callback_fn_t *cbfn, ap_mpm_callback_fn_t *tofn, void *baton, apr_time_t timeout),
(s, p, for_read, cbfn, tofn, baton, timeout), APR_ENOTIMPL)
AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, mpm_unregister_socket_callback,
(apr_socket_t **s, apr_pool_t *p),
{
return ap_run_mpm_register_timed_callback(t, cbfn, baton);
}
-AP_DECLARE(apr_status_t) ap_mpm_register_socket_callback(apr_socket_t **s, apr_pool_t *p, int for_read, ap_mpm_socket_callback_fn_t *cbfn, void *baton)
+AP_DECLARE(apr_status_t) ap_mpm_register_socket_callback(apr_socket_t **s, apr_pool_t *p, int for_read, ap_mpm_callback_fn_t *cbfn, void *baton)
{
return ap_run_mpm_register_socket_callback(s, p, for_read, cbfn, baton);
}
AP_DECLARE(apr_status_t) ap_mpm_register_socket_callback_timeout(apr_socket_t **s,
apr_pool_t *p,
int for_read,
- ap_mpm_socket_callback_fn_t *cbfn,
+ ap_mpm_callback_fn_t *cbfn,
ap_mpm_callback_fn_t *tofn,
void *baton,
apr_time_t timeout)