1 // ThriftCommon.cpp : Common functions for sample Thrift client and server
2 //
3 
4 #include "ThriftCommon.h"
5 
6 namespace thriftcommon
7 {
8 	//----------------------------------------------------------------------------
9 	//Launch child process and pass R/W anonymous pipe handles on cmd line.
10 	//This is a simple example and does not include elevation or other
11 	//advanced features.
12 	//
LaunchAnonPipeChild(std::string app,boost::shared_ptr<TServerTransport> transport)13 	bool LaunchAnonPipeChild(std::string app, boost::shared_ptr<TServerTransport> transport)
14 	{
15 #ifdef _WIN32
16 		PROCESS_INFORMATION pi;
17 		STARTUPINFOA si;
18 		GetStartupInfoA(&si);  //set startupinfo for the spawned process
19 		char handles[MAX_PATH];  //Stores pipe handles converted to text
20 
21 		sprintf(handles, "%s %d %d", app.c_str(),
22 			(int)boost::shared_dynamic_cast<TPipeServer>(transport)->getClientRdPipeHandle(),
23 			(int)boost::shared_dynamic_cast<TPipeServer>(transport)->getClientWrtPipeHandle());
24 
25 		//spawn the child process
26 		if (!CreateProcessA(nullptr, handles, nullptr,nullptr,TRUE,0,nullptr,nullptr,&si,&pi))
27 		{
28 			GlobalOutput.perror("TPipeServer CreateProcess failed, GLE=", GetLastError());
29 			return false;
30 		}
31 
32 		CloseHandle(pi.hThread);
33 		CloseHandle(pi.hProcess);
34 #endif
35 		return true;
36 	}
37 }
38