added Socket::send() that accept a data vector

This commit is contained in:
hyung-hwan 2018-10-22 14:10:37 +00:00
parent 1e08cd4f65
commit f91e8c3170
3 changed files with 67 additions and 1 deletions

View File

@ -347,6 +347,7 @@ pdfdir = @pdfdir@
prefix = @prefix@ prefix = @prefix@
program_transform_name = @program_transform_name@ program_transform_name = @program_transform_name@
psdir = @psdir@ psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@ sbindir = @sbindir@
sharedstatedir = @sharedstatedir@ sharedstatedir = @sharedstatedir@
srcdir = @srcdir@ srcdir = @srcdir@

View File

@ -103,9 +103,13 @@ public:
// underlying system calls // underlying system calls
qse_ssize_t send (const void* buf, qse_size_t len) QSE_CPP_NOEXCEPT; qse_ssize_t send (const void* buf, qse_size_t len) QSE_CPP_NOEXCEPT;
qse_ssize_t send (const void* buf, qse_size_t len, const SocketAddress& dstaddr) QSE_CPP_NOEXCEPT; qse_ssize_t send (const void* buf, qse_size_t len, const SocketAddress& dstaddr) QSE_CPP_NOEXCEPT;
qse_ssize_t send (const qse_ioptl_t* vec, int count) QSE_CPP_NOEXCEPT;
qse_ssize_t send (const qse_ioptl_t* vec, int count, const SocketAddress& dstaddr) QSE_CPP_NOEXCEPT;
// The sendx() functions sends data as much as it can, possibly with multiple // The sendx() functions sends data as much as it can, possibly with multiple
// underlying system calls. // underlying system calls. these are useful for stream sockets and may not
// be useful for datagram sockets they may split the given data into more than
// one packet.
int sendx (const void* buf, qse_size_t len, qse_size_t* total_sent = QSE_NULL) QSE_CPP_NOEXCEPT; int sendx (const void* buf, qse_size_t len, qse_size_t* total_sent = QSE_NULL) QSE_CPP_NOEXCEPT;
int sendx (const void* buf, qse_size_t len, const SocketAddress& dstaddr, qse_size_t* total_sent = QSE_NULL) QSE_CPP_NOEXCEPT; int sendx (const void* buf, qse_size_t len, const SocketAddress& dstaddr, qse_size_t* total_sent = QSE_NULL) QSE_CPP_NOEXCEPT;
int sendx (qse_ioptl_t* vec, int count, qse_size_t* total_sent = QSE_NULL) QSE_CPP_NOEXCEPT; int sendx (qse_ioptl_t* vec, int count, qse_size_t* total_sent = QSE_NULL) QSE_CPP_NOEXCEPT;

View File

@ -482,6 +482,67 @@ qse_ssize_t Socket::send (const void* buf, qse_size_t len, const SocketAddress&
return n; return n;
} }
qse_ssize_t Socket::send (const qse_ioptl_t* iov, int count) QSE_CPP_NOEXCEPT
{
QSE_ASSERT (qse_is_sck_valid(this->handle));
#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV)
ssize_t nwritten;
#if defined(HAVE_SENDMSG)
struct msghdr msg;
QSE_MEMSET (&msg, 0, QSE_SIZEOF(msg));
msg.msg_iov = (struct iovec*)iov;
msg.msg_iovlen = count;
nwritten = ::sendmsg(this->handle, &msg, 0);
#else
nwritten = ::writev(this->handle, (const struct iovec*)iov, count);
#endif
if (nwritten <= -1)
{
this->setErrorCode (syserr_to_errnum(errno));
return -1;
}
return nwritten;
#else
// TODO: combine to a single buffer .... use sendto....
this->setErrorCode (E_NOIMPL);
return -1;
#endif
}
qse_ssize_t Socket::send (const qse_ioptl_t* iov, int count, const SocketAddress& dstaddr) QSE_CPP_NOEXCEPT
{
QSE_ASSERT (qse_is_sck_valid(this->handle));
QSE_ASSERT (qse_is_sck_valid(this->handle));
#if defined(HAVE_SENDMSG)
ssize_t nwritten;
struct msghdr msg;
QSE_MEMSET (&msg, 0, QSE_SIZEOF(msg));
msg.msg_name = (void*)dstaddr.getAddrPtr();
msg.msg_namelen = dstaddr.getAddrSize();
msg.msg_iov = (struct iovec*)iov;
msg.msg_iovlen = count;
nwritten = ::sendmsg(this->handle, &msg, 0);
if (nwritten <= -1)
{
this->setErrorCode (syserr_to_errnum(errno));
return -1;
}
return nwritten;
#else
// TODO: combine to a single buffer .... use sendto....
this->setErrorCode (E_NOIMPL);
return -1;
#endif
return -1;
}
int Socket::sendx (const void* buf, qse_size_t len, qse_size_t* total_sent) QSE_CPP_NOEXCEPT int Socket::sendx (const void* buf, qse_size_t len, qse_size_t* total_sent) QSE_CPP_NOEXCEPT
{ {
QSE_ASSERT (qse_is_sck_valid(this->handle)); QSE_ASSERT (qse_is_sck_valid(this->handle));