From 5caf48e0733cf8a5a38c4c2fb8589a85046d1b73 Mon Sep 17 00:00:00 2001 From: schmidt Date: Mon, 2 Dec 2002 21:41:53 +0000 Subject: ChangeLogTag:Sat Nov 30 09:18:51 2002 Douglas C. Schmidt --- ace/ACE.cpp | 29 ++++++++++++++++++++++++++--- ace/ACE.h | 4 ++++ 2 files changed, 30 insertions(+), 3 deletions(-) (limited to 'ace') diff --git a/ace/ACE.cpp b/ace/ACE.cpp index 8271cdb2c9c..b3492d70c7b 100644 --- a/ace/ACE.cpp +++ b/ace/ACE.cpp @@ -473,9 +473,7 @@ ACE::crc32 (const char *buffer, ACE_UINT32 len) for (const char *p = buffer; p != buffer + len; ++p) - { - COMPUTE (crc, *p); - } + COMPUTE (crc, *p); // Include the length of the string. @@ -485,6 +483,31 @@ ACE::crc32 (const char *buffer, ACE_UINT32 len) return ~crc; } +u_long +ACE::crc32 (iovec *iov, int len) +{ + register ACE_UINT32 crc = 0; + + int total_len = 0; + + for (int i = 0; i < len; ++i) + { + for (const char *p = iov[i].iov_base; + p != iov[i].iov_base + iov[i].iov_len; + ++p) + COMPUTE (crc, *p); + + total_len += iov[i].iov_len; + } + + // Include the length of the string. + + for (; total_len != 0; total_len >>= 8) + COMPUTE (crc, total_len & 0xff); + + return ~crc; +} + #undef COMPUTE #if !defined (ACE_HAS_WINCE) diff --git a/ace/ACE.h b/ace/ACE.h index 14fad8aae3a..3fef3fae893 100644 --- a/ace/ACE.h +++ b/ace/ACE.h @@ -494,6 +494,10 @@ public: /// buffer (the length is included in the CRC). static u_long crc32 (const char *buf, ACE_UINT32 len); + /// Computes the ISO 8802-3 standard 32 bits CRC for the + /// @ len iovec buffers. + static u_long crc32 (iovec *iov, int len); + /// Euclid's greatest common divisor algorithm. static u_long gcd (u_long x, u_long y); -- cgit v1.2.1