added qse_skadrealsize() && SocketAddress::getAddrRealSize()
This commit is contained in:
parent
b7f4bf85b6
commit
c8144cc4b4
@ -61,6 +61,8 @@ public:
|
||||
SocketAddress (const qse_skad_t* skad) QSE_CPP_NOEXCEPT;
|
||||
SocketAddress (const qse_nwad_t* nwad) QSE_CPP_NOEXCEPT;
|
||||
|
||||
bool operator== (const SocketAddress& addr) const QSE_CPP_NOEXCEPT;
|
||||
|
||||
int getFamily () const QSE_CPP_NOEXCEPT;
|
||||
|
||||
qse_skad_t* getAddrPtr() QSE_CPP_NOEXCEPT
|
||||
@ -78,6 +80,11 @@ public:
|
||||
return qse_skadsize(&this->skad);
|
||||
}
|
||||
|
||||
int getAddrRealSize () const QSE_CPP_NOEXCEPT
|
||||
{
|
||||
return qse_skadrealsize(&this->skad);
|
||||
}
|
||||
|
||||
int getAddrCapa() const QSE_CPP_NOEXCEPT
|
||||
{
|
||||
return QSE_SIZEOF(this->skad);
|
||||
|
@ -337,13 +337,25 @@ QSE_EXPORT int qse_skadfamily (
|
||||
|
||||
|
||||
/**
|
||||
* The qse_skadlength() function returns the socket address size
|
||||
* The qse_skadsize() function returns the socket address size
|
||||
* of a given address \a skad.
|
||||
*/
|
||||
QSE_EXPORT int qse_skadsize (
|
||||
const qse_skad_t* skad
|
||||
);
|
||||
|
||||
/**
|
||||
* The qse_skadrealsize() function returns the socket address size
|
||||
* of a given address \a skad. It differs from qse_skadsize() in that
|
||||
* it returns the size of the actual data instead of the whole address
|
||||
* structure. For example, the null-terminated path in a local domain
|
||||
* socket address may be shorter than the actual path buffer.
|
||||
*/
|
||||
QSE_EXPORT int qse_skadrealsize (
|
||||
const qse_skad_t* skad
|
||||
);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -104,6 +104,14 @@ SocketAddress::SocketAddress (const qse_nwad_t* nwad) QSE_CPP_NOEXCEPT
|
||||
this->set (nwad);
|
||||
}
|
||||
|
||||
bool SocketAddress::operator== (const SocketAddress& addr) const QSE_CPP_NOEXCEPT
|
||||
{
|
||||
if (this == &addr) return true;
|
||||
if (FAMILY(&this->skad) != FAMILY(&addr.skad)) return false;
|
||||
if (this->getAddrRealSize() != addr.getAddrRealSize()) return false;
|
||||
return QSE_MEMCMP(this->getAddrPtr(), addr.getAddrPtr(), addr.getAddrRealSize()) == 0;
|
||||
}
|
||||
|
||||
int SocketAddress::getFamily () const QSE_CPP_NOEXCEPT
|
||||
{
|
||||
return FAMILY(&this->skad);
|
||||
|
@ -287,3 +287,34 @@ int qse_skadsize (const qse_skad_t* skad)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qse_skadrealsize (const qse_skad_t* skad)
|
||||
{
|
||||
sockaddr_t* sa = (sockaddr_t*)skad;
|
||||
QSE_ASSERT (QSE_SIZEOF(*skad) >= QSE_SIZEOF(*sa));
|
||||
|
||||
switch (FAMILY(skad))
|
||||
{
|
||||
#if defined(AF_INET)
|
||||
case AF_INET: return QSE_SIZEOF(sa->in4);
|
||||
#endif
|
||||
|
||||
#if defined(AF_INET6)
|
||||
case AF_INET6: return QSE_SIZEOF(sa->in6);
|
||||
#endif
|
||||
|
||||
#if defined(AF_UNIX)
|
||||
case AF_UNIX:
|
||||
{
|
||||
return QSE_OFFSETOF(struct sockaddr_un, sun_path) + qse_mbslen(sa->un.sun_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(AF_PACKET)
|
||||
case AF_PACKET: return QSE_SIZEOF(sa->ll);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user