/** * @brief We have a notification on the listening socket, which means one or more incoming connections. * * @return */ static int new_connect(int listen_fd, int efd) { int infd; int ret = 0; infd = accept(listen_fd, NULL, 0); if (infd == -1) { printf("infd is -1\n"); if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { /* We have processed all incoming connections. */ } else { DEBUG_ERROR("accept"); } return -1; } /* Make the incoming socket non-blocking and add it to the * list of fds to be monitored. */ ret = make_socket_non_blocking(infd); if (ret == -1) { DEBUG_ERROR("set none blocking error\n"); return ret; } return add2epoll(efd, EPOLLIN | EPOLLET, infd); }
int msg_init(char *sock_path) { int listen_sock; int efd; int ret; listen_sock = create_socket(sock_path); if (-1 == listen_sock) { return -1; } efd = epoll_create1(0); if (efd == -1) { DEBUG_ERROR("epoll_create"); close(listen_sock); return -1; } ret = add2epoll(efd, EPOLLIN, listen_sock); if (0 == ret) { g_efd = efd; g_listen_fd = listen_sock; } else { close(listen_sock); close(efd); } return ret; }
static int epoll_init(int listen_sock) { int efd; efd = epoll_create1(0); if (efd > 0) { if (!add2epoll(efd, EPOLLIN, listen_sock)) { return efd; } else { close(efd); } } return -1; }