Allow reading if there is data left in the buffer event socket is closed

Also fixed the bug when writing to a closed socket.
Merge pull request #494 from PinZhang/pzhang/write-on-closed-socket

Allow reading if there is data left in the buffer event socket is closed
Merge branch 'master' into test-https-connection
only catch IOException