| summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'src/server/communication_thread.c')
| -rw-r--r-- | src/server/communication_thread.c | 90 |
1 files changed, 82 insertions, 8 deletions
diff --git a/src/server/communication_thread.c b/src/server/communication_thread.c index e226f17..0f367da 100644 --- a/src/server/communication_thread.c +++ b/src/server/communication_thread.c @@ -9,19 +9,93 @@ /******************************************************************************/ /**** LOCAL FUNCTIONS *********************************************************/ /******************************************************************************/ -/* TODO: implement. */ -/* -void main_loop (struct relabsd_server server [const static 1]) + +static void main_loop (struct relabsd_server server [const static 1]) { + int communication_socket, current_client_socket; + int interrupt_fd, highest_fd; + int ready_fds; + fd_set ready_to_read; + + if + ( + relabsd_server_create_communication_node + ( + relabsd_parameters_get_communication_node_name(&(server->parameters)), + &communication_socket + ) + < 0 + ) + { + relabsd_server_interrupt(); + + return; + } + + interrupt_fd = relabsd_server_get_interruption_file_descriptor(); + + if (interrupt_fd > communication_socket) + { + highest_fd = (interrupt_fd + 1); + } + else + { + highest_fd = (communication_socket + 1); + } + + for (;;) + { + FD_ZERO(&ready_to_read); + FD_SET(communication_socket, &ready_to_read); + FD_SET(interrupt_fd, &ready_to_read); + + ready_fds = + select + ( + highest_fd, + &ready_to_read, + (fd_set *) NULL, + (fd_set *) NULL, + (struct timeval *) NULL + ); + + /* TODO: select error handling. */ + + if (!relabsd_server_keep_running()) + { + return; + } + + errno = 0; + + current_client_socket = + accept + ( + communication_socket, + (struct sockaddr *) NULL, + (socklen_t *) NULL + ); + + if (current_client_socket == -1) + { + RELABSD_ERROR + ( + "Unable to accept on the server's socket: %s.", + strerror(errno) + ); + + return -1; + } + + (void) handle_client(current_client_socket, server); + } } -*/ -void * posix_main_loop (void * params) +static void * posix_main_loop (void * params) { - /* main_loop((struct relabsd_server *) params);*/ - params = NULL; + main_loop((struct relabsd_server *) params); - return params; + return NULL; } /******************************************************************************/ |


