I have been experimenting with this today, and I've come to the determination that the easiest way to fix buffering.rb would be to not use it at all.
Here's a patch that at least starts to remove the extra buffering logic from reads: https://gist.github.com/headius/6477733
With this patch and a modified version of my earlier one, the test script again runs to completion. However, I don't have the logic quite right since there's multiple failures in SSLSocket tests.
I have also filed http://bugs.ruby-lang.org/issues/8875 with MRI for this issue.
Note also that using sysread instead of read makes the original script work (with my earlier patch) without modifying buffering.rb, since it only utilizes SSLSocket's internal buffers in that case.
So to summarize once again... there are two problems:
- SSLSocket has its own internal buffers that IO.select must be patched to see.
- read* methods on SSLSocket are provided by openssl/buffering.rb, which has an additional buffer IO.select can't see.