mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-18 19:47:15 +01:00
Minor changes and additions.
This commit is contained in:
parent
0af137b96a
commit
65f7852c21
@ -44,6 +44,7 @@ LightObj PassiveSocket::Accept()
|
||||
// Return a null object
|
||||
return LightObj{};
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Socket(HSQUIRRELVM vm)
|
||||
{
|
||||
@ -52,10 +53,12 @@ void Register_Socket(HSQUIRRELVM vm)
|
||||
skns.Bind(_SC("Simple"),
|
||||
Class< SimpleSocket, NoConstructor< SimpleSocket > >(vm, SimpleSocketTypename::Str)
|
||||
// Properties
|
||||
.Prop(_SC("Tag"), &SimpleSocket::GetTag, &SimpleSocket::SetTag)
|
||||
.Prop(_SC("Data"), &SimpleSocket::GetData, &SimpleSocket::SetData)
|
||||
.Prop(_SC("IsValid"), &SimpleSocket::IsSocketValid)
|
||||
.Prop(_SC("ErrorDescription"), &SimpleSocket::DescribeError)
|
||||
.Prop(_SC("NonBlocking"), &SimpleSocket::IsNonBlocking)
|
||||
.Prop(_SC("Data"), &SimpleSocket::GetData)
|
||||
.Prop(_SC("InternalData"), &SimpleSocket::GetInternalData)
|
||||
.Prop(_SC("BytesReceived"), &SimpleSocket::GetBytesReceived)
|
||||
.Prop(_SC("BytesSent"), &SimpleSocket::GetBytesSent)
|
||||
.Prop(_SC("ConnectTimeoutSec"), &SimpleSocket::GetConnectTimeoutSec)
|
||||
@ -79,6 +82,7 @@ void Register_Socket(HSQUIRRELVM vm)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SimpleSocketTypename::Fn)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetTag"), &SimpleSocket::ApplyTag)
|
||||
.Func(_SC("Initialize"), &SimpleSocket::Initialize)
|
||||
.Func(_SC("Close"), &SimpleSocket::Close)
|
||||
.Func(_SC("Shutdown"), &SimpleSocket::Shutdown)
|
||||
@ -112,7 +116,7 @@ void Register_Socket(HSQUIRRELVM vm)
|
||||
DerivedClass< PassiveSocket, SimpleSocket, NoCopy< PassiveSocket > >(vm, PassiveSocketTypename::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< int >()
|
||||
.Ctor< SQInteger >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &PassiveSocketTypename::Fn)
|
||||
.Func(_SC("_tostring"), &PassiveSocket::ToString)
|
||||
@ -128,7 +132,7 @@ void Register_Socket(HSQUIRRELVM vm)
|
||||
DerivedClass< ActiveSocket, SimpleSocket, NoCopy< ActiveSocket > >(vm, ActiveSocketTypename::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< int >()
|
||||
.Ctor< SQInteger >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &ActiveSocketTypename::Fn)
|
||||
.Func(_SC("_tostring"), &ActiveSocket::ToString)
|
||||
|
@ -12,6 +12,8 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
using namespace moodycamel;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Handle validation.
|
||||
*/
|
||||
@ -21,6 +23,10 @@ namespace SqMod {
|
||||
#define SQMOD_VALIDATE(x) (x).Validate()
|
||||
#endif // _DEBUG
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
using CSimpleSocketPtr = SharedPtr< CSimpleSocket >;
|
||||
using CSimpleSocketRef = WeakPtr< CSimpleSocket >;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Provides a platform independent class to for socket development. This class is designed
|
||||
* to abstract socket communication development in a platform independent manner.
|
||||
@ -32,10 +38,21 @@ protected:
|
||||
* The managed socket instance.
|
||||
*/
|
||||
CSimpleSocket * m_Socket;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* User tag associated with this instance.
|
||||
*/
|
||||
String m_Tag;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* User data associated with this instance.
|
||||
*/
|
||||
LightObj m_Data;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor. Initializes everything to null.
|
||||
*/
|
||||
SimpleSocket() : m_Socket(nullptr) { }
|
||||
SimpleSocket()
|
||||
: m_Socket(nullptr)
|
||||
{
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor. Initializes with the given socket instance.
|
||||
*/
|
||||
@ -85,6 +102,49 @@ public:
|
||||
* Move assignment operator (disabled).
|
||||
*/
|
||||
SimpleSocket & operator = (SimpleSocket &&) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user tag.
|
||||
*/
|
||||
const String & GetTag() const
|
||||
{
|
||||
return m_Tag;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user tag.
|
||||
*/
|
||||
void SetTag(StackStrF & tag)
|
||||
{
|
||||
if (tag.mLen > 0)
|
||||
{
|
||||
m_Tag.assign(tag.mPtr, static_cast< size_t >(tag.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Tag.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user tag.
|
||||
*/
|
||||
SimpleSocket & ApplyTag(StackStrF & tag)
|
||||
{
|
||||
SetTag(tag);
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated user data.
|
||||
*/
|
||||
LightObj & GetData()
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated user data.
|
||||
*/
|
||||
void SetData(LightObj & data)
|
||||
{
|
||||
m_Data = data;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Initialize instance of CSocket. This method MUST be called before an object can be used.
|
||||
*/
|
||||
@ -130,7 +190,6 @@ public:
|
||||
SQMOD_VALIDATE(*this);
|
||||
return m_Socket->Select(static_cast< Int32 >(timeout_sec), static_cast< Int32 >(timeout_usec));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Does the current instance of the socket object contain a valid socket descriptor.
|
||||
*/
|
||||
@ -165,6 +224,7 @@ public:
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempts to receive a block of data on an established connection. Buffer cursor is not affected!
|
||||
* This is potentially broken because by the time a job is processed, another one could have override internal buffer.
|
||||
*/
|
||||
SQInteger Receive(Buffer::SzType max_bytes)
|
||||
{
|
||||
@ -242,7 +302,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns a copy of the internal buffer used to receive data. Very ineffective. Use carefully.
|
||||
*/
|
||||
SqBuffer GetData()
|
||||
SqBuffer GetInternalData()
|
||||
{
|
||||
SQMOD_VALIDATE(*this);
|
||||
return SqBuffer(reinterpret_cast< Buffer::ConstPtr >(m_Socket->GetData()),
|
||||
@ -396,7 +456,8 @@ public:
|
||||
return m_Socket->SetSendTimeout(timeout_sec, timeout_usec);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
* Returns the last error that occured for the instace of the SimpleSocket instance.
|
||||
* This method should be called immediately to retrieve the error code for the failing mehtod call.
|
||||
*/
|
||||
SQInteger GetSocketError()
|
||||
{
|
||||
@ -692,9 +753,5 @@ public:
|
||||
static_cast< size_t >(str.mLen) * (sizeof(SQChar) / sizeof(uint8_t)));
|
||||
}
|
||||
};
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -399,7 +399,7 @@ Vector4 SqBuffer::ReadVector4()
|
||||
void Register_Buffer(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(Typename::Str,
|
||||
Class< SqBuffer >(vm, Typename::Str)
|
||||
Class< SqBuffer, NoCopy< SqBuffer > >(vm, Typename::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SQInteger >()
|
||||
|
@ -786,7 +786,7 @@ public:
|
||||
/// \param ptr Should be the return value from a call to the new operator
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
SharedPtr(T* ptr)
|
||||
explicit SharedPtr(T* ptr)
|
||||
: m_Ptr(NULL)
|
||||
, m_Ref(NULL)
|
||||
{
|
||||
@ -802,7 +802,7 @@ public:
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class U>
|
||||
SharedPtr(U* ptr)
|
||||
explicit SharedPtr(U* ptr)
|
||||
: m_Ptr(NULL)
|
||||
, m_Ref(NULL)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user