OpenSSL / Persistent connection

Hi.

I want to have a persistent OpenSSL over a TCPSocket connection. The
idea is having a rails website, a backgroundrb daemon. I do keep the
connections within Model.something and I reuse them when needed.

Sadly the OpenSSL socket does not generate any timeout, etc, when the
server side disconnected (I don’t know if it did but it doesn’t work
anymore so I guess it did).

OpenSSL documentation is non existent, does anyone has a hint how to
do that ? As of today, this is how I connect :

  ctx = OpenSSL::SSL::SSLContext.new
  ctx.key = OpenSSL::PKey::RSA.new(cert, self.passphrase)
  ctx.cert = OpenSSL::X509::Certificate.new(cert)
  ctx.timeout = 7200

  s = TCPSocket.new(host, PORT)
  ssl = OpenSSL::SSL::SSLSocket.new(s, ctx)
  ssl.sync = true
  ssl.sync_close = true
  ssl.connect

Then when I use it I have (conn has the persistent connection) :

  (0..10).each do
    begin
      conn[:ssl].write("something")
      conn[:ssl].flush
      conn[:socket].flush

      break
    rescue OpenSSL::SSL::SSLError => e
      self.reconnecting
    rescue Errno::EPIPE => e
      self.reconnecting
    rescue Errno::ENETDOWN => e
      self.reconnecting
    end
  end

Does that look good enough ? I get no error when the server is not
available anymore, sadly.

try ?
begin
s = TCPSocket.new(host, PORT)
ssl = OpenSSL::SSL::SSLSocket.new(s, ctx)
ssl.sync = true
ssl.sync_close = true
ssl.connect
rescue

end