2016-06-03 19:34:09 +02:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
2016-07-21 21:55:16 +02:00
|
|
|
#include <thread>
|
2016-06-03 19:34:09 +02:00
|
|
|
|
|
|
|
#include <grpc++/grpc++.h>
|
|
|
|
|
|
|
|
#include "echo.grpc.pb.h"
|
|
|
|
|
|
|
|
using namespace std;
|
Joel/highlevelv2 (#40)
* Tweak runOps param order, inline common op sequences, clean up serverHandleNormalCall
* More ops sequence inlining for clarity, experimenting with Managed
* Checkpoint: preliminary support for all streaming modes; much cleanup/refactoring and api design still needed
* Use mempty for default StatusDetails; tweak bad status matching mechanism
* Preliminary user-facing, server-streaming, low-level api and test
* renaming wibbles
* Preliminary user-facing, client-streaming, low-level api and test
* Move sendMsgs comb to Network.GRPC.LowLevel.Op; misc cleanup/DCR
* Modify bidi streaming to omit request payload
* Add transformers dep
* Preliminary user-facing low-level bidirectional streaming api and test
* Fix missing peek import
* Remove TimeoutSeconds params on streaming mode functions
* Fix serverHandleNormalCall rebase wart
* Fix rebase warts; minor hlint fixes and wibbles
* Post-rebase tweaks to optional payload use in serverRequestCall (i.e., now respects payloadHandling again)
* Cleanup/refactor serverRequestCall
* Fix comment
* Change ServerRWHandler type so that handler does not have to invoke a finalizer
* Change ServerReaderHandler type so that handler does not have to invoke a finalizer
* Simplify serverWriter interface and ServerWriterHandler structure
* Simplify serverRW (get rid of exec param), improve bidi streaming tests
* Use ExceptT in serverRW impl
* Change ServerRWHandler type to pass recv/send operations.
* Renaming
* Define ClientRWHandler, pass recv/send ops
* wibbles
* Use ExceptT in clientRW impl
* Add DataKinded phantom typing to RegisteredMethod; misc cleanup
* Simplify sendMsgs interface; add SingleSend type and related helpers
* Rename SingleSend to SendSingle, use ExceptT to clean up {client,server}Writer and sendMsgs
* More ExceptT cleanup in clientWriter
* Factor out reusable bits of clientWriter
* Shrink ServerReaderHandler
* Delete stale comments
* begin high-level server interface
* update to datakind representation
* clean up
* move method type info to type level, parametrize ServerCall by payload
* convert for writer handler
* start switching over to Message-based handlers
* begin work on highlevel example
* comment out old code
* parametrize StreamSend
* parametrize StreamRecv
* conversion for ServerReaderHandler
* finish handler conversions
* Add high level version and payload checking to echo-client
* Decouple server CQs from call-bound CQs (registered methods); use more consistent naming conventions
* Decouple server/call-bound CQs for unregistered methods; refactor U.serverRequestCall; misc cleanup
* Make convertRecv total; formatting wibbles
2016-07-12 20:28:21 +02:00
|
|
|
using namespace echo;
|
2016-06-03 19:34:09 +02:00
|
|
|
using grpc::Channel;
|
|
|
|
using grpc::ClientContext;
|
|
|
|
using grpc::Status;
|
|
|
|
|
|
|
|
class EchoClient {
|
|
|
|
public:
|
|
|
|
EchoClient(shared_ptr<Channel> chan) : stub_(Echo::NewStub(chan)) {}
|
|
|
|
|
|
|
|
Status DoEcho(const string& msg){
|
|
|
|
EchoRequest req;
|
|
|
|
req.set_message(msg);
|
|
|
|
|
|
|
|
EchoRequest resp;
|
|
|
|
|
|
|
|
ClientContext ctx;
|
|
|
|
|
|
|
|
return stub_->DoEcho(&ctx, req, &resp);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
unique_ptr<Echo::Stub> stub_;
|
|
|
|
};
|
|
|
|
|
Joel/highlevelv2 (#40)
* Tweak runOps param order, inline common op sequences, clean up serverHandleNormalCall
* More ops sequence inlining for clarity, experimenting with Managed
* Checkpoint: preliminary support for all streaming modes; much cleanup/refactoring and api design still needed
* Use mempty for default StatusDetails; tweak bad status matching mechanism
* Preliminary user-facing, server-streaming, low-level api and test
* renaming wibbles
* Preliminary user-facing, client-streaming, low-level api and test
* Move sendMsgs comb to Network.GRPC.LowLevel.Op; misc cleanup/DCR
* Modify bidi streaming to omit request payload
* Add transformers dep
* Preliminary user-facing low-level bidirectional streaming api and test
* Fix missing peek import
* Remove TimeoutSeconds params on streaming mode functions
* Fix serverHandleNormalCall rebase wart
* Fix rebase warts; minor hlint fixes and wibbles
* Post-rebase tweaks to optional payload use in serverRequestCall (i.e., now respects payloadHandling again)
* Cleanup/refactor serverRequestCall
* Fix comment
* Change ServerRWHandler type so that handler does not have to invoke a finalizer
* Change ServerReaderHandler type so that handler does not have to invoke a finalizer
* Simplify serverWriter interface and ServerWriterHandler structure
* Simplify serverRW (get rid of exec param), improve bidi streaming tests
* Use ExceptT in serverRW impl
* Change ServerRWHandler type to pass recv/send operations.
* Renaming
* Define ClientRWHandler, pass recv/send ops
* wibbles
* Use ExceptT in clientRW impl
* Add DataKinded phantom typing to RegisteredMethod; misc cleanup
* Simplify sendMsgs interface; add SingleSend type and related helpers
* Rename SingleSend to SendSingle, use ExceptT to clean up {client,server}Writer and sendMsgs
* More ExceptT cleanup in clientWriter
* Factor out reusable bits of clientWriter
* Shrink ServerReaderHandler
* Delete stale comments
* begin high-level server interface
* update to datakind representation
* clean up
* move method type info to type level, parametrize ServerCall by payload
* convert for writer handler
* start switching over to Message-based handlers
* begin work on highlevel example
* comment out old code
* parametrize StreamSend
* parametrize StreamRecv
* conversion for ServerReaderHandler
* finish handler conversions
* Add high level version and payload checking to echo-client
* Decouple server CQs from call-bound CQs (registered methods); use more consistent naming conventions
* Decouple server/call-bound CQs for unregistered methods; refactor U.serverRequestCall; misc cleanup
* Make convertRecv total; formatting wibbles
2016-07-12 20:28:21 +02:00
|
|
|
class AddClient {
|
|
|
|
public:
|
|
|
|
AddClient(shared_ptr<Channel> chan) : stub_(Add::NewStub(chan)) {}
|
|
|
|
|
|
|
|
AddResponse DoAdd(const uint32_t x, const uint32_t y){
|
|
|
|
AddRequest msg;
|
|
|
|
msg.set_addx(x);
|
|
|
|
msg.set_addy(y);
|
|
|
|
|
|
|
|
AddResponse resp;
|
|
|
|
|
|
|
|
ClientContext ctx;
|
|
|
|
|
|
|
|
stub_->DoAdd(&ctx, msg, &resp);
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
unique_ptr<Add::Stub> stub_;
|
|
|
|
};
|
|
|
|
|
2016-07-21 21:55:16 +02:00
|
|
|
void do10k(EchoClient* client, AddClient* addClient){
|
2016-06-03 19:34:09 +02:00
|
|
|
string msg("hi");
|
2016-07-21 21:55:16 +02:00
|
|
|
|
|
|
|
for(int i = 0; i < 10000; i++){
|
|
|
|
Status status = client->DoEcho(msg);
|
2016-06-03 19:34:09 +02:00
|
|
|
if(!status.ok()){
|
|
|
|
cout<<"Error: "<<status.error_code()<<endl;
|
|
|
|
}
|
2016-07-21 21:55:16 +02:00
|
|
|
AddResponse answer = addClient->DoAdd(1,2);
|
2016-06-03 19:34:09 +02:00
|
|
|
}
|
2016-07-21 21:55:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(){
|
2016-06-03 19:34:09 +02:00
|
|
|
|
2016-07-21 21:55:16 +02:00
|
|
|
EchoClient client(grpc::CreateChannel("localhost:50051",
|
|
|
|
grpc::InsecureChannelCredentials()));
|
2016-07-14 18:53:28 +02:00
|
|
|
AddClient addClient (grpc::CreateChannel("localhost:50051",
|
Joel/highlevelv2 (#40)
* Tweak runOps param order, inline common op sequences, clean up serverHandleNormalCall
* More ops sequence inlining for clarity, experimenting with Managed
* Checkpoint: preliminary support for all streaming modes; much cleanup/refactoring and api design still needed
* Use mempty for default StatusDetails; tweak bad status matching mechanism
* Preliminary user-facing, server-streaming, low-level api and test
* renaming wibbles
* Preliminary user-facing, client-streaming, low-level api and test
* Move sendMsgs comb to Network.GRPC.LowLevel.Op; misc cleanup/DCR
* Modify bidi streaming to omit request payload
* Add transformers dep
* Preliminary user-facing low-level bidirectional streaming api and test
* Fix missing peek import
* Remove TimeoutSeconds params on streaming mode functions
* Fix serverHandleNormalCall rebase wart
* Fix rebase warts; minor hlint fixes and wibbles
* Post-rebase tweaks to optional payload use in serverRequestCall (i.e., now respects payloadHandling again)
* Cleanup/refactor serverRequestCall
* Fix comment
* Change ServerRWHandler type so that handler does not have to invoke a finalizer
* Change ServerReaderHandler type so that handler does not have to invoke a finalizer
* Simplify serverWriter interface and ServerWriterHandler structure
* Simplify serverRW (get rid of exec param), improve bidi streaming tests
* Use ExceptT in serverRW impl
* Change ServerRWHandler type to pass recv/send operations.
* Renaming
* Define ClientRWHandler, pass recv/send ops
* wibbles
* Use ExceptT in clientRW impl
* Add DataKinded phantom typing to RegisteredMethod; misc cleanup
* Simplify sendMsgs interface; add SingleSend type and related helpers
* Rename SingleSend to SendSingle, use ExceptT to clean up {client,server}Writer and sendMsgs
* More ExceptT cleanup in clientWriter
* Factor out reusable bits of clientWriter
* Shrink ServerReaderHandler
* Delete stale comments
* begin high-level server interface
* update to datakind representation
* clean up
* move method type info to type level, parametrize ServerCall by payload
* convert for writer handler
* start switching over to Message-based handlers
* begin work on highlevel example
* comment out old code
* parametrize StreamSend
* parametrize StreamRecv
* conversion for ServerReaderHandler
* finish handler conversions
* Add high level version and payload checking to echo-client
* Decouple server CQs from call-bound CQs (registered methods); use more consistent naming conventions
* Decouple server/call-bound CQs for unregistered methods; refactor U.serverRequestCall; misc cleanup
* Make convertRecv total; formatting wibbles
2016-07-12 20:28:21 +02:00
|
|
|
grpc::InsecureChannelCredentials()));
|
2016-07-21 21:55:16 +02:00
|
|
|
thread unus(do10k,&client,&addClient);
|
|
|
|
thread duo(do10k,&client,&addClient);
|
|
|
|
thread tres(do10k,&client,&addClient);
|
|
|
|
thread quattuor(do10k,&client,&addClient);
|
|
|
|
unus.join();
|
|
|
|
duo.join();
|
|
|
|
tres.join();
|
|
|
|
quattuor.join();
|
2016-06-03 19:34:09 +02:00
|
|
|
return 0;
|
|
|
|
}
|