[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Processing the errorArray-subset returned by IO.select

Sebastien Raveau

3/4/2009 9:38:00 PM

Hi everybody!


I am posting my question to this list really as a last recourse after
having duly searched Ruby's doc, Google, Ruby's source, IRC, etc...
Can somebody please end my torment?

What I'm trying to achieve is a fully asynchronous HTTP proxy (or, for
the sake of simplicity let's just say a TCP relay between A and B) in
just one thread, meaning:
* when I non-blockingly (select+accept) get a new connection from A, I
have to open the relay connection to B using connect_nonblock
* upon "readable" events on sockets belonging to either A or B, I must
non-blockingly write() to the other (or cache the data and wait for
the other socket to be "writable")
* have to teardown the relay as soon as any side shows signs of
connect timeout, close, reset, etc

Now, in order to monitor socket status I cannot rely on
begin/rescue/end (actually I found a tutorial where the author calls
connect_nonblock a second time and checks EISCONN to see if the socket
connection was successful, but that's not the best way to do it, is
it?), so I thought my answer was in the third array returned by
select, concerning socket errors/exceptions... but I cannot find any
documentation on that, and everybody seems to call IO.select() with
'nil' as third argument :-/

Does anybody know how to process it? Is there a way to get the
corresponding Errno for each socket?


Thank you :-)

--
Sebastien Raveau
C old-timer learning Ruby ;-)