Fix incorrect reading logic and EAGAIN handling
Fix incorrect reading logic and EAGAIN handling

This is one of the issues raised by #4410

jkonecny12/kakoune,casimir/kakoune,mawww/kakoune,casimir/kakoune,mawww/kakoune,mawww/kakoune,casimir/kakoune,mawww/kakoune,jkonecny12/kakoune,jkonecny12/kakoune,jkonecny12/kakoune,casimir/kakoune