mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-05 18:59:42 +01:00
9113e416e7
* 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
73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
#include <string>
|
|
#include <iostream>
|
|
|
|
#include <grpc++/grpc++.h>
|
|
|
|
#include "echo.grpc.pb.h"
|
|
|
|
using namespace std;
|
|
using namespace echo;
|
|
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_;
|
|
};
|
|
|
|
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_;
|
|
};
|
|
|
|
int main(){
|
|
/*
|
|
EchoClient client(grpc::CreateChannel("localhost:50051",
|
|
grpc::InsecureChannelCredentials()));
|
|
string msg("hi");
|
|
for(int i = 0; i < 100000; i++){
|
|
Status status = client.DoEcho(msg);
|
|
if(!status.ok()){
|
|
cout<<"Error: "<<status.error_code()<<endl;
|
|
return 1;
|
|
}
|
|
}
|
|
*/
|
|
|
|
AddClient client (grpc::CreateChannel("localhost:50051",
|
|
grpc::InsecureChannelCredentials()));
|
|
AddResponse answer = client.DoAdd(1,2);
|
|
cout<<"Got answer: "<<answer.answer()<<endl;
|
|
return 0;
|
|
}
|