void dispatcher_sigusr1(int sig) { syslog(LOG_INFO, "Cerrando cola de conexiones"); destroy_connections(_connections); free(_connections); syslog(LOG_INFO, "Apagando dispatcher"); daemon_on = 0; pthread_exit(OK); }
void destroy_graph(t_graph *graph) { t_graph *tmp; t_graph *prev; tmp = graph; prev = NULL; while (tmp) { destroy_connections(tmp->connections); ft_strdel(&tmp->id); ft_memdel((void**)&prev); prev = tmp; tmp = tmp->next; } ft_memdel((void**)&prev); }
int main(int argc, char *argv[]) { int lsfd; int ret, n, i; struct epoll_event event; struct epoll_event *events = NULL; connection_t *conn; connections_head_t *head = NULL; if (argc != 2) { fprintf(stdout, "Usage: %s [port]\n", argv[0]); exit(EXIT_FAILURE); } /* init connections cache */ head = init_connections(MAX_CONNECTIONS); if (NULL == head) { ERROR_MSG("init_connections\n"); goto error; } /* init SSL data */ ret = init_OpenSSL(); if (ret != 0) { ERROR_MSG("init_OpenSSL\n"); goto error; } head->ctx = init_ssl_ctx(SRV_CERTFILE, SRV_PRIKEY, SRV_CAFILE); if (NULL == head->ctx) { ERROR_MSG("init_ssl_ctx error\n"); goto error; } /* init epoll's data */ head->epfd = epoll_create(MAX_CONNECTIONS); if (-1 == head->epfd) { ERROR_MSG("epoll_create\n"); goto error; } events = calloc(MAX_EVENTS, sizeof(struct epoll_event)); if (NULL == events) { ERROR_MSG("calloc\n"); goto error; } /* listen's data */ lsfd = start_listen(argv[1]); if (lsfd < 0) { ERROR_MSG("start_listen\n"); goto error; } /* add the lsfd to events */ conn = get_connection(head); if (NULL == conn) { ERROR_MSG("get_connection\n"); goto error; } conn->fd = lsfd; conn->handler = accept_handler; event.data.ptr = conn; event.events = EPOLLIN | EPOLLET; ret = epoll_ctl(head->epfd, EPOLL_CTL_ADD, lsfd, &event); if (-1 == ret) { ERROR_MSG("epoll_ctl\n"); goto error; } /* The event loop */ while (1) { n = epoll_wait(head->epfd, events, MAX_EVENTS, -1); for (i = 0; i < n; ++i) { conn = events[i].data.ptr; if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || !(events[i].events & EPOLLIN)) { /* it will delete the event from events at the same time * due to invoked close */ free_connection(head, conn); } else { if (conn->handler) { conn->handler(head, conn); } } } } error: if (events) free(events); destroy_connections(head); return EXIT_SUCCESS; }