Non-blocking I/O support for Ruby OpenSSL
C Ruby
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Ruby 1.9.2 added non-blocking counterparts to its core OpenSSL methods,
including connect_nonblock, read_nonblock, etc. However, there’s no reason
you can’t have these methods today on any recent version of Ruby.

With a bit of crazy C hackery, this module will patch existing versions of
Ruby, including 1.8.6, 1.8.7, and 1.9.1 to include non-blocking SSL support.


openssl-nonblock is installable as a gem. Just run:

gem install openssl-nonblock

to install it.

Alternatively, you may build it from the git repo. Run:

rake gem

to build a gem in the package directory, then:

gem install pkg/openssl-nonblock-X.Y.Z.gem

to install it.


Once the openssl-nonblock gem has been installed, use:

require ‘openssl/nonblock’

to include non-blocking SSL support in your program. This will also pull in
the ‘openssl’ library if you haven’t required it already.

Additional methods

The openssl-nonblock gem adds four new methods to the OpenSSL::SSL::SSLSocket
class. These methods are:

  • 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


openssl-nonblock raises one of two exceptions when it would otherwise need to
block. These exceptions are raised from any of the nonblocking methods that
openssl-nonblock adds and need to be properly handled:

  • 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.


openssl-nonblock is a subcomponent of Rev, an event library for Ruby. Please
address any questions about openssl-ruby to the rev-talk mailing list at:

Additional information about Rev is available at: