bool background_work() { // We accept as many connections as we can ... connection_list connections; { boost::unique_lock<mutex_type> l(connections_mtx_, boost::try_to_lock); if(l && !connections_.empty()) { connections.push_back(connections_.front()); connections_.pop_front(); } } connection_ptr rcv; // do // { rcv = accept(); if(rcv && !rcv->receive()) { connections.push_back(rcv); } // } while(rcv); rcv.reset(); if(!connections.empty()) { receive_messages(std::move(connections)); return true; } return false; }
int main() { DWORD exit_code = STILL_ACTIVE; atexit(application_exit); // Set security attributes for the Child Process (Output.exe) SECURITY_ATTRIBUTES security_attributes = {}; security_attributes.nLength = sizeof(SECURITY_ATTRIBUTES); security_attributes.bInheritHandle = TRUE; security_attributes.lpSecurityDescriptor = NULL; CreatePipe(&output_pipe_read, &output_pipe_write, &security_attributes, 0); SetHandleInformation(output_pipe_write, HANDLE_FLAG_INHERIT, 0); // Assigns startup information for the Child Process (Output.exe) STARTUPINFO startup_info = {}; startup_info.cb = sizeof(STARTUPINFO); startup_info.hStdInput = output_pipe_read; startup_info.dwFlags = STARTF_USESTDHANDLES; CreateProcess(NULL, "Output", NULL, NULL, TRUE, CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT, NULL, NULL, &startup_info, &process_information); // Prints welcome banner for LanComms user std::cout << "/---------------------------------------------------------\\\n" "| |\n" "| --Welcome to LanComms-- |\n" "| Version 1.3.2 |\n" "| Copyright (c) 2012 by Christopher Harpum |\n" "| |\n" "| -PRESS ESCAPE TO RETURN TO PREVIOUS MENU AT ANY TIME- |\n" "| |\n" "\\---------------------------------------------------------/\n\n"; // Super loop while (application_alive) { GetExitCodeProcess(process_information.hProcess, &exit_code); if (exit_code != STILL_ACTIVE) { break; } else if (needs_restart) { init_comms(); } else { process_user_messages(); receive_messages(); transmit_messages(); } Sleep(5); } // Application has requested to quit so print leaving message and close down std::cout << "\n\n----------------------------------------\n\n" "Exiting Application..."; return 0; }
void xt_net_http_post_receive_messages(void *http_post_object) { assert(http_post_object); xt_net_http_post_t *http_post; http_post = http_post_object; http_post->last_receive_activity_time = time(NULL); if (receive_messages(http_post)) { reset_for_next_receive(http_post); } }
int main(int argc, char * argv[]) { int socket_id, e; char *hostname, *username; int sending = 0; if (argc < 3) { printf("Usage: client <hostname> <username>\n"); exit(1); } else { hostname = argv[1]; username = argv[2]; if (argc >= 4) { sending = 1; }; } struct user me = new_user(username); setup_sig_handler(); e = socket_id = connect_to_server(hostname, PORT); if (e < 0) check_errors("Error connecting to server", e); e = handshake(socket_id, me); if (e < 0) { printf("Username already taken\n"); running = 0; } else { printf("Handshake succesfull!\n"); } while (running) { if (sending) { e = send_messages(socket_id, me); } else { e = receive_messages(socket_id); } if (e < 0) running = 0; } cleanup(socket_id); }