void aio_set_fd_handler(AioContext *ctx,

                        int fd,

                        IOHandler *io_read,

                        IOHandler *io_write,

                        void *opaque)

{

    /* fd is a SOCKET in our case */

    AioHandler *node;



    QLIST_FOREACH(node, &ctx->aio_handlers, node) {

        if (node->pfd.fd == fd && !node->deleted) {

            break;

        }

    }



    /* Are we deleting the fd handler? */

    if (!io_read && !io_write) {

        if (node) {

            /* If the lock is held, just mark the node as deleted */

            if (ctx->walking_handlers) {

                node->deleted = 1;

                node->pfd.revents = 0;

            } else {

                /* Otherwise, delete it for real.  We can't just mark it as

                 * deleted because deleted nodes are only cleaned up after

                 * releasing the walking_handlers lock.

                 */

                QLIST_REMOVE(node, node);

                g_free(node);

            }

        }

    } else {

        HANDLE event;



        if (node == NULL) {

            /* Alloc and insert if it's not already there */

            node = g_malloc0(sizeof(AioHandler));

            node->pfd.fd = fd;

            QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);

        }



        node->pfd.events = 0;

        if (node->io_read) {

            node->pfd.events |= G_IO_IN;

        }

        if (node->io_write) {

            node->pfd.events |= G_IO_OUT;

        }



        node->e = &ctx->notifier;



        /* Update handler with latest information */

        node->opaque = opaque;

        node->io_read = io_read;

        node->io_write = io_write;



        event = event_notifier_get_handle(&ctx->notifier);

        WSAEventSelect(node->pfd.fd, event,

                       FD_READ | FD_ACCEPT | FD_CLOSE |

                       FD_CONNECT | FD_WRITE | FD_OOB);

    }



    aio_notify(ctx);

}

void aio_set_fd_handler(AioContext *ctx,

                        int fd,

                        IOHandler *io_read,

                        IOHandler *io_write,

                        void *opaque)

{

    

    AioHandler *node;



    QLIST_FOREACH(node, &ctx->aio_handlers, node) {

        if (node->pfd.fd == fd && !node->deleted) {

            break;

        }

    }



    

    if (!io_read && !io_write) {

        if (node) {

            

            if (ctx->walking_handlers) {

                node->deleted = 1;

                node->pfd.revents = 0;

            } else {

                







                QLIST_REMOVE(node, node);

                g_free(node);

            }

        }

    } else {

        HANDLE event;



        if (node == NULL) {

            

            node = g_malloc0(sizeof(AioHandler));

            node->pfd.fd = fd;

            QLIST_INSERT_HEAD(&ctx->aio_handlers, node, node);

        }



        node->pfd.events = 0;

        if (node->io_read) {

            node->pfd.events |= G_IO_IN;

        }

        if (node->io_write) {

            node->pfd.events |= G_IO_OUT;

        }



        node->e = &ctx->notifier;



        

        node->opaque = opaque;

        node->io_read = io_read;

        node->io_write = io_write;



        event = event_notifier_get_handle(&ctx->notifier);

        WSAEventSelect(node->pfd.fd, event,

                       FD_READ | FD_ACCEPT | FD_CLOSE |

                       FD_CONNECT | FD_WRITE | FD_OOB);

    }



    aio_notify(ctx);

}

void FUNC_0(AioContext *VAR_0,

                        int VAR_1,

                        IOHandler *VAR_2,

                        IOHandler *VAR_3,

                        void *VAR_4)

{

    

    AioHandler *node;



    QLIST_FOREACH(node, &VAR_0->aio_handlers, node) {

        if (node->pfd.VAR_1 == VAR_1 && !node->deleted) {

            break;

        }

    }



    

    if (!VAR_2 && !VAR_3) {

        if (node) {

            

            if (VAR_0->walking_handlers) {

                node->deleted = 1;

                node->pfd.revents = 0;

            } else {

                







                QLIST_REMOVE(node, node);

                g_free(node);

            }

        }

    } else {

        HANDLE event;



        if (node == NULL) {

            

            node = g_malloc0(sizeof(AioHandler));

            node->pfd.VAR_1 = VAR_1;

            QLIST_INSERT_HEAD(&VAR_0->aio_handlers, node, node);

        }



        node->pfd.events = 0;

        if (node->VAR_2) {

            node->pfd.events |= G_IO_IN;

        }

        if (node->VAR_3) {

            node->pfd.events |= G_IO_OUT;

        }



        node->e = &VAR_0->notifier;



        

        node->VAR_4 = VAR_4;

        node->VAR_2 = VAR_2;

        node->VAR_3 = VAR_3;



        event = event_notifier_get_handle(&VAR_0->notifier);

        WSAEventSelect(node->pfd.VAR_1, event,

                       FD_READ | FD_ACCEPT | FD_CLOSE |

                       FD_CONNECT | FD_WRITE | FD_OOB);

    }



    aio_notify(VAR_0);

}

void FUNC_0(AioContext *VAR_0,
int VAR_1,
IOHandler *VAR_2,
IOHandler *VAR_3,
void *VAR_4)
{ AioHandler *node; QLIST_FOREACH(node, &VAR_0->aio_handlers, node) { if (node->pfd.VAR_1 == VAR_1 && !node->deleted) { break; } } if (!VAR_2 && !VAR_3) { if (node) { if (VAR_0->walking_handlers) { node->deleted = 1; node->pfd.revents = 0; } else { QLIST_REMOVE(node, node); g_free(node); } } } else { HANDLE event; if (node == NULL) { node = g_malloc0(sizeof(AioHandler)); node->pfd.VAR_1 = VAR_1; QLIST_INSERT_HEAD(&VAR_0->aio_handlers, node, node); } node->pfd.events = 0; if (node->VAR_2) { node->pfd.events |= G_IO_IN; } if (node->VAR_3) { node->pfd.events |= G_IO_OUT; } node->e = &VAR_0->notifier; node->VAR_4 = VAR_4; node->VAR_2 = VAR_2; node->VAR_3 = VAR_3; event = event_notifier_get_handle(&VAR_0->notifier); WSAEventSelect(node->pfd.VAR_1, event,
FD_READ | FD_ACCEPT | FD_CLOSE |
FD_CONNECT | FD_WRITE | FD_OOB); } aio_notify(VAR_0); }