Skip to content

Commit 0d77c18

Browse files
committed
Merge #78: Handle EOF in the reader thread
acc05c3 Handle EOF in the reader thread (Alekos Filini) Pull request description: Instead of ignoring empty lines we should return an error, because it means we are at EOF. Fixes #70 and hopefully also #67 ACKs for top commit: RCasatta: ACK acc05c3 Tree-SHA512: e92b27610c91a419cc0f71ecd77205fdaeed592b50e38c42fd8cde805773f4e9e8eeda75ba14f73002d6ae20a70986f981741e6a69d1a89cf61971c174614951
2 parents d9668c8 + acc05c3 commit 0d77c18

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/raw_client.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,21 +477,23 @@ impl<S: Read + Write> RawClient<S> {
477477

478478
// Loop over every message
479479
loop {
480-
raw_resp.clear();
481-
482-
if let Err(e) = reader.read_line(&mut raw_resp) {
480+
let send_err = |e: std::io::Error| {
483481
let error = Arc::new(e);
484482
for (_, s) in self.waiting_map.lock().unwrap().drain() {
485483
s.send(ChannelMessage::Error(error.clone()))?;
486484
}
487-
return Err(Error::SharedIOError(error));
488-
}
489-
trace!("<== {:?}", raw_resp);
490485

491-
if raw_resp.is_empty() {
492-
continue;
486+
Err(Error::SharedIOError(error))
487+
};
488+
489+
match reader.read_line(&mut raw_resp) {
490+
Err(e) => return send_err(e),
491+
Ok(0) => return send_err(std::io::ErrorKind::UnexpectedEof.into()),
492+
_ => {}
493493
}
494494

495+
trace!("<== {:?}", raw_resp);
496+
495497
let resp: serde_json::Value = serde_json::from_str(&raw_resp)?;
496498

497499
// Normally there is and id, but it's missing for spontaneous notifications

0 commit comments

Comments
 (0)