Пример #1
0
static void ares_socket_cb(void *data, int s, int read, int write)
{
    ape_global *ape = data;
    unsigned i, f   = 0u;

    int listenfor = read ? EVENT_READ : 0 | write ? EVENT_WRITE : 0;

    for (i = 0; i < ape->dns.sockets.size; i++) {
        if (!f && ape->dns.sockets.list[i].s.fd == 0) {
            f = i;
        } else if (ape->dns.sockets.list[i].s.fd == s) {
            /* Modify or delete the object (+ return) */
            if (!listenfor) {
                ape->dns.sockets.list[i].s.fd = 0;
                events_del(s, ape);
                close(s);
            } else {
                events_mod((ape_event_descriptor *)&ape->dns.sockets.list[i],
                           listenfor | EVENT_LEVEL, ape);
            }
            return;
        }
    }

    setnonblocking(s);
    ape->dns.sockets.list[f].s.fd   = s;
    ape->dns.sockets.list[f].s.type = APE_EVENT_DELEGATE;
    ape->dns.sockets.list[f].on_io  = ares_io;
    ape->dns.sockets.list[f].data   = NULL;

    events_add((ape_event_descriptor *)&ape->dns.sockets.list[f],
               listenfor | EVENT_LEVEL, ape);
}
Пример #2
0
void APE_destroy(ape_global *ape)
{
    //  destroying dns
    struct _ares_sockets *as;
    size_t i;

    ares_cancel(ape->dns.channel);
    as = ape->dns.sockets.list;

    for (i = 0; i < ape->dns.sockets.size; i++) {
        events_del(as->s.fd, ape);
        as++;
    }

    free(ape->dns.sockets.list);
    ape->dns.sockets.size = 0;
    ape->dns.sockets.used = 0;
    ares_destroy(ape->dns.channel);
    ares_library_cleanup();

    //  destroying events
    events_destroy(&ape->events);
    // destroying timers
    APE_timers_destroy_all(ape);

    if (ape->ssl_global_ctx) {
        ape_ssl_shutdown(ape->ssl_global_ctx);
        ape_ssl_destroy(ape->ssl_global_ctx);
    }
    ape_ssl_library_destroy();

    close(ape->urandom_fd);
    if (ape->logger.cleanup) {
        ape->logger.cleanup(ape->logger.ctx, ape->logger.cb_args);
    }
    //  destroying rest
    free(ape);

    pthread_setspecific(g_APEThreadContextKey, NULL);
}