Rafael Sevilla
2009-Jan-13 23:23 UTC
[Eventmachine-talk] timing out if the peer does not respond
Basically, I want to be able to work around peers that don''t quite respond as expected, without disconnecting from them (if you must know why I''m after this functionality, I''ve wrote some code that allows EventMachine to communicate over a serial port, and I want to be able to reset the modem if it doesn''t respond to an AT command in a timely fashion, although I do imagine there are some cases where this sort of behavior might be useful in other contexts as well). I''ve managed to hack together a solution which involves using a Deferrable, basically I have a deferrable set up in post_init, with an errback that performs the actions I expect to perform on a timeout timeout. Whenever protocol data units are sent over the wire expecting a response, the Deferrable gets a timeout attached to it. Whenever protocol data units are received over the wire, the Deferrable''s timeout is cancelled. It works, from my testing and simulations, although it is to my mind somewhat inelegant. Is there a cleaner way of achieving this behavior? -- I am the bone of my sword. Steel is my body, and fire is my blood. I have created over a thousand blades. Unaware of loss. Nor aware of gain. Withstood pain to create many weapons. Waiting for one''s arrival. I have no regrets, this is the only path. My whole life was Unlimited Blade Works. http://stormwyrm.blogspot.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 197 bytes Desc: not available URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20090114/a971899c/attachment.bin>
Roger Pack
2009-Jan-14 04:34 UTC
[Eventmachine-talk] timing out if the peer does not respond
So you want to basically timeout a peer not sending for awhile, right? I would probably have done what you did, just using a timer that fires after x seconds on lack of input. And reset it on input. I''m not sure if EM::Timer has reset functionality or if that''s a ticket on the tracker...not sure. Good luck! -=r On Wed, Jan 14, 2009 at 4:23 AM, Rafael Sevilla <dido at imperium.ph> wrote:> Basically, I want to be able to work around peers that don''t quite > respond as expected, without disconnecting from them (if you must know > why I''m after this functionality, I''ve wrote some code that allows > EventMachine to communicate over a serial port, and I want to be able to > reset the modem if it doesn''t respond to an AT command in a timely > fashion, although I do imagine there are some cases where this sort of > behavior might be useful in other contexts as well). > > I''ve managed to hack together a solution which involves using a > Deferrable, basically I have a deferrable set up in post_init, with an > errback that performs the actions I expect to perform on a > timeout timeout. Whenever protocol data units are sent over the wire > expecting a response, the Deferrable gets a timeout attached to it. > Whenever protocol data units are received over the wire, the > Deferrable''s timeout is cancelled. It works, from my testing and > simulations, although it is to my mind somewhat inelegant. Is there a > cleaner way of achieving this behavior? > > -- > I am the bone of my sword. Steel is my body, and fire is my blood. I > have created over a thousand blades. Unaware of loss. Nor aware of gain. > Withstood pain to create many weapons. Waiting for one''s arrival. I have > no regrets, this is the only path. My whole life was Unlimited Blade > Works. http://stormwyrm.blogspot.com > > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk >-- 2 Timothy 1:7