本文整理汇总了C++中DataChunk::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ DataChunk::GetLength方法的具体用法?C++ DataChunk::GetLength怎么用?C++ DataChunk::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataChunk
的用法示例。
在下文中一共展示了DataChunk::GetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Append
/*-----------------------------------------------------------------------------
Append data to the SSL/TLS stream and handle packet framing.
-----------------------------------------------------------------------------*/
void SSLStream::Append(const DataChunk& chunk) {
if (process_data_) {
size_t len = chunk.GetLength();
const char * buff = chunk.GetData();
while (len && buff) {
size_t copy_bytes = 0;
// are we starting a new frame?
if (message_size_ < 0) {
// see if we can at least copy over the size of the initial frame
size_t needed = sizeof(SSL_HEADER) - message_len_;
copy_bytes = min(needed, len);
if (copy_bytes) {
memcpy(&message_[message_len_], buff, copy_bytes);
message_len_ += (int)copy_bytes;
len -= copy_bytes;
buff += copy_bytes;
}
// see if we have a header to parse and get the actual message size
if (message_len_ >= sizeof(SSL_HEADER)) {
SSL_HEADER * header = (SSL_HEADER *)message_;
message_size_ = htons(header->record_length) + sizeof(SSL_HEADER);
}
}
// see if we have bytes remaining in the current message
if (message_size_ > 0 &&
message_len_ < message_size_ &&
len > 0 &&
buff) {
copy_bytes = min(message_size_ - message_len_, (__int32)len);
memcpy(&message_[message_len_], buff, copy_bytes);
message_len_ += (int)copy_bytes;
len -= copy_bytes;
buff += copy_bytes;
}
// see if we have a full message
if (message_size_ == message_len_) {
ProcessMessage();
// reset state for the next message
message_size_ = -1;
message_len_ = 0;
}
}
}
}