Skip to content

tarcieri/openssl-nonblock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

openssl-nonblock

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.

Installation

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.

Usage

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

Exceptions

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.

Problems?

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:

http://rubyforge.org/mailman/listinfo/rev-talk

Additional information about Rev is available at:

http://rev.rubyforge.org

About

Non-blocking I/O support for Ruby OpenSSL

Resources

License

Stars

Watchers

Forks

Packages

No packages published