1919#include < iostream>
2020#include < memory>
2121#include < string>
22+ #include < sys/time.h>
2223
2324#include < grpc++/grpc++.h>
2425#include < grpc/support/log.h>
@@ -51,7 +52,12 @@ class GreeterClient {
5152
5253 // Assembles the client's payload and sends it to the server.
5354 void SayHello (const std::string& user) {
54- void * payload_alloc = GenPayload (1024 *1024 *200 );
55+ const int size = 12 * 1024 * 1024 ;
56+ char * payload_alloc = (char *)GenPayload (size);
57+
58+ struct timeval t0_copy, t1_copy;
59+ gettimeofday (&t0_copy, 0 );
60+ // std::string pay_load(payload_alloc, size);
5561
5662 // Call object to store rpc data
5763 AsyncClientCall* call = new AsyncClientCall;
@@ -60,7 +66,13 @@ class GreeterClient {
6066 // Data we are sending to the server.
6167 HelloRequest request;
6268 request.set_name (user);
63- request.set_payload (*reinterpret_cast <std::string*>(payload_alloc));
69+ request.set_payload (payload_alloc, size);
70+
71+ gettimeofday (&t1_copy, 0 );
72+ double dif = double ((t1_copy.tv_sec - t0_copy.tv_sec ) * 1000.0 +
73+ (t1_copy.tv_usec - t0_copy.tv_usec ) / 1000.0 );
74+ printf (" time is %.2f ms\n " , dif);
75+
6476 // auto* pl = request.mutable_payload();
6577 // pl = reinterpret_cast<std::string*>(payload_alloc);
6678 free (payload_alloc);
@@ -150,8 +162,15 @@ int main(int argc, char** argv) {
150162 // are created. This channel models a connection to an endpoint (in this case,
151163 // localhost at port 50051). We indicate that the channel isn't authenticated
152164 // (use of InsecureChannelCredentials()).
153- GreeterClient greeter (grpc::CreateChannel (
154- " localhost:50051" , grpc::InsecureChannelCredentials ()));
165+ grpc::ChannelArguments args;
166+ args.SetMaxSendMessageSize (std::numeric_limits<int >::max ());
167+ args.SetMaxReceiveMessageSize (std::numeric_limits<int >::max ());
168+
169+ auto ch = std::shared_ptr<grpc::Channel>( grpc::CreateCustomChannel (" 127.0.0.1:50051" , grpc::InsecureChannelCredentials (), args));
170+
171+ // GreeterClient greeter(grpc::CreateChannel(
172+ // "localhost:50051", grpc::InsecureChannelCredentials()));
173+ GreeterClient greeter (ch);
155174
156175 // Spawn reader thread that loops indefinitely
157176 std::thread thread_ = std::thread (&GreeterClient::AsyncCompleteRpc, &greeter);
0 commit comments