2016-03-10 04:57:13 +01:00
|
|
|
#ifndef _SQMMDB_SOCKADDR_HPP_
|
|
|
|
#define _SQMMDB_SOCKADDR_HPP_
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Common.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
|
|
* Class that can obtain information from string addresses and be used repeatedly thereafter.
|
|
|
|
*/
|
|
|
|
class SockAddr
|
|
|
|
{
|
2016-11-14 14:46:48 +01:00
|
|
|
public:
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef struct addrinfo Type; // The managed type.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Type* Pointer; // Pointer to the managed type.
|
|
|
|
typedef const Type* ConstPtr; // Constant pointer to the managed type.
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
typedef Type& Reference; // Reference to the managed type.
|
|
|
|
typedef const Type& ConstRef; // Constant reference to the managed type.
|
|
|
|
|
2016-11-14 14:46:48 +01:00
|
|
|
protected:
|
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
* Validate the managed sockaddr pointer and throw an error if invalid.
|
2016-03-10 04:57:13 +01:00
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
void Validate(CCStr file, Int32 line) const;
|
|
|
|
#else
|
2016-03-10 04:57:13 +01:00
|
|
|
void Validate() const;
|
2016-11-14 13:06:30 +01:00
|
|
|
#endif // _DEBUG
|
2016-03-10 04:57:13 +01:00
|
|
|
|
2016-11-14 13:06:30 +01:00
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Validate the managed sockaddr pointer and throw an error if invalid.
|
|
|
|
*/
|
|
|
|
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
|
|
|
Pointer GetValid(CCStr file, Int32 line) const;
|
|
|
|
#else
|
|
|
|
Pointer GetValid() const;
|
|
|
|
#endif // _DEBUG
|
2016-11-14 14:46:48 +01:00
|
|
|
|
2016-03-10 04:57:13 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------
|
2016-11-14 13:06:30 +01:00
|
|
|
Pointer m_Handle; // The managed sockaddr structure.
|
|
|
|
String m_Addres; // The address that was queried for information.
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Default constructor.
|
|
|
|
*/
|
|
|
|
SockAddr()
|
2016-11-14 13:06:30 +01:00
|
|
|
: m_Handle(nullptr), m_Addres(_SC(""))
|
2016-03-10 04:57:13 +01:00
|
|
|
{
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Base constructor.
|
|
|
|
*/
|
|
|
|
SockAddr(CSStr addr);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy constructor. (disabled)
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
SockAddr(const SockAddr & o) = delete;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move constructor.
|
|
|
|
*/
|
|
|
|
SockAddr(SockAddr && o)
|
|
|
|
: m_Handle(o.m_Handle)
|
|
|
|
, m_Addres(o.m_Addres)
|
|
|
|
{
|
|
|
|
o.m_Handle = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Destructor.
|
|
|
|
*/
|
|
|
|
~SockAddr();
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Copy assignment operator. (disabled)
|
|
|
|
*/
|
2016-11-14 13:06:30 +01:00
|
|
|
SockAddr & operator = (const SockAddr & o) = delete;
|
2016-03-10 04:57:13 +01:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Move assignment operator.
|
|
|
|
*/
|
|
|
|
SockAddr & operator = (SockAddr && o)
|
|
|
|
{
|
|
|
|
if (m_Handle != o.m_Handle)
|
|
|
|
{
|
|
|
|
m_Handle = o.m_Handle;
|
|
|
|
m_Addres = o.m_Addres;
|
|
|
|
o.m_Handle = nullptr;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the internal addrinfo structure pointer.
|
|
|
|
*/
|
|
|
|
Pointer GetHandle()
|
|
|
|
{
|
|
|
|
return m_Handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the internal addrinfo structure pointer.
|
|
|
|
*/
|
|
|
|
Pointer GetHandle() const
|
|
|
|
{
|
|
|
|
return m_Handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to convert an instance of this type to a string.
|
|
|
|
*/
|
|
|
|
CSStr ToString() const
|
|
|
|
{
|
|
|
|
return m_Addres.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Used by the script engine to retrieve the name from instances of this type.
|
|
|
|
*/
|
|
|
|
static SQInteger Typename(HSQUIRRELVM vm);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* See whether this instance references a valid addrinfo structure.
|
|
|
|
*/
|
|
|
|
bool IsValid() const
|
|
|
|
{
|
|
|
|
return m_Handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------
|
|
|
|
* Retrieve the associated string address.
|
|
|
|
*/
|
|
|
|
CSStr GetAddress() const
|
|
|
|
{
|
|
|
|
return m_Addres.c_str();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|
|
|
|
|
|
|
|
#endif // _SQMMDB_SOCKADDR_HPP_
|