@@ -315,25 +315,28 @@ lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) {
315
315
Status error;
316
316
ConnectionStatus status = eConnectionStatusSuccess;
317
317
bool done = false ;
318
- bool disconnect = false ;
319
318
while (!done && comm->m_read_thread_enabled ) {
320
319
size_t bytes_read = comm->ReadFromConnection (
321
320
buf, sizeof (buf), std::chrono::seconds (5 ), status, &error);
322
- if (bytes_read > 0 || status == eConnectionStatusEndOfFile )
321
+ if (bytes_read > 0 )
323
322
comm->AppendBytesToCache (buf, bytes_read, true , status);
323
+ else if ((bytes_read == 0 ) && status == eConnectionStatusEndOfFile) {
324
+ if (comm->GetCloseOnEOF ())
325
+ comm->Disconnect ();
326
+ comm->AppendBytesToCache (buf, bytes_read, true , status);
327
+ }
324
328
325
329
switch (status) {
326
330
case eConnectionStatusSuccess:
327
331
break ;
328
332
329
333
case eConnectionStatusEndOfFile:
330
334
done = true ;
331
- disconnect = comm->GetCloseOnEOF ();
332
335
break ;
333
336
case eConnectionStatusError: // Check GetError() for details
334
337
if (error.GetType () == eErrorTypePOSIX && error.GetError () == EIO) {
335
338
// EIO on a pipe is usually caused by remote shutdown
336
- disconnect = comm->GetCloseOnEOF ();
339
+ comm->Disconnect ();
337
340
done = true ;
338
341
}
339
342
if (error.Fail ())
@@ -362,15 +365,9 @@ lldb::thread_result_t Communication::ReadThread(lldb::thread_arg_t p) {
362
365
if (log)
363
366
LLDB_LOGF (log, " %p Communication::ReadThread () thread exiting..." , p);
364
367
365
- comm->BroadcastEvent (eBroadcastBitNoMorePendingInput);
366
- {
367
- std::lock_guard<std::mutex> guard (comm->m_synchronize_mutex );
368
- comm->m_read_thread_did_exit = true ;
369
- if (disconnect)
370
- comm->Disconnect ();
371
- }
372
-
368
+ comm->m_read_thread_did_exit = true ;
373
369
// Let clients know that this thread is exiting
370
+ comm->BroadcastEvent (eBroadcastBitNoMorePendingInput);
374
371
comm->BroadcastEvent (eBroadcastBitReadThreadDidExit);
375
372
return {};
376
373
}
0 commit comments