/* Main loop that takes and sends screenshots until SIGINT killed */ void screenshotprog_1(char *host, double framerate) { input_data screenshot_1_arg; CLIENT *clnt_delete, *clnt_refresh, *clnt_init; create_clients(host, &clnt_init, &clnt_delete, &clnt_refresh); gtk_init(NULL, NULL); initdisplay_1(NULL, clnt_init); while (1) { update_remote_display(clnt_refresh, clnt_delete); sleep(1.0 / framerate); } close_clients(&clnt_init, &clnt_delete, &clnt_refresh); }
/** * Ask all threads to stop (by locking their mutex), and then wait * until they really stop (if wait is TRUE) using g_thread_join() * and g_thread_pool_free(). * * \param wait If wait is TRUE, the function will block until all threads * stopped. Else, it will just ask all threads to stop. */ void stop_threads(gboolean wait) { log_message(INFO, DEBUG_AREA_MAIN, "Asking threads to stop."); #ifdef BUILD_NUAUTH_COMMAND /* stop command server */ if (nuauthconf->use_command_server) { thread_stop(&nuauthdatas->command_thread); } #endif /* ask theads to stop */ if (nuauthconf->push && nuauthconf->hello_authentication) { thread_stop(&nuauthdatas->localid_auth_thread); } /* wait thread end */ if (wait) { log_message(INFO, DEBUG_AREA_MAIN, "Waiting for threads end ..."); } /* kill push worker */ thread_stop(&nuauthdatas->tls_pusher); if (wait) { log_message(DEBUG, DEBUG_AREA_MAIN, "Waiting for thread 'tls pusher'"); g_thread_join(nuauthdatas->tls_pusher.thread); } /* kill entries point */ thread_list_stop_user_ev(nuauthdatas->tls_auth_servers); thread_list_stop_nufw_ev(nuauthdatas->tls_nufw_servers); thread_stop(&nuauthdatas->pre_client_thread); if (wait) { thread_list_wait_end(nuauthdatas->tls_auth_servers); thread_list_wait_end(nuauthdatas->tls_nufw_servers); thread_wait_end(&nuauthdatas->pre_client_thread); } /* Close nufw and client connections */ log_message(INFO, DEBUG_AREA_MAIN, "Closing nufw connections"); close_nufw_servers(); log_message(INFO, DEBUG_AREA_MAIN, "Closing client connections"); close_clients(); thread_stop(&nuauthdatas->limited_connections_handler); thread_stop(&nuauthdatas->search_and_fill_worker); if (wait) { thread_wait_end(&nuauthdatas->limited_connections_handler); thread_wait_end(&nuauthdatas->search_and_fill_worker); } #ifdef BUILD_NUAUTH_COMMAND if (nuauthconf->use_command_server) { thread_wait_end(&nuauthdatas->command_thread); } #endif if (nuauthconf->push && nuauthconf->hello_authentication && wait) { thread_wait_end(&nuauthdatas->localid_auth_thread); } stop_all_thread_pools(wait); /* done! */ log_message(INFO, DEBUG_AREA_MAIN, "Threads stopped."); }
~TCPServer() { close_clients(); _server_sock.close(); }
/* Handle incoming connections */ void server_loop () { struct sockaddr_un client_name; socklen_t name_len = sizeof (client_name); logit ("MOC server started, pid: %d", getpid()); assert (server_sock != -1); log_circular_start (); do { int res; fd_set fds_write, fds_read; FD_ZERO (&fds_read); FD_ZERO (&fds_write); FD_SET (server_sock, &fds_read); FD_SET (wake_up_pipe[0], &fds_read); add_clients_fds (&fds_read, &fds_write); res = 0; if (!server_quit) res = select (max_fd(server_sock)+1, &fds_read, &fds_write, NULL, NULL); if (res == -1 && errno != EINTR && !server_quit) fatal ("select() failed: %s", xstrerror (errno)); if (!server_quit && res >= 0) { if (FD_ISSET(server_sock, &fds_read)) { int client_sock; debug ("accept()ing connection..."); client_sock = accept (server_sock, (struct sockaddr *)&client_name, &name_len); if (client_sock == -1) fatal ("accept() failed: %s", xstrerror (errno)); logit ("Incoming connection"); if (!add_client(client_sock)) busy (client_sock); } if (FD_ISSET(wake_up_pipe[0], &fds_read)) { int w; logit ("Got 'wake up'"); if (read(wake_up_pipe[0], &w, sizeof(w)) < 0) fatal ("Can't read wake up signal: %s", xstrerror (errno)); } send_events (&fds_write); handle_clients (&fds_read); } if (server_quit) logit ("Exiting..."); } while (!server_quit); log_circular_log (); log_circular_stop (); close_clients (); clients_cleanup (); close (server_sock); server_sock = -1; server_shutdown (); }