added qse_ip4adtoprefix()

added Socket::isOpen()
This commit is contained in:
hyung-hwan 2020-08-20 16:21:36 +00:00
parent 42e21d9e1e
commit a83005ca99
5 changed files with 67 additions and 6 deletions

View File

@ -492,22 +492,22 @@ public:
Node* insert (const T& datum)
{
return this->inject (datum, -1, QSE_NULL);
return this->inject(datum, -1, QSE_NULL);
}
Node* ensert (const T& datum)
{
return this->inject (datum, 0, QSE_NULL);
return this->inject(datum, 0, QSE_NULL);
}
Node* upsert (const T& datum)
{
return this->inject (datum, 1, QSE_NULL);
return this->inject(datum, 1, QSE_NULL);
}
Node* update (const T& datum)
{
Node* node = this->find_node (datum);
Node* node = this->find_node(datum);
if (node) node->value = datum;
return node;
}

View File

@ -381,6 +381,15 @@ QSE_EXPORT int qse_prefixtoip6ad (
qse_ip6ad_t* ipad
);
/*
* The qse_ip4adtoprefix() function returns the prefix length
* of the given IPv4 address mask.
*/
QSE_EXPORT int qse_ip4adtoprefix (
const qse_ip4ad_t* ipad
);
#if defined(__cplusplus)
}
#endif

View File

@ -55,6 +55,7 @@ public:
void close () QSE_CPP_NOEXCEPT;
qse_sck_hnd_t getHandle() const QSE_CPP_NOEXCEPT { return this->handle; }
bool isOpen() const QSE_CPP_NOEXCEPT { return this->handle != QSE_INVALID_SCKHND; }
// --------------------------------------------------------------------

View File

@ -734,3 +734,54 @@ int qse_prefixtoip6ad (int prefix, qse_ip6ad_t* ipad)
return 0;
}
#define __COUNTUP(x,cnt,rest) \
switch (x) \
{ \
case 0xFF000000: \
cnt += 8; break; \
case 0x00000000: \
if (rest) return -1; break; \
case 0xFE000000: cnt++; \
case 0xFC000000: cnt++; \
case 0xF8000000: cnt++; \
case 0XF0000000: cnt++; \
case 0xE0000000: cnt++; \
case 0xC0000000: cnt++; \
case 0x80000000: cnt++; \
if (rest) return -1; break; \
default: return -1; \
}
int qse_ip4adtoprefix (const qse_ip4ad_t* ipad)
{
int pfx = 0;
qse_uint32_t x, nm;
nm = qse_ntoh32(ipad->value);
if (nm)
{
x = nm & 0xFF000000; nm <<= 8;
__COUNTUP (x, pfx, nm);
}
if (nm)
{
x = nm & 0xFF000000; nm <<= 8;
__COUNTUP (x, pfx, nm);
}
if (nm)
{
x = nm & 0xFF000000; nm <<= 8;
__COUNTUP (x, pfx, nm);
}
if (nm)
{
x = nm & 0xFF000000;
__COUNTUP (x, pfx, 0);
}
return pfx;
}
/* TODO: qse_ip6adtoprefix() */

View File

@ -310,7 +310,7 @@ int qse_mbsspl (
qse_mchar_t* s, const qse_mchar_t* delim,
qse_mchar_t lquote, qse_mchar_t rquote, qse_mchar_t escape)
{
return qse_mbsspltrn (s, delim, lquote, rquote, escape, QSE_NULL);
return qse_mbsspltrn(s, delim, lquote, rquote, escape, QSE_NULL);
}
int qse_wcsspltrn (
@ -596,5 +596,5 @@ int qse_wcsspl (
qse_wchar_t* s, const qse_wchar_t* delim,
qse_wchar_t lquote, qse_wchar_t rquote, qse_wchar_t escape)
{
return qse_wcsspltrn (s, delim, lquote, rquote, escape, QSE_NULL);
return qse_wcsspltrn(s, delim, lquote, rquote, escape, QSE_NULL);
}