#include #include #include #include "templ.h" #include "Server.h" #include #include #define SERVER_PORT 13123 // Sync variable used to wait for the client's "killMe" request. extern HPCxx_Sync *mywait; // The main function. int main(int argc, char **argv) { // Every HPC++ context (not created by hpcxx_createContext) calls this // function to initialize. Must be called only once in a context. HPCxx_Group *group; hpcxx_init(argc, argv, group); cout << "Server :: in main(): hpcxx_init done \n" << flush; // Instantiate the sync variable to be used later to wait. mywait = new HPCxx_Sync; // Register all the functions that the client may invoke Server::registerAll(); // Allow other contexts to attach to me. I am asking the clients to attach to // me on the SERVER_PORT. The next two args are: a callback function and its // arg. For this example, we don't want to be called back when an attach // request comes, so they are given as NULL. unsigned short attachPort = SERVER_PORT; if ( hpcxx_allowAttach(attachPort, (void (*)(void *)) NULL, (void *)NULL) == -1) { cout << "Error: hpcxx_allowAttach unsuccessful\n"; hpcxx_exit(); cout << "Should never reach here\n" << flush; exit(1); } cout << "Server :: ready to accept \"attach\" requests\n" << flush; // Wait here until asked by the client to exit. int x = *mywait; // Let the killMe call return to the client, then I will exit. sleep(3); // Called before exiting. hpcxx_exit(); }