[Ace-users] Pipes on Win32 and Unix

pivlev at gmail.com pivlev at gmail.com
Tue Feb 5 10:52:37 CST 2008


As described on http://groups.google.com/group/comp.soft-sys.ace/browse_thread/thread/9b8e6a105b193d47/2a119dd6af437bdf
, the problem could be solved by setting ACE_CLOEXEC for file
descriptor.
Now the code has exactly the same behaviour on Win32 and Linux:

class HandleWrapper: public ACE_IPC_SAP
{

};

int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
	ACE_Process nmproc;
	ACE_Process_Options nm_opts;
	nm_opts.command_line(pro_path);

	ACE_HANDLE pipe[2];
	ACE_OS::pipe(pipe);
	nm_opts.set_handles(pipe[0]);

	HandleWrapper hr;
	hr.set_handle(pipe[1]);
	hr.enable(ACE_CLOEXEC);

	ACE_OS::close(pipe[0]);
	nmproc.spawn(nm_opts);
	ACE_OS::write(pipe[1], "aa\n", 2);
	nm_opts.release_handles();
	ACE_OS::sleep(2);
	ACE_OS::close(pipe[1]); // After this call a child process receives
EOF
	return 0;
}



More information about the Ace-users mailing list