@ -42,7 +42,8 @@ void DumpSliceBuffer(SliceBuffer* buffer, absl::string_view context_string) {
for ( size_t i = 0 ; i < buffer - > Count ( ) ; i + + ) {
for ( size_t i = 0 ; i < buffer - > Count ( ) ; i + + ) {
auto str = buffer - > MutableSliceAt ( i ) . as_string_view ( ) ;
auto str = buffer - > MutableSliceAt ( i ) . as_string_view ( ) ;
GRPC_TRACE_LOG ( event_engine_endpoint , INFO )
GRPC_TRACE_LOG ( event_engine_endpoint , INFO )
< < context_string < < " : " < < str ;
< < context_string < < " [ " < < i + 1 < < " / " < < buffer - > Count ( )
< < " ]: " < < str ;
}
}
}
}
@ -78,7 +79,7 @@ WindowsEndpoint::~WindowsEndpoint() {
void WindowsEndpoint : : AsyncIOState : : DoTcpRead ( SliceBuffer * buffer ) {
void WindowsEndpoint : : AsyncIOState : : DoTcpRead ( SliceBuffer * buffer ) {
GRPC_TRACE_LOG ( event_engine_endpoint , INFO )
GRPC_TRACE_LOG ( event_engine_endpoint , INFO )
< < " WindowsEndpoint:: " < < endpoint < < " reading " ;
< < " WindowsEndpoint:: " < < endpoint < < " attempting a read " ;
if ( socket - > IsShutdown ( ) ) {
if ( socket - > IsShutdown ( ) ) {
socket - > read_info ( ) - > SetErrorStatus (
socket - > read_info ( ) - > SetErrorStatus (
absl : : InternalError ( " Socket is shutting down. " ) ) ;
absl : : InternalError ( " Socket is shutting down. " ) ) ;
@ -294,15 +295,23 @@ void WindowsEndpoint::HandleReadClosure::Run() {
return ResetAndReturnCallback ( ) ( status ) ;
return ResetAndReturnCallback ( ) ( status ) ;
}
}
if ( result . bytes_transferred = = 0 ) {
if ( result . bytes_transferred = = 0 ) {
DCHECK_GT ( io_state . use_count ( ) , 0 ) ;
// Either the endpoint is shut down or we've seen the end of the stream
// Either the endpoint is shut down or we've seen the end of the stream
if ( GRPC_TRACE_FLAG_ENABLED ( event_engine_endpoint_data ) ) {
if ( GRPC_TRACE_FLAG_ENABLED ( event_engine_endpoint_data ) ) {
DumpSliceBuffer ( buffer_ , absl : : StrFormat ( " WindowsEndpoint::%p READ " ,
LOG ( INFO ) < < " WindowsEndpoint:: " < < this < < " read 0 bytes. " ;
DumpSliceBuffer (
& last_read_buffer_ ,
absl : : StrFormat ( " WindowsEndpoint::%p READ last_read_buffer_: " ,
io_state - > endpoint ) ) ;
io_state - > endpoint ) ) ;
}
}
buffer_ - > Swap ( last_read_buffer_ ) ;
if ( buffer_ - > Length ( ) = = 0 ) {
// Only send an error if there is no more data to consume. If the endpoint
// or socket is shut down, the next read will discover that.
status = absl : : InternalError ( " End of TCP stream " ) ;
status = absl : : InternalError ( " End of TCP stream " ) ;
grpc_core : : StatusSetInt ( & status , grpc_core : : StatusIntProperty : : kRpcStatus ,
grpc_core : : StatusSetInt ( & status , grpc_core : : StatusIntProperty : : kRpcStatus ,
GRPC_STATUS_UNAVAILABLE ) ;
GRPC_STATUS_UNAVAILABLE ) ;
buffer_ - > Swap ( last_read_buffer_ ) ;
}
return ResetAndReturnCallback ( ) ( status ) ;
return ResetAndReturnCallback ( ) ( status ) ;
}
}
DCHECK_GT ( result . bytes_transferred , 0 ) ;
DCHECK_GT ( result . bytes_transferred , 0 ) ;
@ -320,8 +329,13 @@ void WindowsEndpoint::HandleReadClosure::Run() {
bool WindowsEndpoint : : HandleReadClosure : : MaybeFinishIfDataHasAlreadyBeenRead ( ) {
bool WindowsEndpoint : : HandleReadClosure : : MaybeFinishIfDataHasAlreadyBeenRead ( ) {
if ( last_read_buffer_ . Length ( ) > 0 ) {
if ( last_read_buffer_ . Length ( ) > 0 ) {
GRPC_TRACE_LOG ( event_engine_endpoint , INFO )
< < " WindowsEndpoint:: " < < io_state_ - > endpoint
< < " finishing a synchronous read " ;
buffer_ - > Swap ( last_read_buffer_ ) ;
buffer_ - > Swap ( last_read_buffer_ ) ;
// Captures io_state_ to ensure it remains alive until the callback is run.
if ( GRPC_TRACE_FLAG_ENABLED ( event_engine_endpoint_data ) ) {
DumpSliceBuffer ( buffer_ , " finishing synchronous read " ) ;
}
io_state_ - > thread_pool - > Run (
io_state_ - > thread_pool - > Run (
[ cb = ResetAndReturnCallback ( ) ] ( ) mutable { cb ( absl : : OkStatus ( ) ) ; } ) ;
[ cb = ResetAndReturnCallback ( ) ] ( ) mutable { cb ( absl : : OkStatus ( ) ) ; } ) ;
return true ;
return true ;