added IFNAMSIZ check in configure.ac

added QSE::SocketAddress::toString()
added QSE::Socket::getSendBuf(), QSE::Socket::getRecvBuf()
This commit is contained in:
hyung-hwan 2020-08-24 10:11:49 +00:00
parent 24d8c70835
commit 5829f8a28d
9 changed files with 170 additions and 15 deletions

73
qse/configure vendored
View File

@ -23113,6 +23113,64 @@ _ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking numeric value of IFNAMSIZ" >&5
$as_echo_n "checking numeric value of IFNAMSIZ... " >&6; }
if ${ax_cv_numvalof_IFNAMSIZ+:} false; then :
$as_echo_n "(cached) " >&6
else
if ac_fn_c_compute_int "$LINENO" "(IFNAMSIZ)" "ax_cv_numvalof_IFNAMSIZ" "#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
"; then :
else
ax_cv_numvalof_IFNAMSIZ=-1
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_numvalof_IFNAMSIZ" >&5
$as_echo "$ax_cv_numvalof_IFNAMSIZ" >&6; }
cat >>confdefs.h <<_ACEOF
#define NUMVALOF_IFNAMSIZ $ax_cv_numvalof_IFNAMSIZ
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking numeric value of IF_NAMESIZE" >&5
$as_echo_n "checking numeric value of IF_NAMESIZE... " >&6; }
if ${ax_cv_numvalof_IF_NAMESIZE+:} false; then :
$as_echo_n "(cached) " >&6
else
if ac_fn_c_compute_int "$LINENO" "(IF_NAMESIZE)" "ax_cv_numvalof_IF_NAMESIZE" "#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
"; then :
else
ax_cv_numvalof_IF_NAMESIZE=-1
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_numvalof_IF_NAMESIZE" >&5
$as_echo "$ax_cv_numvalof_IF_NAMESIZE" >&6; }
cat >>confdefs.h <<_ACEOF
#define NUMVALOF_IF_NAMESIZE $ax_cv_numvalof_IF_NAMESIZE
_ACEOF
if test "x${platform_win32}" = "xyes" if test "x${platform_win32}" = "xyes"
then then
# The cast to long int works around a bug in the HP C Compiler # The cast to long int works around a bug in the HP C Compiler
@ -24478,6 +24536,21 @@ cat >>confdefs.h <<_ACEOF
#define QSE_AF_UNIX ${ax_cv_numvalof_AF_UNIX} #define QSE_AF_UNIX ${ax_cv_numvalof_AF_UNIX}
_ACEOF _ACEOF
fi
if test ${ax_cv_numvalof_IFNAMSIZ} -ge 0
then
cat >>confdefs.h <<_ACEOF
#define QSE_IF_NAMESIZE ${ax_cv_numvalof_IFNAMSIZ}
_ACEOF
elif test ${ax_cv_numvalof_IF_NAMESIZE} -ge 0
then
cat >>confdefs.h <<_ACEOF
#define QSE_IF_NAMESIZE ${ax_cv_numvalof_IF_NAMESIZE}
_ACEOF
fi fi

View File

@ -551,6 +551,12 @@ AX_CHECK_NUMVALOF(AF_PACKET, [-1], [#include <sys/types.h>
AX_CHECK_NUMVALOF(AF_UNIX, [-1], [#include <sys/types.h> AX_CHECK_NUMVALOF(AF_UNIX, [-1], [#include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h>]) #include <sys/un.h>])
AX_CHECK_NUMVALOF(IFNAMSIZ, [-1], [#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>])
AX_CHECK_NUMVALOF(IF_NAMESIZE, [-1], [#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>])
if test "x${platform_win32}" = "xyes" if test "x${platform_win32}" = "xyes"
then then
@ -851,6 +857,13 @@ if test ${ax_cv_numvalof_AF_UNIX} -ge 0
then then
AC_DEFINE_UNQUOTED(QSE_AF_UNIX, ${ax_cv_numvalof_AF_UNIX}, [AF_UNIX]) AC_DEFINE_UNQUOTED(QSE_AF_UNIX, ${ax_cv_numvalof_AF_UNIX}, [AF_UNIX])
fi fi
if test ${ax_cv_numvalof_IFNAMSIZ} -ge 0
then
AC_DEFINE_UNQUOTED(QSE_IF_NAMESIZE, ${ax_cv_numvalof_IFNAMSIZ}, [IF_NAMESIZE])
elif test ${ax_cv_numvalof_IF_NAMESIZE} -ge 0
then
AC_DEFINE_UNQUOTED(QSE_IF_NAMESIZE, ${ax_cv_numvalof_IF_NAMESIZE}, [IF_NAMESIZE])
fi
AC_DEFINE_UNQUOTED(QSE_SIZEOF_STRUCT_SOCKADDR_IN, ${ac_cv_sizeof_struct_sockaddr_in}, [sizeof(struct sockaddr_in)]) AC_DEFINE_UNQUOTED(QSE_SIZEOF_STRUCT_SOCKADDR_IN, ${ac_cv_sizeof_struct_sockaddr_in}, [sizeof(struct sockaddr_in)])
AC_DEFINE_UNQUOTED(QSE_SIZEOF_STRUCT_SOCKADDR_IN6, ${ac_cv_sizeof_struct_sockaddr_in6}, [sizeof(struct sockaddr_in6)]) AC_DEFINE_UNQUOTED(QSE_SIZEOF_STRUCT_SOCKADDR_IN6, ${ac_cv_sizeof_struct_sockaddr_in6}, [sizeof(struct sockaddr_in6)])

View File

@ -73,10 +73,10 @@
(QSE_IS_LEAPYEAR(year)? QSE_DAYS_PER_LEAPYEAR: QSE_DAYS_PER_NORMYEAR) (QSE_IS_LEAPYEAR(year)? QSE_DAYS_PER_LEAPYEAR: QSE_DAYS_PER_NORMYEAR)
#define QSE_SECNSEC_TO_MSEC(sec,nsec) \ #define QSE_SECNSEC_TO_MSEC(sec,nsec) \
(((qse_long_t)(sec) * QSE_MSECS_PER_SEC) + ((qse_long_t)(nsec) / QSE_NSECS_PER_MSEC)) (((qse_ntime_sec_t)(sec) * QSE_MSECS_PER_SEC) + ((qse_ntime_sec_t)(nsec) / QSE_NSECS_PER_MSEC))
#define QSE_SECNSEC_TO_USEC(sec,nsec) \ #define QSE_SECNSEC_TO_USEC(sec,nsec) \
(((qse_long_t)(sec) * QSE_USECS_PER_SEC) + ((qse_long_t)(nsec) / QSE_NSECS_PER_USEC)) (((qse_ntime_sec_t)(sec) * QSE_USECS_PER_SEC) + ((qse_ntime_sec_t)(nsec) / QSE_NSECS_PER_USEC))
#define QSE_SEC_TO_MSEC(sec) ((sec) * QSE_MSECS_PER_SEC) #define QSE_SEC_TO_MSEC(sec) ((sec) * QSE_MSECS_PER_SEC)
#define QSE_MSEC_TO_SEC(sec) ((sec) / QSE_MSECS_PER_SEC) #define QSE_MSEC_TO_SEC(sec) ((sec) / QSE_MSECS_PER_SEC)
@ -93,6 +93,9 @@
#define QSE_SEC_TO_USEC(sec) ((sec) * QSE_USECS_PER_SEC) #define QSE_SEC_TO_USEC(sec) ((sec) * QSE_USECS_PER_SEC)
#define QSE_USEC_TO_SEC(usec) ((usec) / QSE_USECS_PER_SEC) #define QSE_USEC_TO_SEC(usec) ((usec) / QSE_USECS_PER_SEC)
typedef qse_long_t qse_ntime_sec_t;
typedef qse_int32_t qse_ntime_nsec_t;
/** /**
* The qse_ntime_t type defines a numeric time type expressed in the * The qse_ntime_t type defines a numeric time type expressed in the
* number of milliseconds since the Epoch (00:00:00 UTC, Jan 1, 1970). * number of milliseconds since the Epoch (00:00:00 UTC, Jan 1, 1970).
@ -100,8 +103,8 @@
typedef struct qse_ntime_t qse_ntime_t; typedef struct qse_ntime_t qse_ntime_t;
struct qse_ntime_t struct qse_ntime_t
{ {
qse_long_t sec; qse_ntime_sec_t sec;
qse_int32_t nsec; /* nanoseconds */ qse_ntime_nsec_t nsec; /* nanoseconds */
}; };
typedef struct qse_btime_t qse_btime_t; typedef struct qse_btime_t qse_btime_t;
@ -123,7 +126,7 @@ struct qse_btime_t
typedef qse_long_t qse_mtime_t; typedef qse_long_t qse_mtime_t;
#if defined(QSE_HAVE_INLINE) #if defined(QSE_HAVE_INLINE)
static QSE_INLINE void qse_inittime(qse_ntime_t* x, qse_long_t s, qse_int32_t nsec) static QSE_INLINE void qse_inittime(qse_ntime_t* x, qse_ntime_sec_t s, qse_ntime_nsec_t nsec)
{ {
x->sec = s; x->sec = s;
x->nsec = nsec; x->nsec = nsec;

View File

@ -810,6 +810,12 @@
/* The size of `AF_UNIX', as computed by valueof. */ /* The size of `AF_UNIX', as computed by valueof. */
#undef NUMVALOF_AF_UNIX #undef NUMVALOF_AF_UNIX
/* The size of `IFNAMSIZ', as computed by valueof. */
#undef NUMVALOF_IFNAMSIZ
/* The size of `IF_NAMESIZE', as computed by valueof. */
#undef NUMVALOF_IF_NAMESIZE
/* The size of `MB_LEN_MAX', as computed by valueof. */ /* The size of `MB_LEN_MAX', as computed by valueof. */
#undef NUMVALOF_MB_LEN_MAX #undef NUMVALOF_MB_LEN_MAX
@ -898,6 +904,9 @@
/* char16_t literal prefix */ /* char16_t literal prefix */
#undef QSE_HAVE_PREFIX_SMALL_U #undef QSE_HAVE_PREFIX_SMALL_U
/* IF_NAMESIZE */
#undef QSE_IF_NAMESIZE
/* MB_LEN_MAX */ /* MB_LEN_MAX */
#undef QSE_MBLEN_MAX #undef QSE_MBLEN_MAX

View File

@ -54,6 +54,7 @@ public:
int open (int domain, int type, int protocol, int traits = 0) QSE_CPP_NOEXCEPT; int open (int domain, int type, int protocol, int traits = 0) QSE_CPP_NOEXCEPT;
void close () QSE_CPP_NOEXCEPT; void close () QSE_CPP_NOEXCEPT;
int getDomain () const QSE_CPP_NOEXCEPT { return this->domain; }
qse_sck_hnd_t getHandle() const QSE_CPP_NOEXCEPT { return this->handle; } qse_sck_hnd_t getHandle() const QSE_CPP_NOEXCEPT { return this->handle; }
bool isOpen() const QSE_CPP_NOEXCEPT { return this->handle != QSE_INVALID_SCKHND; } bool isOpen() const QSE_CPP_NOEXCEPT { return this->handle != QSE_INVALID_SCKHND; }
@ -65,6 +66,10 @@ public:
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;
// --------------------------------------------------------------------
int getSendBuf (unsigned int& n) QSE_CPP_NOEXCEPT;
int getRecvBuf (unsigned int& n) QSE_CPP_NOEXCEPT;
// -------------------------------------------------------------------- // --------------------------------------------------------------------
int setDebug (int n) QSE_CPP_NOEXCEPT; int setDebug (int n) QSE_CPP_NOEXCEPT;
int setReuseAddr (int n) QSE_CPP_NOEXCEPT; int setReuseAddr (int n) QSE_CPP_NOEXCEPT;

View File

@ -29,6 +29,7 @@
#include <qse/Types.hpp> #include <qse/Types.hpp>
#include <qse/si/nwad.h> #include <qse/si/nwad.h>
#include <qse/cmn/String.hpp>
///////////////////////////////// /////////////////////////////////
QSE_BEGIN_NAMESPACE(QSE) QSE_BEGIN_NAMESPACE(QSE)
@ -87,6 +88,10 @@ public:
qse_mchar_t* toStrBuf (qse_mchar_t* buf, qse_size_t len) const QSE_CPP_NOEXCEPT; qse_mchar_t* toStrBuf (qse_mchar_t* buf, qse_size_t len) const QSE_CPP_NOEXCEPT;
qse_wchar_t* toStrBuf (qse_wchar_t* buf, qse_size_t len) const QSE_CPP_NOEXCEPT; qse_wchar_t* toStrBuf (qse_wchar_t* buf, qse_size_t len) const QSE_CPP_NOEXCEPT;
QSE::MbString toMbString (QSE::Mmgr* mmgr = QSE_NULL) const;
QSE::WcString toWcString (QSE::Mmgr* mmgr = QSE_NULL) const;
QSE::String toString (QSE::Mmgr* mmgr = QSE_NULL) const;
static qse_mchar_t* ip4addrToStrBuf (const qse_ip4ad_t* ipaddr, qse_mchar_t* buf, qse_size_t len); static qse_mchar_t* ip4addrToStrBuf (const qse_ip4ad_t* ipaddr, qse_mchar_t* buf, qse_size_t len);
static qse_mchar_t* ip4addrToStrBuf (qse_uint32_t ipaddr, qse_mchar_t* buf, qse_size_t len); static qse_mchar_t* ip4addrToStrBuf (qse_uint32_t ipaddr, qse_mchar_t* buf, qse_size_t len);
static qse_mchar_t* ip6addrToStrBuf (const qse_ip6ad_t* ipaddr, qse_mchar_t* buf, qse_size_t len); static qse_mchar_t* ip6addrToStrBuf (const qse_ip6ad_t* ipaddr, qse_mchar_t* buf, qse_size_t len);

View File

@ -187,6 +187,18 @@ int Socket::setOption (int level, int optname, const void* optval, qse_sck_len_t
return n; return n;
} }
int Socket::getSendBuf (unsigned int& size) QSE_CPP_NOEXCEPT
{
qse_sck_len_t optlen = QSE_SIZEOF(size);
return this->getOption(SOL_SOCKET, SO_SNDBUF, (char*)&size, &optlen);
}
int Socket::getRecvBuf (unsigned int& size) QSE_CPP_NOEXCEPT
{
qse_sck_len_t optlen = QSE_SIZEOF(size);
return this->getOption(SOL_SOCKET, SO_RCVBUF, (char*)&size, &optlen);
}
int Socket::setDebug (int n) QSE_CPP_NOEXCEPT int Socket::setDebug (int n) QSE_CPP_NOEXCEPT
{ {
return this->setOption(SOL_SOCKET, SO_DEBUG, (char*)&n, QSE_SIZEOF(n)); return this->setOption(SOL_SOCKET, SO_DEBUG, (char*)&n, QSE_SIZEOF(n));

View File

@ -300,6 +300,36 @@ qse_mchar_t* SocketAddress::toStrBuf (qse_mchar_t* buf, qse_size_t len) const QS
return buf; return buf;
} }
QSE::MbString SocketAddress::toMbString (QSE::Mmgr* mmgr) const
{
QSE::MbString buf(256, mmgr);
qse_nwad_t nwad;
qse_skadtonwad (&this->skad, &nwad);
qse_size_t n = qse_nwadtombs(&nwad, (qse_mchar_t*)buf.getBuffer(), buf.getCapacity(), QSE_NWADTOMBS_ALL);
buf.truncate (n);
return buf;
}
QSE::WcString SocketAddress::toWcString (QSE::Mmgr* mmgr) const
{
QSE::WcString buf(256, mmgr);
qse_nwad_t nwad;
qse_skadtonwad (&this->skad, &nwad);
qse_size_t n = qse_nwadtowcs(&nwad, (qse_wchar_t*)buf.getBuffer(), buf.getCapacity(), QSE_NWADTOWCS_ALL);
buf.truncate (n);
return buf;
}
QSE::String SocketAddress::toString (QSE::Mmgr* mmgr) const
{
QSE::String buf(256, mmgr);
qse_nwad_t nwad;
qse_skadtonwad (&this->skad, &nwad);
qse_size_t n = qse_nwadtostr(&nwad, (qse_char_t*)buf.getBuffer(), buf.getCapacity(), QSE_NWADTOSTR_ALL);
buf.truncate (n);
return buf;
}
qse_mchar_t* SocketAddress::ip4addrToStrBuf (const qse_ip4ad_t* ipaddr, qse_mchar_t* buf, qse_size_t len) qse_mchar_t* SocketAddress::ip4addrToStrBuf (const qse_ip4ad_t* ipaddr, qse_mchar_t* buf, qse_size_t len)
{ {
qse_nwad_t nwad; qse_nwad_t nwad;

View File

@ -16,7 +16,6 @@ static int test1 ()
{ {
QSE::Socket s; QSE::Socket s;
QSE::SocketAddress addr; QSE::SocketAddress addr;
qse_ioptl_t k[3];
if (s.open (QSE_AF_INET6, QSE_SOCK_STREAM, 0) <= -1) if (s.open (QSE_AF_INET6, QSE_SOCK_STREAM, 0) <= -1)
{ {
@ -61,15 +60,21 @@ static int test1 ()
addr.set ("[::1]:9999"); addr.set ("[::1]:9999");
s.connect (addr); if (s.connect(addr) <= -1)
{
k[0].ptr = (void*)"hello"; qse_printf (QSE_T("unable to connect to [::1]:9999\n"));
k[0].len = 5; }
k[1].ptr = (void*)"world"; else
k[1].len = 5; {
k[2].ptr = (void*)"forever"; qse_ioptl_t k[3];
k[2].len = 7; k[0].ptr = (void*)"hello";
s.sendx (k, 3); k[0].len = 5;
k[1].ptr = (void*)"world";
k[1].len = 5;
k[2].ptr = (void*)"forever";
k[2].len = 7;
s.sendx (k, 3);
}
return 0; return 0;
} }