Guest User

Untitled

a guest
Nov 22nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. package ns;
  2. service Hoge {
  3. rpc Foo(FooReq) returns (FooRep) {}
  4. rpc Bar(BarReq) returns (BarRep) {}
  5. }
  6.  
  7. |
  8. V
  9.  
  10. #### client
  11.  
  12. io = qrpc::Client()
  13.  
  14. rpc = ns::HogeService::Client(io, host, port);
  15. //rpc2 = ns2::FugaService::Client(io, host, port); compose multiple rpc on single connection, if host and port same. otherwise new connection created
  16. //or funny idea with variable template argument...
  17. //qrpc::Fuse<ns::HogeService, ns2::FugaService>::Client(io, host, port);
  18.  
  19. io.PollBackground();
  20. or
  21. while (true) {
  22. io.Poll();
  23. }
  24.  
  25. rpc.Call(BarReq *req, [context...](BarRep *rep, Error *error) {
  26. //run as background poller thread
  27. //or
  28. //thread which calls rpc.Poll
  29. });
  30.  
  31. Future<BarRep> f = rpc.CallAsync(BarReq *req);
  32. unique_ptr<BarRep> rep; //or unique_ptr<IMessage>
  33. unique_ptr<Error> err;
  34. rep.get(rep, err); //may block
  35.  
  36. vector<FutureBase> af;
  37. unique_ptr<IMessage> msg;
  38. for (int i = 0; i < concurrency; i++) {
  39. af.push_back(rpc.CallAsync(FooReq *req);
  40. }
  41. rpc.WaitAll(af);
  42. for (auto &fb : af) {
  43. fb.get(msg, err);
  44. }
  45.  
  46. FutureBase fb = rpc.WaitOne(af);
  47. fb.get(msg, err);
  48.  
  49.  
  50. #### server
  51. io = qrpc::Server(cert, key);
  52. sv = ns::HogeService::Server<Handler>(io, host, port);
  53. //sv2 = ns2::FugaService::Server<Handler2>(io, host, port); compose multiple rpc on single accepted connection, if host and port is same.
  54. //or funny idea with variable template argument...
  55. //qrpc::Fuse<ns::HogeService, ns2::FugaService>::Server<Handler>(io, host, port);
  56.  
  57. io.Serve(number_of_thread);
Add Comment
Please, Sign In to add comment