blob: 2b676a88efba8d96743c7f5dfc9b4ffe9bb30916 [file] [log] [blame]
Roger Meier122803b2012-06-18 20:23:58 +00001// ThriftCommon.cpp : Common functions for sample Thrift client and server
2//
3
4#include "ThriftCommon.h"
5
6namespace 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 //
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
zeshuai00726681fb2020-06-03 17:24:38 +080026 if (!CreateProcessA(nullptr, handles, nullptr,nullptr,TRUE,0,nullptr,nullptr,&si,&pi))
Roger Meier122803b2012-06-18 20:23:58 +000027 {
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}