igrigorik/em-synchrony — pull request #81 by eliaslevy (2011-11-08 23:39:59+00:00)
Title: read and recv should behave differently

read should wait until it receives as much data as requested or it reaches EOF, rather than return a short read.

When EOF is reached, if some data has already been read, return a partial result. Otherwise, return nil.

Ilya, I had to do a few changes to handle the case of partial reads when EOF is reached. I also had to add a @closed instance variable since checking whether the _req variables are nil is not reliable, as they are recreated when you call sync and they are nil before read or write are called, but potentially after a connection has been established.

I also had to set @closed in the read function, in addition to the unbind callback, as I found that the callback was not being called after sync returned a nil, leading to deadlock.

Its not pretty, but it works. You may want to review with care.