static void * worker (void *arg) { ACE_HANDLE handle = (ACE_HANDLE) arg; run_svc (handle); // Wait for the threads to exit. barrier.wait (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) %n: shutting down tester\n")); return 0; }
int main (int argc, char *argv[]) { ACE_LOG_MSG->open (argv[0]); if (argc != 2) ACE_ERROR ((LM_ERROR, "usage: %n string\n%a", 1)); string_name = argv[1]; ACE_HANDLE handles[2]; // Create a pipe and initialize the handles. ACE_Pipe pipe (handles); #if defined (ACE_WIN32) || defined (CHORUS) if (ACE_Thread::spawn (ACE_THR_FUNC (worker), (void *) handles[0], THR_DETACHED) == -1 || ACE_Thread::spawn (ACE_THR_FUNC (worker), (void *) handles[1], THR_DETACHED) == -1) ACE_ERROR ((LM_ERROR, "%p\n%a", "spawn", 1)); barrier.wait (); #else pid_t pid = ACE_OS::fork (argv[0]); if (pid == -1) ACE_ERROR ((LM_ERROR, "%p\n%a", "fork", 1)); run_svc (handles[pid == 0]); ACE_DEBUG ((LM_DEBUG, "(%P|%t) %n: shutting down tester\n")); #endif /* ACE_WIN32 */ if (pipe.close () == -1) ACE_ERROR ((LM_ERROR, "%p\n", "close")); return 0; }
static void * client (void *arg) { client_data info; info.me = client_id++; int info_len = sizeof (client_data); client_arg *data = (client_arg*) arg; ACE_CLASSIX_Port_Core *server_port = data->server; ACE_CLASSIX_Port server_addr(*server_port); ACE_Barrier *barrier = data->wait; //=================================================================== // Stream & Connector // // ACE_CLASSIX_Stream cli_stream(*server_port); ACE_CLASSIX_Stream cli_stream; // create a stream where the local SAP uses the actor's default port. ACE_CLASSIX_CLD_Connector con; // create a connector for the stream ACE_DEBUG ((LM_DEBUG, "(%P|%t) Connecting local and peer SAPs\n")); // Connect local and peer SAPs. barrier->wait(); //=================================================================== // Attempt a connect to the server... // A local port will be created as a local SAP if (con.connect (cli_stream, server_addr) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "connection failed"), 0); } ACE_CLASSIX_Port client_addr; if (cli_stream.local_sap().get_addr (client_addr) == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "get_local_addr"), 0); else ACE_DEBUG ((LM_DEBUG, "(%P|%t) connected client at %d\n", client_addr.get_handle ())); //=================================================================== // Insert the local SAP to the test group ACE_CLASSIX_Group_Stamp group(TEST_STAMP); // group that the client's port is in if (group.insert(&client_addr) == -1) ACE_ERROR_RETURN((LM_ERROR, "Failed to insert local SAP of client %d in to the" "group \n"), -1); //=================================================================== // Do not use Reactor, so disable local port from being monitored int result = cli_stream.unselectable(); if (result != 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) failed to disable local port(%d)\n", result), -1); //=================================================================== // Send data to server (correctly handles "incomplete writes"). char *c = ACE_ALPHABET; do { ACE_OS::thr_yield(); info.c = *c; if (cli_stream.send_n (&info, info_len) != info_len) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "send_n")); }while(*c++ != '\0'); //=================================================================== // Close writer // ACE_DEBUG ((LM_DEBUG, "(%P|%t) closing writer\n")); // Explicitly close the writer-side of the connection. //if (cli_stream.close_writer () == -1) // ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close_writer")); // Wait for handshake with server. client_data response; do { if (cli_stream.ipcRecv_n (&response, info_len) != info_len) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "recv_n")); } while (response.me != info.me); ACE_DEBUG ((LM_DEBUG, "(%P|%t) received handshake from server\n")); // Close the connection completely. if (cli_stream.close () == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close")); return 0; }
int Yield_Test::svc () { #if ACE_DEBUG_CST > 0 ACE_DEBUG ((LM_DEBUG, "Yield_Test::svc (), entering")); ACE_hthread_t thread_id; ACE_Thread_Manager::instance ()->thr_self (thread_id); int priority; ACE_OS::thr_getprio (thread_id, priority); ACE_DEBUG ((LM_DEBUG, "; thread ID is %u, priority is %u\n", thread_id, priority)); #endif /* ACE_DEBUG_CST */ #if defined (VXWORKS) // Start the timer, if it hasn't already been started. if (! started_) { // Double-check. ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1); if (! started_) { started_ = 1; timer_.start (); } } #endif /* VXWORKS */ for (ACE_UINT32 i = 0; i < iterations_; ++i) { #if ACE_DEBUG_CST > 0 if (i % (iterations_ >= 10 ? iterations_ / 10 : 1) == 0) { ACE_DEBUG ((LM_DEBUG, "Yield_Test::svc () [%u], iteration %u\n", thread_id, i)); } #endif /* ACE_DEBUG_CST */ ACE_OS::thr_yield (); } #if defined (VXWORKS) // Stop the timer, if it hasn't already been started. if (! stopped_) { // Maybe it would be better to read the clock before grabbing // the mutex. Then, only apply the clock reading below, instead // of reading the clock after grabbing the mutex. // Double-check. ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, mutex_, -1); if (! stopped_) { stopped_ = 1; timer_.stop (); timer_.elapsed_time (elapsed_time_); /* nanoseconds */ } } #else /* ! VXWORKS */ timer_barrier_.wait (); #endif /* ! VXWORKS */ #if ACE_DEBUG_CST > 0 ACE_DEBUG ((LM_DEBUG, "Yield_Test::svc, finishing\n")); #endif /* ACE_DEBUG_CST */ return 0; }