diff --git a/src/sf_iov.c b/src/sf_iov.c index cbbdcfb..1702d22 100644 --- a/src/sf_iov.c +++ b/src/sf_iov.c @@ -55,6 +55,7 @@ int sf_iova_consume(SFDynamicIOVArray *iova, const int consume_len) if (iova->cnt == 0) { struct iovec *last; + /* update the last iov for next slice */ last = iob - 1; last->iov_base = (char *)last->iov_base + last->iov_len; last->iov_len = 0; diff --git a/src/sf_iov.h b/src/sf_iov.h index e0e6a7e..ff7cf02 100644 --- a/src/sf_iov.h +++ b/src/sf_iov.h @@ -82,6 +82,33 @@ int sf_iova_memset_ex(const struct iovec *iov, const int iovcnt, #define sf_iova_memset(iova, c, offset, length) \ sf_iova_memset_ex((iova).iov, (iova).cnt, c, offset, length) +static inline void sf_iova_memcpy_ex(const struct iovec *iov, + const int iovcnt, const char *buff, const int length) +{ + const struct iovec *iob; + const struct iovec *end; + const char *current; + int remain; + int bytes; + + current = buff; + remain = length; + end = iov + iovcnt; + for (iob=iov; iobiov_len); + memcpy(iob->iov_base, current, bytes); + + remain -= bytes; + if (remain == 0) { + break; + } + current += bytes; + } +} + +#define sf_iova_memcpy(iova, buff, length) \ + sf_iova_memcpy_ex((iova).iov, (iova).cnt, buff, length) + #ifdef __cplusplus } #endif