1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-03-18 18:17:14 +01:00

Compare commits

..

No commits in common. "3e75e36cdf724d4f6f50d479114dd9d769308a39" and "5a57bf2fbfbf4aab0dba45ff7c8506462b6001c3" have entirely different histories.

4 changed files with 33 additions and 77 deletions

View File

@ -285,13 +285,13 @@ public:
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host an element of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host an element of size (%u)"),
m_Cap, sizeof(T));
}
// Make sure that the specified element is withing buffer range
else if (n > (m_Cap - sizeof(T)))
{
ThrowMemExcept(fmt::runtime("Element of size ({}) at index ({}) is out of buffer capacity ({})"),
ThrowMemExcept(fmt::runtime("Element of size (%d) at index (%u) is out of buffer capacity (%u)"),
sizeof(T), n, m_Cap);
}
// Return the requested element
@ -306,13 +306,13 @@ public:
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host an element of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host an element of size (%u)"),
m_Cap, sizeof(T));
}
// Make sure that the specified element is withing buffer range
else if (n > (m_Cap - sizeof(T)))
{
ThrowMemExcept(fmt::runtime("Element of size ({}) at index ({}) is out of buffer capacity ({})"),
ThrowMemExcept(fmt::runtime("Element of size (%d) at index (%u) is out of buffer capacity (%u)"),
sizeof(T), n, m_Cap);
}
// Return the requested element
@ -359,7 +359,7 @@ public:
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host an element of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host an element of size (%u)"),
m_Cap, sizeof(T));
}
// Return the requested element
@ -374,7 +374,7 @@ public:
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host an element of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host an element of size (%u)"),
m_Cap, sizeof(T));
}
// Return the requested element
@ -389,7 +389,7 @@ public:
// Make sure that the buffer can host at least two elements of this type
if (m_Cap < (sizeof(T) * 2))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host two elements of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host two elements of size (%u)"),
m_Cap, sizeof(T));
}
// Return the requested element
@ -404,7 +404,7 @@ public:
// Make sure that the buffer can host at least two elements of this type
if (m_Cap < (sizeof(T) * 2))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host two elements of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host two elements of size (%u)"),
m_Cap, sizeof(T));
}
// Return the requested element
@ -419,7 +419,7 @@ public:
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host an element of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host an element of size (%u)"),
m_Cap, sizeof(T));
}
// Return the requested element
@ -434,7 +434,7 @@ public:
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host an element of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host an element of size (%u)"),
m_Cap, sizeof(T));
}
// Return the requested element
@ -449,7 +449,7 @@ public:
// Make sure that the buffer can host at least two elements of this type
if (m_Cap < (sizeof(T) * 2))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host two elements of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host two elements of size (%u)"),
m_Cap, sizeof(T));
}
// Return the requested element
@ -464,7 +464,7 @@ public:
// Make sure that the buffer can host at least two elements of this type
if (m_Cap < (sizeof(T) * 2))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host two elements of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host two elements of size (%u)"),
m_Cap, sizeof(T));
}
// Return the requested element
@ -540,7 +540,7 @@ public:
// Make sure that at least one element of this type exists after the cursor
if ((m_Cur + sizeof(T)) > m_Cap)
{
ThrowMemExcept(fmt::runtime("Element of size ({}) starting at ({}) exceeds buffer capacity ({})"),
ThrowMemExcept(fmt::runtime("Element of size (%u) starting at (%u) exceeds buffer capacity (%u)"),
sizeof(T), m_Cur, m_Cap);
}
// Return the requested element
@ -555,7 +555,7 @@ public:
// Make sure that at least one element of this type exists after the cursor
if ((m_Cur + sizeof(T)) > m_Cap)
{
ThrowMemExcept(fmt::runtime("Element of size ({}) starting at ({}) exceeds buffer capacity ({})"),
ThrowMemExcept(fmt::runtime("Element of size (%u) starting at (%u) exceeds buffer capacity (%u)"),
sizeof(T), m_Cur, m_Cap);
}
// Return the requested element
@ -570,7 +570,7 @@ public:
// The cursor must have at least one element of this type behind
if (m_Cur < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Cannot read an element of size ({}) before the cursor at ({})"),
ThrowMemExcept(fmt::runtime("Cannot read an element of size (%u) before the cursor at (%u)"),
sizeof(T), m_Cur);
}
// Return the requested element
@ -585,7 +585,7 @@ public:
// The cursor must have at least one element of this type behind
if (m_Cur < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Cannot read an element of size ({}) before the cursor at ({})"),
ThrowMemExcept(fmt::runtime("Cannot read an element of size (%u) before the cursor at (%u)"),
sizeof(T), m_Cur);
}
// Return the requested element
@ -600,13 +600,13 @@ public:
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host an element of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host an element of size (%u)"),
m_Cap, sizeof(T));
}
// There must be buffer left for at least two elements of this type after the cursor
else if ((m_Cur + (sizeof(T) * 2)) > m_Cap)
{
ThrowMemExcept(fmt::runtime("Element of size ({}) starting at ({}) exceeds buffer capacity ({})"),
ThrowMemExcept(fmt::runtime("Element of size (%u) starting at (%u) exceeds buffer capacity (%u)"),
sizeof(T), m_Cur + sizeof(T), m_Cap);
}
// Return the requested element
@ -621,13 +621,13 @@ public:
// Make sure that the buffer can host at least one element of this type
if (m_Cap < sizeof(T))
{
ThrowMemExcept(fmt::runtime("Buffer capacity of ({}) is unable to host an element of size ({})"),
ThrowMemExcept(fmt::runtime("Buffer capacity of (%u) is unable to host an element of size (%u)"),
m_Cap, sizeof(T));
}
// There must be buffer left for at least two elements of this type after the cursor
else if ((m_Cur + (sizeof(T) * 2)) > m_Cap)
{
ThrowMemExcept(fmt::runtime("Element of size ({}) starting at ({}) exceeds buffer capacity ({})"),
ThrowMemExcept(fmt::runtime("Element of size (%u) starting at (%u) exceeds buffer capacity (%u)"),
sizeof(T), m_Cur + sizeof(T), m_Cap);
}
// Return the requested element
@ -708,7 +708,7 @@ public:
// See if the requested capacity doesn't exceed the limit
if (n > Max< T >())
{
ThrowMemExcept(fmt::runtime("Requested buffer of ({}) elements exceeds the ({}) limit"), n, Max< T >());
ThrowMemExcept(fmt::runtime("Requested buffer of (%u) elements exceeds the (%u) limit"), n, Max< T >());
}
// Is there an existing buffer?
else if (n && !m_Cap)

View File

@ -294,41 +294,33 @@ public:
/* --------------------------------------------------------------------------------------------
* Reposition the edit cursor to the specified number of elements ahead.
*/
SqBuffer & Advance(SQInteger n)
void Advance(SQInteger n) const
{
Valid().Advance(ConvTo< SzType >::From(n));
// Allow chaining
return *this;
}
/* --------------------------------------------------------------------------------------------
* Reposition the edit cursor to the specified number of elements behind.
*/
SqBuffer & Retreat(SQInteger n)
void Retreat(SQInteger n) const
{
Valid().Retreat(ConvTo< SzType >::From(n));
// Allow chaining
return *this;
}
/* --------------------------------------------------------------------------------------------
* Reposition the edit cursor to a fixed position within the buffer.
*/
SqBuffer & Move(SQInteger n)
void Move(SQInteger n) const
{
Valid().Move(ConvTo< SzType >::From(n));
// Allow chaining
return *this;
}
/* --------------------------------------------------------------------------------------------
* Append a value to the current cursor location and advance the cursor.
*/
SqBuffer & Push(SQInteger v)
void Push(SQInteger v) const
{
Valid().Push(ConvTo< Value >::From(v));
// Allow chaining
return *this;
}
/* --------------------------------------------------------------------------------------------
@ -422,17 +414,15 @@ public:
/* --------------------------------------------------------------------------------------------
* Grow the size of the internal buffer by the specified amount of bytes.
*/
SqBuffer & Grow(SQInteger n)
void Grow(SQInteger n) const
{
Valid().Grow(ConvTo< SzType >::From(n) * sizeof(Value));
// Allow chaining
return *this;
return Valid().Grow(ConvTo< SzType >::From(n) * sizeof(Value));
}
/* --------------------------------------------------------------------------------------------
* Makes sure there is enough capacity to hold the specified element count.
*/
SqBuffer & Adjust(SQInteger n)
void Adjust(SQInteger n)
{
// Validate the managed buffer reference
Validate();
@ -448,8 +438,6 @@ public:
{
STHROWF("{}", e.what()); // Re-package
}
// Allow chaining
return *this;
}
/* --------------------------------------------------------------------------------------------

View File

@ -22,8 +22,6 @@ void InitializeNet()
#endif
#ifndef NO_SSL
f |= MG_FEATURES_SSL;
#else
OutputMessage("Network compiled without SSL support.");
#endif
#ifndef NO_CGI
f |= MG_FEATURES_CGI;
@ -137,11 +135,6 @@ int WebSocketClient::DataHandler(int flags, char * data, size_t data_len) noexce
{
LogFtl("Failed to queue web-socket data");
}
// Should we auto-close the connection
if (((flags & 0xF) == MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE) && mAutoClose.load() == true)
{
return 0;
}
// Return 1 to keep the connection open
return 1;
}
@ -180,7 +173,6 @@ void Register_Net(HSQUIRRELVM vm)
.Prop(_SC("OnClose"), &WebSocketClient::GetOnClose, &WebSocketClient::SetOnClose)
.Prop(_SC("Valid"), &WebSocketClient::IsValid)
.Prop(_SC("Closing"), &WebSocketClient::IsClosing)
.Prop(_SC("AutoClose"), &WebSocketClient::GetAutoClose, &WebSocketClient::SetAutoClose)
// Member Methods
.FmtFunc(_SC("SetTag"), &WebSocketClient::ApplyTag)
.FmtFunc(_SC("SetData"), &WebSocketClient::ApplyData)

View File

@ -159,13 +159,6 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
*/
std::atomic< bool > mClosed{false};
/* --------------------------------------------------------------------------------------------
* Whether to not keep the connection open after receiving the close event.
* Internally this event is ignored but if set to true the connection is immediatelly closed
* in the internal event handler, before the event may reach the script callback.
*/
std::atomic< bool > mAutoClose{false};
/* --------------------------------------------------------------------------------------------
* Server host to connect to, i.e. "echo.websocket.org" or "192.168.1.1" or "localhost".
*/
@ -191,8 +184,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
*/
WebSocketClient()
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
, mPort(0), mSecure(false), mClosing(false), mClosed(false), mAutoClose(false)
, mHost(), mPath(), mOrigin(), mExtensions()
, mPort(0), mSecure(false), mClosing(false), mClosed(false), mHost(), mPath(), mOrigin(), mExtensions()
{
ChainInstance(); // Remember this instance
}
@ -202,7 +194,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
*/
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path)
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
, mPort(port), mSecure(false), mClosing(false), mClosed(false), mAutoClose(false)
, mPort(port), mSecure(false), mClosing(false), mClosed(false)
, mHost(host.mPtr, host.GetSize())
, mPath(path.mPtr, path.GetSize())
, mOrigin(), mExtensions()
@ -215,7 +207,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
*/
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure)
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
, mPort(port), mSecure(secure), mClosing(false), mClosed(false), mAutoClose(false)
, mPort(port), mSecure(secure), mClosing(false), mClosed(false)
, mHost(host.mPtr, host.GetSize())
, mPath(path.mPtr, path.GetSize())
, mOrigin(), mExtensions()
@ -228,7 +220,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
*/
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure, StackStrF & origin)
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
, mPort(port), mSecure(secure), mClosing(false), mClosed(false), mAutoClose(false)
, mPort(port), mSecure(secure), mClosing(false), mClosed(false)
, mHost(host.mPtr, host.GetSize())
, mPath(path.mPtr, path.GetSize())
, mOrigin(origin.mPtr, origin.GetSize())
@ -242,7 +234,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
*/
WebSocketClient(StackStrF & host, uint16_t port, StackStrF & path, bool secure, StackStrF & origin, StackStrF & ext)
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
, mPort(port), mSecure(secure), mClosing(false), mClosed(false), mAutoClose(false)
, mPort(port), mSecure(secure), mClosing(false), mClosed(false)
, mHost(host.mPtr, host.GetSize())
, mPath(path.mPtr, path.GetSize())
, mOrigin(origin.mPtr, origin.GetSize())
@ -302,22 +294,6 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
return mClosing.load();
}
/* --------------------------------------------------------------------------------------------
* Retrieve whether auto-closing is enabled or not.
*/
SQMOD_NODISCARD bool GetAutoClose() const
{
return mAutoClose.load();
}
/* --------------------------------------------------------------------------------------------
* Modify whether auto-closing is enabled or not.
*/
void SetAutoClose(bool toggle)
{
mAutoClose.store(toggle);
}
/* --------------------------------------------------------------------------------------------
* Retrieve the associated user tag.
*/