/* * The servers main dispatch loop for incoming requests using SSL over TCP */ static DWORD server_dispatch( Remote * remote ) { LONG result = ERROR_SUCCESS; Packet * packet = NULL; THREAD * cpt = NULL; dprintf( "[DISPATCH] entering server_dispatch( 0x%08X )", remote ); // Bring up the scheduler subsystem. result = scheduler_initialize( remote ); if( result != ERROR_SUCCESS ) return result; while( TRUE ) { if( event_poll( serverThread->sigterm, 0 ) ) { dprintf( "[DISPATCH] server dispatch thread signaled to terminate..." ); break; } result = server_socket_poll( remote, 100 ); if( result > 0 ) { result = packet_receive( remote, &packet ); if( result != ERROR_SUCCESS ) { dprintf( "[DISPATCH] packet_receive returned %d, exiting dispatcher...", result ); break; } cpt = thread_create( command_process_thread, remote, packet ); if( cpt ) { dprintf( "[DISPATCH] created command_process_thread 0x%08X, handle=0x%08X", cpt, cpt->handle ); thread_run( cpt ); } } else if( result < 0 ) { dprintf( "[DISPATCH] server_socket_poll returned %d, exiting dispatcher...", result ); break; } } dprintf( "[DISPATCH] calling scheduler_destroy..." ); scheduler_destroy(); dprintf( "[DISPATCH] calling command_join_threads..." ); command_join_threads(); dprintf( "[DISPATCH] leaving server_dispatch." ); return result; }
/*! * @brief The servers main dispatch loop for incoming requests using SSL over TCP * @param remote Pointer to the remote endpoint for this server connection. * @returns Indication of success or failure. */ static BOOL server_dispatch_tcp(Remote * remote, THREAD* dispatchThread) { BOOL running = TRUE; LONG result = ERROR_SUCCESS; Packet *packet = NULL; THREAD *cpt = NULL; dprintf("[DISPATCH] entering server_dispatch( 0x%08X )", remote); // Bring up the scheduler subsystem. result = scheduler_initialize(remote); if (result != ERROR_SUCCESS) { return result; } while (running) { if (event_poll(dispatchThread->sigterm, 0)) { dprintf("[DISPATCH] server dispatch thread signaled to terminate..."); break; } result = server_socket_poll(remote, 500000); if (result > 0) { result = packet_receive_via_ssl(remote, &packet); if (result != ERROR_SUCCESS) { dprintf("[DISPATCH] packet_receive returned %d, exiting dispatcher...", result); break; } running = command_handle(remote, packet); dprintf("[DISPATCH] command_process result: %s", (running ? "continue" : "stop")); } else if (result < 0) { dprintf("[DISPATCH] server_socket_poll returned %d, exiting dispatcher...", result); break; } } dprintf("[DISPATCH] calling scheduler_destroy...") scheduler_destroy(); dprintf("[DISPATCH] calling command_join_threads...") command_join_threads(); dprintf("[DISPATCH] leaving server_dispatch."); return result; }