added Socket::getSockName() and Socket::getPeerName()

This commit is contained in:
hyung-hwan 2018-10-23 03:51:47 +00:00
parent 6130d3cdfe
commit 95a41ab8a1
2 changed files with 21 additions and 0 deletions

View File

@ -60,6 +60,9 @@ public:
// -------------------------------------------------------------------- // --------------------------------------------------------------------
int getSockName (SocketAddress& addr) QSE_CPP_NOEXCEPT;
int getPeerName (SocketAddress& addr) QSE_CPP_NOEXCEPT;
int getOption (int level, int optname, void* optval, qse_sck_len_t* optlen) QSE_CPP_NOEXCEPT; int getOption (int level, int optname, void* optval, qse_sck_len_t* optlen) QSE_CPP_NOEXCEPT;
int setOption (int level, int optname, const void* optval, qse_sck_len_t optlen) QSE_CPP_NOEXCEPT; int setOption (int level, int optname, const void* optval, qse_sck_len_t optlen) QSE_CPP_NOEXCEPT;

View File

@ -152,6 +152,24 @@ void Socket::close () QSE_CPP_NOEXCEPT
} }
} }
int Socket::getSockName (SocketAddress& addr) QSE_CPP_NOEXCEPT
{
QSE_ASSERT (qse_is_sck_valid(this->handle));
qse_sck_len_t len = addr.getAddrCapa();
int n = ::getsockname(this->handle, (struct sockaddr*)addr.getAddrPtr(), &len);
if (n == -1) this->setErrorCode (syserr_to_errnum(errno));
return n;
}
int Socket::getPeerName (SocketAddress& addr) QSE_CPP_NOEXCEPT
{
QSE_ASSERT (qse_is_sck_valid(this->handle));
qse_sck_len_t len = addr.getAddrCapa();
int n = ::getpeername(this->handle, (struct sockaddr*)addr.getAddrPtr(), &len);
if (n == -1) this->setErrorCode (syserr_to_errnum(errno));
return n;
}
int Socket::getOption (int level, int optname, void* optval, qse_sck_len_t* optlen) QSE_CPP_NOEXCEPT int Socket::getOption (int level, int optname, void* optval, qse_sck_len_t* optlen) QSE_CPP_NOEXCEPT
{ {
QSE_ASSERT (qse_is_sck_valid(this->handle)); QSE_ASSERT (qse_is_sck_valid(this->handle));