mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-03-19 18:47:14 +01:00
Compare commits
No commits in common. "5a57bf2fbfbf4aab0dba45ff7c8506462b6001c3" and "804a5abb29db14728e2d68c7bdd35e4bfe0213ed" have entirely different histories.
5a57bf2fbf
...
804a5abb29
@ -11,13 +11,6 @@
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <Poco/Checksum.h>
|
||||
#include <Poco/Base32Encoder.h>
|
||||
#include <Poco/Base32Decoder.h>
|
||||
#include <Poco/Base64Encoder.h>
|
||||
#include <Poco/Base64Decoder.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sstream>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
@ -37,7 +30,7 @@ SQInteger SqBuffer::WriteRawString(StackStrF & val) const
|
||||
}
|
||||
// Calculate the string length
|
||||
Buffer::SzType length = ConvTo< Buffer::SzType >::From(val.mLen);
|
||||
// Write the string contents
|
||||
// Write the the string contents
|
||||
m_Buffer->AppendS(val.mPtr, length);
|
||||
// Return the length of the written string
|
||||
return val.mLen;
|
||||
@ -231,7 +224,7 @@ AABB SqBuffer::ReadAABB() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< AABB >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return AABB(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -244,7 +237,7 @@ Circle SqBuffer::ReadCircle() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Circle >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Circle(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -257,7 +250,7 @@ Color3 SqBuffer::ReadColor3() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Color3 >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Color3(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -270,7 +263,7 @@ Color4 SqBuffer::ReadColor4() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Color4 >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Color4(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -283,7 +276,7 @@ Quaternion SqBuffer::ReadQuaternion() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Quaternion >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Quaternion(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -296,7 +289,7 @@ Sphere SqBuffer::ReadSphere() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Sphere >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Sphere(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -309,7 +302,7 @@ Vector2 SqBuffer::ReadVector2() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Vector2 >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Vector2(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -322,7 +315,7 @@ Vector2i SqBuffer::ReadVector2i() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Vector2i >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Vector2i(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -335,7 +328,7 @@ Vector3 SqBuffer::ReadVector3() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Vector3 >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Vector3(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -348,7 +341,7 @@ Vector4 SqBuffer::ReadVector4() const
|
||||
// Advance the buffer cursor
|
||||
m_Buffer->Advance< Vector4 >(1);
|
||||
// Return the requested information
|
||||
return {value};
|
||||
return Vector4(value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -359,7 +352,7 @@ SQInteger SqBuffer::GetCRC32(SQInteger n) const
|
||||
// Create the checksum computer
|
||||
Poco::Checksum c(Poco::Checksum::TYPE_CRC32);
|
||||
// Give it the data to process
|
||||
c.update(&m_Buffer->Cursor< char >(), ClampRemaining(n));
|
||||
c.update(&m_Buffer->Cursor< char >(), n >= 0 ? static_cast< uint32_t >(n) : m_Buffer->Remaining());
|
||||
// return the result
|
||||
return static_cast< SQInteger >(c.checksum());
|
||||
}
|
||||
@ -372,46 +365,12 @@ SQInteger SqBuffer::GetADLER32(SQInteger n) const
|
||||
// Create the checksum computer
|
||||
Poco::Checksum c(Poco::Checksum::TYPE_ADLER32);
|
||||
// Give it the data to process
|
||||
c.update(&m_Buffer->Cursor< char >(), ClampRemaining(n));
|
||||
c.update(&m_Buffer->Cursor< char >(), n >= 0 ? static_cast< uint32_t >(n) : m_Buffer->Remaining());
|
||||
// return the result
|
||||
return static_cast< SQInteger >(c.checksum());
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LightObj SqBuffer::GetBase32(SQInteger n) const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
ValidateDeeper();
|
||||
// Create a string receiver
|
||||
std::ostringstream out;
|
||||
// Create the encoder
|
||||
Poco::Base32Encoder enc(out);
|
||||
// Encode the string
|
||||
enc.write(&m_Buffer->Cursor< char >(), ClampRemaining(n));
|
||||
// Close the encoder
|
||||
enc.close();
|
||||
// Return the resulted string
|
||||
return LightObj{out.str()};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LightObj SqBuffer::GetBase64(SQInteger n) const
|
||||
{
|
||||
// Validate the managed buffer reference
|
||||
ValidateDeeper();
|
||||
// Create a string receiver
|
||||
std::ostringstream out;
|
||||
// Create the encoder
|
||||
Poco::Base64Encoder enc(out);
|
||||
// Encode the string
|
||||
enc.write(&m_Buffer->Cursor< char >(), ClampRemaining(n));
|
||||
// Close the encoder
|
||||
enc.close();
|
||||
// Return the resulted string
|
||||
return LightObj{out.str()};
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Buffer(HSQUIRRELVM vm)
|
||||
{
|
||||
@ -498,8 +457,6 @@ void Register_Buffer(HSQUIRRELVM vm)
|
||||
.Func(_SC("ReadVector4"), &SqBuffer::ReadVector4)
|
||||
.Func(_SC("CRC32"), &SqBuffer::GetCRC32)
|
||||
.Func(_SC("ADLER32"), &SqBuffer::GetADLER32)
|
||||
.Func(_SC("Base32"), &SqBuffer::GetBase32)
|
||||
.Func(_SC("Base64"), &SqBuffer::GetBase64)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -193,24 +193,6 @@ public:
|
||||
return *m_Buffer;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Limit the specified amount at to the range of the cursor and the end of the buffer.
|
||||
*/
|
||||
SQMOD_NODISCARD SzType ClampRemaining(SQInteger n) const
|
||||
{
|
||||
// Do we even specify a buffer amount?
|
||||
if (n >= 0)
|
||||
{
|
||||
// Is it within the range we currently have left?
|
||||
if (static_cast< SzType >(n) <= m_Buffer->Remaining())
|
||||
{
|
||||
return static_cast< SzType >(n);
|
||||
}
|
||||
}
|
||||
// Fall back to the actual remaining data
|
||||
return m_Buffer->Remaining();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a certain element type at the specified position.
|
||||
*/
|
||||
@ -779,16 +761,6 @@ public:
|
||||
* Compute the Adler-32 checksums on the data in the buffer.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetADLER32(SQInteger n) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Encode the specified range of data as base32 and return it.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj GetBase32(SQInteger n) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Encode the specified range of data as base64 and return it.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj GetBase64(SQInteger n) const;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -89,9 +89,6 @@ WebSocketClient & WebSocketClient::Connect()
|
||||
{
|
||||
STHROWF("Connection failed: {}", err_buf);
|
||||
}
|
||||
// Reset memebrs
|
||||
mClosing.store(false);
|
||||
mClosed.store(false);
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
@ -116,9 +113,6 @@ WebSocketClient & WebSocketClient::ConnectExt()
|
||||
{
|
||||
STHROWF("Connection failed: {}", err_buf);
|
||||
}
|
||||
// Reset memebrs
|
||||
mClosing.store(false);
|
||||
mClosed.store(false);
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
|
@ -154,11 +154,6 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
||||
*/
|
||||
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".
|
||||
*/
|
||||
@ -184,7 +179,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
||||
*/
|
||||
WebSocketClient()
|
||||
: Base(), mHandle(nullptr), mQueue(1024), mOnData(), mOnClose(), mTag(), mData()
|
||||
, mPort(0), mSecure(false), mClosing(false), mClosed(false), mHost(), mPath(), mOrigin(), mExtensions()
|
||||
, mPort(0), mSecure(false), mClosing(false), mHost(), mPath(), mOrigin(), mExtensions()
|
||||
{
|
||||
ChainInstance(); // Remember this instance
|
||||
}
|
||||
@ -194,7 +189,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)
|
||||
, mPort(port), mSecure(false), mClosing(false)
|
||||
, mHost(host.mPtr, host.GetSize())
|
||||
, mPath(path.mPtr, path.GetSize())
|
||||
, mOrigin(), mExtensions()
|
||||
@ -207,7 +202,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)
|
||||
, mPort(port), mSecure(secure), mClosing(false)
|
||||
, mHost(host.mPtr, host.GetSize())
|
||||
, mPath(path.mPtr, path.GetSize())
|
||||
, mOrigin(), mExtensions()
|
||||
@ -220,7 +215,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)
|
||||
, mPort(port), mSecure(secure), mClosing(false)
|
||||
, mHost(host.mPtr, host.GetSize())
|
||||
, mPath(path.mPtr, path.GetSize())
|
||||
, mOrigin(origin.mPtr, origin.GetSize())
|
||||
@ -234,7 +229,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)
|
||||
, mPort(port), mSecure(secure), mClosing(false)
|
||||
, mHost(host.mPtr, host.GetSize())
|
||||
, mPath(path.mPtr, path.GetSize())
|
||||
, mOrigin(origin.mPtr, origin.GetSize())
|
||||
@ -653,7 +648,7 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Sends the contents of the given buffer through the socket as a single frame.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger SendOpCode(SQInteger opcode)
|
||||
SQMOD_NODISCARD SQInteger SendOpCode(SqBuffer & buf, SQInteger opcode)
|
||||
{
|
||||
return mg_websocket_client_write(Valid(), static_cast< int >(opcode), nullptr, 0);
|
||||
}
|
||||
@ -711,12 +706,9 @@ struct WebSocketClient : public SqChainedInstances< WebSocketClient >
|
||||
}
|
||||
}
|
||||
// Is the server closing the connection?
|
||||
if (closing && !mClosed.load() && !mOnClose.IsNull())
|
||||
if (closing && !mOnClose.IsNull())
|
||||
{
|
||||
// Let the user know
|
||||
mOnClose.Execute();
|
||||
// Prevent calling this callback again
|
||||
mClosed.store(true);
|
||||
mOnClose.Execute(); // Let the user know
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,15 +88,6 @@ struct LightObj {
|
||||
sq_addref(SqVM(), &mObj);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Constructs a LightObj from a string object
|
||||
///
|
||||
/// \param o Squirrel object
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
explicit LightObj(const string & s) : LightObj(s.c_str(), static_cast< SQInteger >(s.size())) {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Constructs a LightObj from a Squirrel object at a certain index on the stack
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user