Starting the multithreaded server is a bit more complicated than the single threaded one. First you have to create the server object and tell it how many threads you want to have. Then you start the dispatcher threads. Afterwards you can either wait for all the threads to terminate or do something more useful until the termination.
MultiThreadRpcServer server(protocol, num_threads); server.addMethod(&testcall, Struct::getValueName(), "testcall", Integer::getValueName() + "," + Integer::getValueName(), "Testcase with a c-function"); unsigned started = server.dispatchAsync(); do_some_work(); server.waitAsync(false, true);
Create the server object.
Add rpc methods.
Start all threads.
Do something useful in the meanwhile.
Wait for all threads to finish before terminating the application.
One problem is it currently to terminate the server. Since I have not yet found a portable and good solution to make the threads terminate regularly while waiting for connections I usually use a shutdown method which I invoke via XML-RPC. This method has to be sent to all threads. See the server example files. One big drawbacks is that you have to secure this method against attacks.