Hi,
I have a simple client and server using gRPC to exchange information. For now, client side transfer big binary data to server by stream. At server side, server reads one by one from stream and copy the content to another pre-allocated memory to deal with.
My question is, is there any way to avoid coping data from stream into pre-allocated space and use stream data directly in other thread.
Here is the code snip
proto:
message my_data{
sint32 data_len;
string data;
}
rpc transfer(stream my_data) returns (stream other)
server:
Status
transfer ServerContext* context,
ServerReaderWriter<
my_data ,
other >* stream
{
my_data d;
while (stream->Read(&d)) {
char* p = malloc(d.data_len);
strncpy(p, d.data.c_str(), d.data_len);
//add p to list
}
.....
}
is there any way to avoid above strncpy?
Thanks.