diff --git a/HISTORY b/HISTORY index e2a6155..ca33d54 100644 --- a/HISTORY +++ b/HISTORY @@ -1,8 +1,9 @@ -Version 1.56 2022-01-31 +Version 1.56 2022-02-02 * add function fc_gettid * function normalize_path: NULL from parameter for getcwd * sockopt.[hc] support tcpwritev and tcpreadv + * add function fc_iov_get_bytes Version 1.55 2022-01-12 * fastcommon php extension adapt to php 8 diff --git a/src/shared_func.h b/src/shared_func.h index 6d9e3fa..66f6ead 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -1232,6 +1232,35 @@ static inline pid_t fc_gettid() #endif } +static inline size_t fc_iov_get_bytes(const + struct iovec *iov, const int iovcnt) +{ + const struct iovec *iob; + const struct iovec *end; + size_t bytes; + + switch (iovcnt) { + case 0: + return 0; + case 1: + return iov[0].iov_len; + case 2: + return iov[0].iov_len + iov[1].iov_len; + case 3: + return iov[0].iov_len + iov[1].iov_len + iov[2].iov_len; + case 4: + return iov[0].iov_len + iov[1].iov_len + + iov[2].iov_len + iov[3].iov_len; + default: + bytes = 0; + end = iov + iovcnt; + for (iob=iov; iobiov_len; + } + return bytes; + } +} + #ifdef __cplusplus } #endif