int main(int argc, const char *argv[]) { int i = 0; int srv_fd = -1; int epoll_fd = -1; struct epoll_event es[MAX_USERS]; struct user_list* ul = create_user_list(); if (init_server(&srv_fd, &epoll_fd) != 0) return 1; for(;;) { i = epoll_wait(epoll_fd, es, MAX_USERS, -1); if (i < 0) { printf("Cannot wait for events\n"); close(epoll_fd); close(srv_fd); return 1; } for (--i; i > -1; --i) { if (es[i].data.fd == srv_fd) { if (accept_client(srv_fd, epoll_fd) < 0) return 1; } else { if (serve_client(epoll_fd, &es[i], ul) < 0) { close(epoll_fd); close(srv_fd); return 1; } } } } return 0; }
void get_own_msg(user* own){ if(NULL == user_list_head ||NULL == user_list_tail) create_user_list(); *own = *user_list_head; }