mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 03:57:14 +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 a null object
|
||||||
return LightObj{};
|
return LightObj{};
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================================================================================
|
// ================================================================================================
|
||||||
void Register_Socket(HSQUIRRELVM vm)
|
void Register_Socket(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
@ -52,10 +53,12 @@ void Register_Socket(HSQUIRRELVM vm)
|
|||||||
skns.Bind(_SC("Simple"),
|
skns.Bind(_SC("Simple"),
|
||||||
Class< SimpleSocket, NoConstructor< SimpleSocket > >(vm, SimpleSocketTypename::Str)
|
Class< SimpleSocket, NoConstructor< SimpleSocket > >(vm, SimpleSocketTypename::Str)
|
||||||
// Properties
|
// Properties
|
||||||
|
.Prop(_SC("Tag"), &SimpleSocket::GetTag, &SimpleSocket::SetTag)
|
||||||
|
.Prop(_SC("Data"), &SimpleSocket::GetData, &SimpleSocket::SetData)
|
||||||
.Prop(_SC("IsValid"), &SimpleSocket::IsSocketValid)
|
.Prop(_SC("IsValid"), &SimpleSocket::IsSocketValid)
|
||||||
.Prop(_SC("ErrorDescription"), &SimpleSocket::DescribeError)
|
.Prop(_SC("ErrorDescription"), &SimpleSocket::DescribeError)
|
||||||
.Prop(_SC("NonBlocking"), &SimpleSocket::IsNonBlocking)
|
.Prop(_SC("NonBlocking"), &SimpleSocket::IsNonBlocking)
|
||||||
.Prop(_SC("Data"), &SimpleSocket::GetData)
|
.Prop(_SC("InternalData"), &SimpleSocket::GetInternalData)
|
||||||
.Prop(_SC("BytesReceived"), &SimpleSocket::GetBytesReceived)
|
.Prop(_SC("BytesReceived"), &SimpleSocket::GetBytesReceived)
|
||||||
.Prop(_SC("BytesSent"), &SimpleSocket::GetBytesSent)
|
.Prop(_SC("BytesSent"), &SimpleSocket::GetBytesSent)
|
||||||
.Prop(_SC("ConnectTimeoutSec"), &SimpleSocket::GetConnectTimeoutSec)
|
.Prop(_SC("ConnectTimeoutSec"), &SimpleSocket::GetConnectTimeoutSec)
|
||||||
@ -79,6 +82,7 @@ void Register_Socket(HSQUIRRELVM vm)
|
|||||||
// Meta-methods
|
// Meta-methods
|
||||||
.SquirrelFunc(_SC("_typename"), &SimpleSocketTypename::Fn)
|
.SquirrelFunc(_SC("_typename"), &SimpleSocketTypename::Fn)
|
||||||
// Member Methods
|
// Member Methods
|
||||||
|
.FmtFunc(_SC("SetTag"), &SimpleSocket::ApplyTag)
|
||||||
.Func(_SC("Initialize"), &SimpleSocket::Initialize)
|
.Func(_SC("Initialize"), &SimpleSocket::Initialize)
|
||||||
.Func(_SC("Close"), &SimpleSocket::Close)
|
.Func(_SC("Close"), &SimpleSocket::Close)
|
||||||
.Func(_SC("Shutdown"), &SimpleSocket::Shutdown)
|
.Func(_SC("Shutdown"), &SimpleSocket::Shutdown)
|
||||||
@ -112,7 +116,7 @@ void Register_Socket(HSQUIRRELVM vm)
|
|||||||
DerivedClass< PassiveSocket, SimpleSocket, NoCopy< PassiveSocket > >(vm, PassiveSocketTypename::Str)
|
DerivedClass< PassiveSocket, SimpleSocket, NoCopy< PassiveSocket > >(vm, PassiveSocketTypename::Str)
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< int >()
|
.Ctor< SQInteger >()
|
||||||
// Meta-methods
|
// Meta-methods
|
||||||
.SquirrelFunc(_SC("_typename"), &PassiveSocketTypename::Fn)
|
.SquirrelFunc(_SC("_typename"), &PassiveSocketTypename::Fn)
|
||||||
.Func(_SC("_tostring"), &PassiveSocket::ToString)
|
.Func(_SC("_tostring"), &PassiveSocket::ToString)
|
||||||
@ -128,7 +132,7 @@ void Register_Socket(HSQUIRRELVM vm)
|
|||||||
DerivedClass< ActiveSocket, SimpleSocket, NoCopy< ActiveSocket > >(vm, ActiveSocketTypename::Str)
|
DerivedClass< ActiveSocket, SimpleSocket, NoCopy< ActiveSocket > >(vm, ActiveSocketTypename::Str)
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< int >()
|
.Ctor< SQInteger >()
|
||||||
// Meta-methods
|
// Meta-methods
|
||||||
.SquirrelFunc(_SC("_typename"), &ActiveSocketTypename::Fn)
|
.SquirrelFunc(_SC("_typename"), &ActiveSocketTypename::Fn)
|
||||||
.Func(_SC("_tostring"), &ActiveSocket::ToString)
|
.Func(_SC("_tostring"), &ActiveSocket::ToString)
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
|
using namespace moodycamel;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Handle validation.
|
* Handle validation.
|
||||||
*/
|
*/
|
||||||
@ -21,6 +23,10 @@ namespace SqMod {
|
|||||||
#define SQMOD_VALIDATE(x) (x).Validate()
|
#define SQMOD_VALIDATE(x) (x).Validate()
|
||||||
#endif // _DEBUG
|
#endif // _DEBUG
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
using CSimpleSocketPtr = SharedPtr< CSimpleSocket >;
|
||||||
|
using CSimpleSocketRef = WeakPtr< CSimpleSocket >;
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
* Provides a platform independent class to for socket development. This class is designed
|
* Provides a platform independent class to for socket development. This class is designed
|
||||||
* to abstract socket communication development in a platform independent manner.
|
* to abstract socket communication development in a platform independent manner.
|
||||||
@ -32,10 +38,21 @@ protected:
|
|||||||
* The managed socket instance.
|
* The managed socket instance.
|
||||||
*/
|
*/
|
||||||
CSimpleSocket * m_Socket;
|
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.
|
* Default constructor. Initializes everything to null.
|
||||||
*/
|
*/
|
||||||
SimpleSocket() : m_Socket(nullptr) { }
|
SimpleSocket()
|
||||||
|
: m_Socket(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
/* --------------------------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------------------------
|
||||||
* Explicit constructor. Initializes with the given socket instance.
|
* Explicit constructor. Initializes with the given socket instance.
|
||||||
*/
|
*/
|
||||||
@ -85,6 +102,49 @@ public:
|
|||||||
* Move assignment operator (disabled).
|
* Move assignment operator (disabled).
|
||||||
*/
|
*/
|
||||||
SimpleSocket & operator = (SimpleSocket &&) = delete;
|
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.
|
* Initialize instance of CSocket. This method MUST be called before an object can be used.
|
||||||
*/
|
*/
|
||||||
@ -130,7 +190,6 @@ public:
|
|||||||
SQMOD_VALIDATE(*this);
|
SQMOD_VALIDATE(*this);
|
||||||
return m_Socket->Select(static_cast< Int32 >(timeout_sec), static_cast< Int32 >(timeout_usec));
|
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.
|
* 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!
|
* 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)
|
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.
|
* Returns a copy of the internal buffer used to receive data. Very ineffective. Use carefully.
|
||||||
*/
|
*/
|
||||||
SqBuffer GetData()
|
SqBuffer GetInternalData()
|
||||||
{
|
{
|
||||||
SQMOD_VALIDATE(*this);
|
SQMOD_VALIDATE(*this);
|
||||||
return SqBuffer(reinterpret_cast< Buffer::ConstPtr >(m_Socket->GetData()),
|
return SqBuffer(reinterpret_cast< Buffer::ConstPtr >(m_Socket->GetData()),
|
||||||
@ -396,7 +456,8 @@ public:
|
|||||||
return m_Socket->SetSendTimeout(timeout_sec, timeout_usec);
|
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()
|
SQInteger GetSocketError()
|
||||||
{
|
{
|
||||||
@ -692,9 +753,5 @@ public:
|
|||||||
static_cast< size_t >(str.mLen) * (sizeof(SQChar) / sizeof(uint8_t)));
|
static_cast< size_t >(str.mLen) * (sizeof(SQChar) / sizeof(uint8_t)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// ------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // Namespace:: SqMod
|
} // Namespace:: SqMod
|
||||||
|
@ -399,7 +399,7 @@ Vector4 SqBuffer::ReadVector4()
|
|||||||
void Register_Buffer(HSQUIRRELVM vm)
|
void Register_Buffer(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
RootTable(vm).Bind(Typename::Str,
|
RootTable(vm).Bind(Typename::Str,
|
||||||
Class< SqBuffer >(vm, Typename::Str)
|
Class< SqBuffer, NoCopy< SqBuffer > >(vm, Typename::Str)
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
.Ctor< SQInteger >()
|
.Ctor< SQInteger >()
|
||||||
|
@ -786,7 +786,7 @@ public:
|
|||||||
/// \param ptr Should be the return value from a call to the new operator
|
/// \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_Ptr(NULL)
|
||||||
, m_Ref(NULL)
|
, m_Ref(NULL)
|
||||||
{
|
{
|
||||||
@ -802,7 +802,7 @@ public:
|
|||||||
///
|
///
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
template <class U>
|
template <class U>
|
||||||
SharedPtr(U* ptr)
|
explicit SharedPtr(U* ptr)
|
||||||
: m_Ptr(NULL)
|
: m_Ptr(NULL)
|
||||||
, m_Ref(NULL)
|
, m_Ref(NULL)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user