static int setup_unnamed_pipe (ACE_Process_Options &opt) { // Create an unnamed pipe instance. ACE_Pipe pipe; // Check if the pipe is created successfully. if (pipe.open () == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "pipe.open"), -1); // Setting up pipe between parent and child process. Use the pipe // as child process'es ACE_STDIN. ACE_Process_Options will keep // copies (by dup) of fd's that we pass in. Notice that we have to // specify child process to use ACE_STDOUT for output explicitly // because we'll close it down in the line after. Child process // will use whatever we use to dup2 ACE_STDOUT as its stdout. opt.set_handles (pipe.read_handle (), ACE_STDOUT); // The previous keep a copy of original ACE_STDOUT fd, now we // can replace ACE_STDOUT of parent process to the pipe. ACE_OS::dup2 (pipe.write_handle (), ACE_STDOUT); // Don't forget to close the unused fd. pipe.close (); return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { if (argc != 2) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("usage: pingpong <string>\n")), -1); ACE_LOG_MSG->open (argv[0]); string_name = argv[1]; ACE_HANDLE handles[2]; //FUZZ: disable check_for_lack_ACE_OS // Create a pipe and initialize the handles. ACE_Pipe pipe (handles); //FUZZ: enable check_for_lack_ACE_OS #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, ACE_TEXT ("%p\n%a"), ACE_TEXT ("spawn"), 1)); barrier.wait (); #else pid_t pid = ACE_OS::fork (argv[0]); if (pid == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n%a"), ACE_TEXT ("fork"), 1)); run_svc (handles[pid == 0]); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) %n: shutting down tester\n"))); #endif /* ACE_WIN32 */ if (pipe.close () == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("close"))); 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 open_pipe (ACE_Pipe &pipe, const char *name) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("opening %C\n"), name)); int result = pipe.open (); ACE_TEST_ASSERT (result != -1); result = pipe.read_handle () != ACE_INVALID_HANDLE && pipe.write_handle () != ACE_INVALID_HANDLE; ACE_TEST_ASSERT (result == 1); if (close_pipe) pipe.close (); }