@@ -204,8 +204,8 @@ class TGRpcRequestImpl
204204 WriteDataOk (resp, status);
205205 }
206206
207- void Reply (grpc::ByteBuffer* resp, ui32 status) override {
208- WriteByteDataOk (resp, status);
207+ void Reply (grpc::ByteBuffer* resp, ui32 status, EStreamCtrl ctrl ) override {
208+ WriteByteDataOk (resp, status, ctrl );
209209 }
210210
211211 void ReplyError (grpc::StatusCode code, const TString& msg, const TString& details) override {
@@ -314,7 +314,7 @@ class TGRpcRequestImpl
314314 }
315315 }
316316
317- void WriteByteDataOk (grpc::ByteBuffer* resp, ui32 status) {
317+ void WriteByteDataOk (grpc::ByteBuffer* resp, ui32 status, EStreamCtrl ctrl ) {
318318 auto sz = resp->Length ();
319319 if (Writer_) {
320320 GRPC_LOG_DEBUG (Logger_, " [%p] issuing response Name# %s data# byteString peer# %s" , this , Name_,
@@ -332,14 +332,23 @@ class TGRpcRequestImpl
332332 // because of std::function cannot hold move-only captured object
333333 // we allocate shared object on heap to avoid buffer copy
334334 auto uResp = MakeIntrusive<TUniversalResponse<TOut>>(resp);
335- auto cb = [this , uResp = std::move (uResp), sz, status]() {
335+ const bool finish = ctrl == EStreamCtrl::FINISH;
336+ auto cb = [this , uResp = std::move (uResp), sz, status, finish]() {
336337 GRPC_LOG_DEBUG (Logger_, " [%p] issuing response Name# %s data# byteString peer# %s (pushed to grpc)" ,
337338 this , Name_, this ->Context .peer ().c_str ());
338- StateFunc_ = &TThis::NextReply;
339+
340+ StateFunc_ = finish ? &TThis::SetFinishDone : &TThis::NextReply;
341+
339342 ResponseSize += sz;
340343 ResponseStatus = status;
341344 OnBeforeCall ();
342- StreamWriter_->Write (*uResp, GetGRpcTag ());
345+ if (finish) {
346+ Finished_ = true ;
347+ const auto option = grpc::WriteOptions ().set_last_message ();
348+ StreamWriter_->WriteAndFinish (*uResp, option, grpc::Status::OK, GetGRpcTag ());
349+ } else {
350+ StreamWriter_->Write (*uResp, GetGRpcTag ());
351+ }
343352 };
344353 StreamAdaptor_->Enqueue (std::move (cb), false );
345354 }
0 commit comments