+ reply_header->result =
+ process_trace_cmd(recv_header->command,
+ trace_inf->field);
+ goto send_response;
+
+ }
+ default:
+ reply_header->result =
+ process_simple_client_cmd(recv_header->command,
+ recv_buf);
+ goto send_response;
+
+ }
+
+ return;
+
+send_response:
+ ustcomm_send(sock, reply_header, send_buf);
+}
+
+#define MAX_EVENTS 10
+
+void *listener_main(void *p)
+{
+ struct ustcomm_sock *epoll_sock;
+ struct epoll_event events[MAX_EVENTS];
+ struct sockaddr addr;
+ int accept_fd, nfds, result, i, addr_size;
+
+ DBG("LISTENER");
+
+ pthread_cleanup_push(listener_cleanup, NULL);
+
+ for(;;) {
+ nfds = epoll_wait(epoll_fd, events, MAX_EVENTS, -1);
+ if (nfds == -1) {
+ PERROR("listener_main: epoll_wait failed");
+ continue;
+ }
+
+ for (i = 0; i < nfds; i++) {
+ pthread_mutex_lock(&listener_thread_data_mutex);
+ pthread_cleanup_push(release_listener_mutex, NULL);
+ epoll_sock = (struct ustcomm_sock *)events[i].data.ptr;
+ if (epoll_sock == listen_sock) {
+ addr_size = sizeof(struct sockaddr);
+ accept_fd = accept(epoll_sock->fd,
+ &addr,
+ (socklen_t *)&addr_size);
+ if (accept_fd == -1) {
+ PERROR("listener_main: accept failed");
+ continue;
+ }
+ ustcomm_init_sock(accept_fd, epoll_fd,
+ &ust_socks);
+ } else {
+ memset(receive_header, 0,
+ sizeof(*receive_header));
+ memset(receive_buffer, 0,
+ sizeof(receive_buffer));
+ result = ustcomm_recv(epoll_sock->fd,
+ receive_header,
+ receive_buffer);
+ if (result == 0) {
+ ustcomm_del_sock(epoll_sock, 0);
+ } else {
+ process_client_cmd(receive_header,
+ receive_buffer,
+ epoll_sock->fd);
+ }
+ }
+ pthread_cleanup_pop(1); /* release listener mutex */
+ }