static apr_status_t event_register_socket_callback(apr_socket_t **s, 
                                                  apr_pool_t *p, 
                                                  int for_read,
                                                  ap_mpm_callback_fn_t *cbfn,
                                                  void *baton)
{
    apr_status_t rc, final_rc= APR_SUCCESS;
    int i = 0, nsock;
    socket_callback_baton_t *scb = apr_pcalloc(p, sizeof(*scb));
    listener_poll_type *pt = apr_palloc(p, sizeof(*pt));
    apr_pollfd_t **pfds = NULL;

    while(s[i] != NULL) { 
        i++; 
    }
    nsock = i;
    pfds = apr_palloc(p, nsock * sizeof(apr_pollfd_t*));

    pt->type = PT_USER;
    pt->baton = scb;

    scb->cbfunc = cbfn;
    scb->user_baton = baton;
    scb->nsock = nsock;
    scb->pfds = pfds;

    for (i = 0; i<nsock; i++) { 
        pfds[i] = apr_palloc(p, sizeof(apr_pollfd_t));
        pfds[i]->desc_type = APR_POLL_SOCKET;
        pfds[i]->reqevents = (for_read ? APR_POLLIN : APR_POLLOUT) | APR_POLLERR | APR_POLLHUP;
        pfds[i]->desc.s = s[i];
        pfds[i]->client_data = pt;
        rc = apr_pollset_add(event_pollset, pfds[i]);
        if (rc != APR_SUCCESS) final_rc = rc;
    }
    return final_rc;
}