ircbot: fix reconnect() waiting
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 15 Jan 2009 19:30:06 +0000 (20:30 +0100)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 15 Jan 2009 19:57:31 +0000 (20:57 +0100)
commit929205f7c7e94daf83f6d762ff7614753cfaa712
treecf0d1dbe27bd262636687211760acabff2a1093f
parent4a9285ca12580656a8269c16e90e2bcd9374ae74
ircbot: fix reconnect() waiting

The refactored reconnect() method would only wait when the socket was
connected at the time it got called. In case where the socket would have
closed earlier (e.g. because of a network I/O error) it would reconnect
directly, which would for example fail to prevent fast reconnections.

Fix by fencing the wait code with a check for @last_rec (checked before the
optional disconnect) rather than keeping it with the socket connect check,
and always initializing @last_rec on socket connect.

A side effect of this strategy is that reconnect() will only wait if the bot
was previously connect, or if it got disconnected by anything but the
disconnect() method. Callers of disconnect() should take care of waiting
themselves if they plan to reconnect.
lib/rbot/ircbot.rb