Yes, you need to wait for the Write itself to complete before you can attempt another Write. It isn't really an issue of efficiency, it's more about the nature of a network connection, and a mechanism to signal to the application that another write can proceed. See https://grpc.github.io/grpc/cpp/classgrpc_1_1internal_1_1_async_writer_interface.html#a03f8532dfbd6c82c7d1fed5bc6e79d79.
Examining this example's use of ClientAsyncReaderWriter may be helpful to you as well https://github.com/grpc/grpc/blob/master/test/cpp/qps/client_async.cc On Tuesday, August 15, 2023 at 7:26:02 PM UTC-7 黄舒心 wrote: > Hi, > I want to use ClientAsyncReaderWriter::Write() in a loop like this: > for(int i = 0; i < n; i++){ > Write(msg); > } > But I got this error: proto_buffer_writer.h:65] assertion failed: > !byte_buffer->Valid(). > > Does that mean that I can't call Write() multiple times without waiting > tag from CompletionQueue? > > If I must wait for a tag, I can only write one message, and wait until > get the tag, then write the next message. I think it's very inefficient. > > So can I use ClientAsyncReaderWriter::Write() in a loop? If so, how to > resolve the !byte_buffer->Valid() problem? If not, is there any other > method to call Write() multiple times without waiting for tag? Or any other > method that can Write() efficiently > ? > > Any advice is appreciated. > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/15dc3406-cafc-4a5b-a43c-1da3a5ff1ee4n%40googlegroups.com.