Menu

#360 evhttp have some problems in iocp background

For_2.1
open
nobody
None
5
2015-06-22
2015-06-22
zhouYiWei
No

In sample http-server.c in libevent-2.1.5-beta,I add some code to enable the iocp background,then the problem arise.The source code was below.
Problem:
it only accept the conncet,but the user callbake(dump_request_cb,send_document_cb) isn't be invoked

I think:
It is because the bev_a->ok not set to 1

Speculations:
1. method evhttp_get_request_connection call the evhttp_connection_base_bufferevent_new to new a bufferevent with argument fd=-1.it make the bev_a->ok to 0.
2. after that,bufferevent_setfd is invoked,there is some problem in there.This method invoke the be_async_ctrl with argument op=BEV_CTRL_SET_FD.In the case BEV_CTRL_SET_FD,the data->fd ,which has already associate with IOCP and connected,is pass to event_iocp_port_associate_ again,which make this method return -1
3. after that, evhttp_start_read_ is invoked,but the bev_a->ok is 0 so that it only set the flag but not really launch the async read

What i try:
I modify the code in the case BEV_CTRL_SET_FD in method be_async_ctrl as below:
case BEV_CTRL_SET_FD: {
struct event_iocp_port *iocp;

        if (data->fd == evbuffer_overlapped_get_fd_(bev->input))
            return 0;
        if (!(iocp = event_base_get_iocp_(bev->ev_base)))
            return -1;
        if (event_iocp_port_associate_(iocp, data->fd, 1) < 0)
        {
            int err = GetLastError();
            /* We may have alrady associated this fd with a port.
            * Let's hope it's this port, and that the error code
            * for doing this neer changes. */
            if (err != ERROR_INVALID_PARAMETER)
                return -1;
        }
        evbuffer_overlapped_set_fd_(bev->input, data->fd);
        evbuffer_overlapped_set_fd_(bev->output, data->fd);
        struct bufferevent_async *bev_async = upcast(bev);
        bev_async->ok = 1;
        return 0;

}
Result: it works,the user callback can be invoke

1 Attachments

Discussion


Log in to post a comment.