mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Prevent double closing event in web-sockets.
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
This commit is contained in:
parent
15e85f1394
commit
5a57bf2fbf
@ -89,6 +89,9 @@ WebSocketClient & WebSocketClient::Connect()
|
|||||||
{
|
{
|
||||||
STHROWF("Connection failed: {}", err_buf);
|
STHROWF("Connection failed: {}", err_buf);
|
||||||
}
|
}
|
||||||
|
// Reset memebrs
|
||||||
|
mClosing.store(false);
|
||||||
|
mClosed.store(false);
|
||||||
// Allow chaining
|
// Allow chaining
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -113,6 +116,9 @@ WebSocketClient & WebSocketClient::ConnectExt()
|
|||||||
{
|
{
|
||||||
STHROWF("Connection failed: {}", err_buf);
|
STHROWF("Connection failed: {}", err_buf);
|
||||||
}
|
}
|
||||||
|
// Reset memebrs
|
||||||
|
mClosing.store(false);
|
||||||
|
mClosed.store(false);
|
||||||
// Allow chaining
|
// Allow chaining
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -154,6 +154,11 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
|||||||
*/
|
*/
|
||||||
std::atomic< bool > mClosing{false};
|
std::atomic< bool > mClosing{false};
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------
|
||||||
|
* Whether the closing callback was inoked (avoid recursive calls).
|
||||||
|
*/
|
||||||
|
std::atomic< bool > mClosed{false};
|
||||||
|
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Server host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or "localhost".
|
* Server host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or "localhost".
|
||||||
*/
|
*/
|
||||||
@ -179,7 +184,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
|||||||
*/
|
*/
|
||||||
WebSocketClient()
|
WebSocketClient()
|
||||||
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
||||||
, mPort(0), mSecure(false), mClosing(false), mHost(), mPath(), mOrigin(), mExtensions()
|
, mPort(0), mSecure(false), mClosing(false), mClosed(false), mHost(), mPath(), mOrigin(), mExtensions()
|
||||||
{
|
{
|
||||||
ChainInstance(); // Remember this instance
|
ChainInstance(); // Remember this instance
|
||||||
}
|
}
|
||||||
@ -189,7 +194,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
|||||||
*/
|
*/
|
||||||
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path)
|
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path)
|
||||||
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
||||||
, mPort(port), mSecure(false), mClosing(false)
|
, mPort(port), mSecure(false), mClosing(false), mClosed(false)
|
||||||
, mHost(host.mPtr, host.GetSize())
|
, mHost(host.mPtr, host.GetSize())
|
||||||
, mPath(path.mPtr, path.GetSize())
|
, mPath(path.mPtr, path.GetSize())
|
||||||
, mOrigin(), mExtensions()
|
, mOrigin(), mExtensions()
|
||||||
@ -202,7 +207,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
|||||||
*/
|
*/
|
||||||
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure)
|
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure)
|
||||||
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
||||||
, mPort(port), mSecure(secure), mClosing(false)
|
, mPort(port), mSecure(secure), mClosing(false), mClosed(false)
|
||||||
, mHost(host.mPtr, host.GetSize())
|
, mHost(host.mPtr, host.GetSize())
|
||||||
, mPath(path.mPtr, path.GetSize())
|
, mPath(path.mPtr, path.GetSize())
|
||||||
, mOrigin(), mExtensions()
|
, mOrigin(), mExtensions()
|
||||||
@ -215,7 +220,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
|||||||
*/
|
*/
|
||||||
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure, StackStrF & origin)
|
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure, StackStrF & origin)
|
||||||
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
||||||
, mPort(port), mSecure(secure), mClosing(false)
|
, mPort(port), mSecure(secure), mClosing(false), mClosed(false)
|
||||||
, mHost(host.mPtr, host.GetSize())
|
, mHost(host.mPtr, host.GetSize())
|
||||||
, mPath(path.mPtr, path.GetSize())
|
, mPath(path.mPtr, path.GetSize())
|
||||||
, mOrigin(origin.mPtr, origin.GetSize())
|
, mOrigin(origin.mPtr, origin.GetSize())
|
||||||
@ -229,7 +234,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
|||||||
*/
|
*/
|
||||||
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure, StackStrF & origin, StackStrF & ext)
|
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure, StackStrF & origin, StackStrF & ext)
|
||||||
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
||||||
, mPort(port), mSecure(secure), mClosing(false)
|
, mPort(port), mSecure(secure), mClosing(false), mClosed(false)
|
||||||
, mHost(host.mPtr, host.GetSize())
|
, mHost(host.mPtr, host.GetSize())
|
||||||
, mPath(path.mPtr, path.GetSize())
|
, mPath(path.mPtr, path.GetSize())
|
||||||
, mOrigin(origin.mPtr, origin.GetSize())
|
, mOrigin(origin.mPtr, origin.GetSize())
|
||||||
@ -706,9 +711,12 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Is the server closing the connection?
|
// Is the server closing the connection?
|
||||||
if (closing && !mOnClose.IsNull())
|
if (closing && !mClosed.load() && !mOnClose.IsNull())
|
||||||
{
|
{
|
||||||
mOnClose.Execute(); // Let the user know
|
// Let the user know
|
||||||
|
mOnClose.Execute();
|
||||||
|
// Prevent calling this callback again
|
||||||
|
mClosed.store(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user