Fix double ready bug for channel, fixes #25

This commit is contained in:
Martijn Otto 2015-05-18 10:56:50 +02:00
parent 7ae4f9c5ff
commit a93b88697d
2 changed files with 32 additions and 28 deletions

View File

@ -76,6 +76,7 @@ private:
*/ */
enum { enum {
state_connected, state_connected,
state_ready,
state_closing, state_closing,
state_closed state_closed
} _state = state_closed; } _state = state_closed;
@ -171,7 +172,7 @@ public:
_readyCallback = callback; _readyCallback = callback;
// direct call if channel is already ready // direct call if channel is already ready
if (_state == state_connected) callback(); if (_state == state_ready) callback();
} }
/** /**
@ -188,7 +189,7 @@ public:
_errorCallback = callback; _errorCallback = callback;
// direct call if channel is already in error state // direct call if channel is already in error state
if (_state != state_connected) callback("Channel is in error state"); if (!connected()) callback("Channel is in error state");
} }
/** /**
@ -217,7 +218,7 @@ public:
*/ */
bool connected() bool connected()
{ {
return _state == state_connected; return _state == state_connected || _state == state_ready;
} }
/** /**
@ -541,6 +542,9 @@ public:
// callbacks could destroy us, so monitor it // callbacks could destroy us, so monitor it
Monitor monitor(this); Monitor monitor(this);
// if we are still in connected state we are now ready
if (_state == state_connected) _state = state_ready;
// inform handler // inform handler
if (_readyCallback) _readyCallback(); if (_readyCallback) _readyCallback();

View File

@ -192,7 +192,7 @@ Deferred &ChannelImpl::rollbackTransaction()
Deferred &ChannelImpl::close() Deferred &ChannelImpl::close()
{ {
// this is completely pointless if not connected // this is completely pointless if not connected
if (_state != state_connected) return push(std::make_shared<Deferred>(_state == state_closing)); if (!connected()) return push(std::make_shared<Deferred>(_state == state_closing));
// send a channel close frame // send a channel close frame
auto &handler = push(ChannelCloseFrame(_id)); auto &handler = push(ChannelCloseFrame(_id));