I am using Apache Thrift to set up a c++ server. On the server side I want to execute
execl("a.out","",(char *)NULL);
but either the above line of code is executed first or server.serve() is executed first. Is there any way for the server to start and have the line of code run on top of the server?
I tried putting it in the message_test function but I only want it to execute once not every time when I start up a client.
a.cpp:
int main(){
cout<<"I have started up"<<endl;
string message;
while (cin >> message){
cout<<"your message is: "<<message<<endl;
}
cout<<"I have now exited"<<endl;
}
Server.cpp
class ThforkServiceHandler : virtual public ThforkServiceIf {
public:
ThforkServiceHandler() {
// Your initialization goes here
}
void message_test(const std::string& message) {
// Your implementation goes here
printf("message_test\n");
}
};
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<ThforkServiceHandler> handler(new ThforkServiceHandler());
shared_ptr<TProcessor> processor(new ThforkServiceProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}