示例#1
0
void api_stream_processor(api_stream_t* stream, int events)
{
    api_task_t* task = 0;

    if (events == -1)
    {
        stream->status.terminated = 1;
        stream->filter_head->on_terminate(stream->filter_head);
    }
    else
    if (events & EPOLLERR)
    {
        stream->status.error = api_error_translate(errno);
        stream->filter_head->on_error(stream->filter_head, 
                                        stream->status.error);
    }
    else if (events & EPOLLHUP)
    {
        stream->status.closed = 1;
        stream->filter_head->on_closed(stream->filter_head);
    }
    else if (events & EPOLLRDHUP)
    {
        stream->status.peer_closed = 1;
        stream->filter_head->on_peerclosed(stream->filter_head);
    }
    else
    {
        if ((events & EPOLLIN) || (events & EPOLLPRI))
        {
            api_stream_read_try(stream);
            task = ((api_stream_read_t*)stream->os_linux.reserved[0])->task;
        }
        else
        if (events & EPOLLOUT)
        {
            api_stream_write_try(stream);
            task = ((api_stream_write_t*)stream->os_linux.reserved[1])->task;
        }
        else
        {
            stream->status.error = api_error_translate(errno);
            stream->filter_head->on_error(stream->filter_head,
                                    stream->status.error);
        }
    }

    if (task == 0 && stream->os_linux.reserved[0] != 0)
        task = ((api_stream_read_t*)stream->os_linux.reserved[0])->task;

    if (task == 0 && stream->os_linux.reserved[1] != 0)
        task = ((api_stream_write_t*)stream->os_linux.reserved[1])->task;

    if (task != 0)
        api_task_wakeup(task);
}
示例#2
0
void api_tcp_connect_processor(void* e, DWORD transferred,
                            OVERLAPPED* overlapped, struct api_loop_t* loop)
{
    api_stream_t* stream = 
        (api_stream_t*)((char*)e - offsetof(api_stream_t, os_win));

    api_task_t* task = (api_task_t*)stream->os_win.reserved[0];

    api_task_wakeup(task);
}
示例#3
0
void api_tcp_listener_processor(void* e, DWORD transferred,
                            OVERLAPPED* overlapped, struct api_loop_t* loop)
{
    api_tcp_listener_t* listener = 
        (api_tcp_listener_t*)((char*)e - offsetof(api_tcp_listener_t, os_win));
    
    api_tcp_listener_accept_t* req = 
        (api_tcp_listener_accept_t*)listener->os_win.reserved;

    api_task_wakeup(req->task);
}
示例#4
0
void api_tcp_listener_processor(struct api_tcp_listener_t* listener,
                                int events)
{
    int error;
    int wakeup = 1;
    api_task_t* task = 0;

    if (events == -1)
    {
        listener->status.terminated = 1;
        listener->on_terminate(listener);
    }
    else
    if (events & EPOLLERR)
    {
        listener->status.error = api_error_translate(errno);
        listener->on_error(listener, listener->status.error);
    }
    else if (events & EPOLLHUP)
    {
        listener->status.closed = 1;
        listener->on_closed(listener);
    }
    else
    {
        if ((events & EPOLLIN) || (events & EPOLLPRI))
        {
            wakeup = api_tcp_listener_accept_try(listener);
        }
        else
        {
            listener->status.error = api_error_translate(errno);
            listener->on_error(listener, listener->status.error);
        }
    }

    if (wakeup)
    {
        if (listener->os_linux.reserved != 0)
            task = 
            ((api_tcp_listener_accept_t*)listener->os_linux.reserved)->task;

        if (task != 0)
            api_task_wakeup(task);
    }
}
示例#5
0
void api_tcp_connect_processor(api_stream_t* stream, int events)
{
    if (events == -1)
    {
        stream->status.terminated = 1;
    }
    else
    if (events & EPOLLERR)
    {
        stream->status.error = api_error_translate(errno);
    }
    else if (events & EPOLLHUP)
    {
        stream->status.closed = 1;
    }
    else if ((events & EPOLLOUT) != EPOLLOUT)
    {
        stream->status.error = api_error_translate(errno);
    }

    api_task_wakeup((api_task_t*)stream->os_linux.reserved[0]);
}
示例#6
0
void api_async_exec_completed_handler(struct api_async_t* async)
{
    api_exec_t* exec = (api_exec_t*)async;

    api_task_wakeup(exec->task);
}
示例#7
0
void api_async_wakeup_handler(struct api_async_t* async)
{
    api_task_wakeup((api_task_t*)async->arg);
}