OpenSSL / Persistent connection

F

Fabien Penso

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

He Yyyy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top