# \[ANN\] openssl-nonblock 0.2.1: moving towards compatibility with Ruby 1.9.2

**URL:** <https://www.ruby-forum.com/t/ann-openssl-nonblock-0-2-1-moving-towards-compatibility-with-ruby-1-9-2/180270>\
**Category:** Ruby\
**Created:** [December 16, 2009, 7:59am UTC](https://www.ruby-forum.com/t/ann-openssl-nonblock-0-2-1-moving-towards-compatibility-with-ruby-1-9-2/180270 "2009-12-16T07:59:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [December 16, 2009, 7:59am UTC](https://www.ruby-forum.com/t/ann-openssl-nonblock-0-2-1-moving-towards-compatibility-with-ruby-1-9-2/180270/1 "2009-12-16T07:59:34Z")

</div>

openssl-nonblock is a gem which enables non-blocking support in Ruby’s  
OpenSSL classes by monkeypatching into the heart of some of its C code.  
It’s vile, it’s nasty, but it works!

Install it with: gem install openssl-nonblock

See the README on Github: [GitHub - tarcieri/openssl-nonblock: Non-blocking I/O support for Ruby OpenSSL](http://github.com/tarcieri/openssl-nonblock)

Thanks to a patchfrom Young H., the latest release now uses exceptions  
which aim to bridge compatibility with the non-blocking SSL support in  
the  
forthcoming Ruby 1.9.2 release. When a read or write is needed,  
openssl-nonblock now raises IO::WaitReadable or IO::WaitWritable,  
depending  
on the IO event that needs waiting upon.

This release also effectively disables itself on Ruby 1.9.2, deferring  
to  
the native implementation. This means you can require openssl-nonblock  
as a  
dependency on Ruby 1.8.6+, where it will bridge the gap, but on Ruby  
1.9.2  
it will effectively shut itself off and let you use the core Ruby  
implementation directly.

I have not probed the semantic gap between the gem and the core  
implementation in Ruby 1.9.2, so this release should be considered  
experimental. You can expect a forthcoming 0.3.0 release which will  
ensure,  
as best as possible, that the openssl-nonblock gem implements an API  
identical to what will be found in Ruby 1.9.2.

Enjoy!

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [December 16, 2009, 8:05am UTC](https://www.ruby-forum.com/t/ann-openssl-nonblock-0-2-1-moving-towards-compatibility-with-ruby-1-9-2/180270/2 "2009-12-16T08:05:25Z")

</div>

And perhaps an FYI as to why I am CCing ruby-core:

I am not sure how closely my implementation matches what’s in Ruby  
1.9.2.  
My apologies for not further investigating this myself. I would like to  
match what’s in Ruby 1.9.2. thoroughly and completely, so any comments  
as to  
how well I’ve matched the Ruby 1.9.2 API are most certainly welcome.

I implement the following methods as part of OpenSSL::SSL::SSLSocket:

- connect\_nonblock: connect to an SSL server
- accept\_nonblock: accept an SSL connection
- read\_nonblock(length): read up to the given length, but donâ€™t block
- write\_nonblock(data): write as much of the given data as possible  
without blocking

I raise the following exceptions:

- IO::WaitReadable: this means OpenSSL needs to read more data to  
complete the  
given request. You should wait until the underlying IO object becomes  
readable again before retrying the request.
- IO::WaitWritable similar to above, except OpenSSL is trying to  
write  
data to  
the IO object, and the IO object is not presently writable. You  
should  
wait  
until the object becomes writable again before retrying the request.

Does this sound like I am properly matching what is available in Ruby  
1.9.2?

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [January 5, 2010, 3:17am UTC](https://www.ruby-forum.com/t/ann-openssl-nonblock-0-2-1-moving-towards-compatibility-with-ruby-1-9-2/180270/3 "2010-01-05T03:17:54Z")

</div>

On Dec 15, 2009, at 11:04 PM, Tony A. wrote:

> given request. You should wait until the underlying IO object becomes  
> readable again before retrying the request.  
> • IO::WaitWritable similar to above, except OpenSSL is trying to  
> write data to  
> the IO object, and the IO object is not presently writable. You  
> should wait  
> until the object becomes writable again before retrying the request.  
> Does this sound like I am properly matching what is available in  
> Ruby 1.9.2?

I compared the behavior of openssl-nonblock to Ruby 1.9.2 (but not  
exhaustively), and the main issue I saw was the use of a different  
underlying exception object. Ruby 1.9.2 raises an SSLError while  
openssl-nonblock raises its own ReadAgain/WriteAgain object extended  
with IO::WaitReadable/IO::WaitWritable. Now, if all one cares about  
is being notified that the operation would block (that is, if one is  
just rescuing WaitReadable/WaitWritable), then openssl-nonblock and  
Ruby 1.9.2 are indistinguishable. However, it’s possible for someone  
to rescue SSLError directly, and then the difference shows up.

I tried creating a patch to make openssl-nonblock use SSLError just  
like Ruby 1.9.2, but that seemed like it was going to be more work  
than I expected (partly because somethings are defined static inside  
the OpenSSL extension).

I’m not sure how important this difference is in practice, because it  
mainly affects a narrow use case–running a program written for Ruby  
1.9.2 or later on an older Ruby (that is, backporting features).  
That’s a different use case than supporting nonblocking OpenSSL I/O on  
older Ruby versions in a _forward_ compatible manner (obviously, for  
portability, such code should not rescue ReadAgain/WriteAgain, only  
WaitReadable/WaitWritable).

–Young

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [December 16, 2009, 8:31am UTC](https://www.ruby-forum.com/t/ann-openssl-nonblock-0-2-1-moving-towards-compatibility-with-ruby-1-9-2/180270/4 "2009-12-16T08:31:10Z")

</div>

2009/12/16 Tony A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I am not sure how closely my implementation matches what’s in Ruby 1.9.2.  
> My apologies for not further investigating this myself. I would like to  
> match what’s in Ruby 1.9.2. thoroughly and completely, so any comments as to  
> how well I’ve matched the Ruby 1.9.2 API are most certainly welcome.

Use the tests comes with Ruby 1.9.2.
