mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-30 10:57:34 +08:00
websocket::send_frame_data can be called multiple.
This commit is contained in:
parent
7b343621e0
commit
d453e86828
@ -2,6 +2,8 @@
|
||||
|
||||
545) 2018.10.21
|
||||
545.1) feature: redis_client, redis_client_pool 在非集群模式下创建连接时自动选择db
|
||||
545.2) feature: websocket::send_frame_data 在被循环调用时需检查长度是否一致,
|
||||
且需要根据实际写入的帧长度设置掩码
|
||||
|
||||
544) 2018.10.20
|
||||
544.1) bugfix: websocket::read_frame_data 被循环调用时,掩码使用方式有误
|
||||
|
@ -145,6 +145,7 @@ private:
|
||||
size_t header_size_;
|
||||
size_t header_len_;
|
||||
unsigned long long payload_nread_;
|
||||
unsigned long long payload_nsent_;
|
||||
bool header_sent_;
|
||||
|
||||
void make_frame_header(void);
|
||||
|
@ -18,6 +18,7 @@ websocket::websocket(socket_stream& client)
|
||||
, header_size_(0)
|
||||
, header_len_(0)
|
||||
, payload_nread_(0)
|
||||
, payload_nsent_(0)
|
||||
, header_sent_(false)
|
||||
{
|
||||
reset();
|
||||
@ -42,6 +43,7 @@ websocket& websocket::reset(void)
|
||||
header_.masking_key = 0;
|
||||
|
||||
payload_nread_ = 0;
|
||||
payload_nsent_ = 0;
|
||||
header_sent_ = false;
|
||||
|
||||
return *this;
|
||||
@ -194,10 +196,18 @@ bool websocket::send_frame_data(void* data, size_t len)
|
||||
return true;
|
||||
}
|
||||
|
||||
// senity check
|
||||
if (payload_nsent_ + len > header_.payload_len) {
|
||||
logger_error("data len overflow=%llu > %llu, %llu, %lu",
|
||||
payload_nsent_ + len, header_.payload_len,
|
||||
payload_nsent_, (unsigned long) len);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (header_.mask) {
|
||||
unsigned char* mask = (unsigned char*) &header_.masking_key;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
((char*) data)[i] ^= mask[i % 4];
|
||||
((char*) data)[i] ^= mask[(payload_nsent_ + i) % 4];
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,6 +216,7 @@ bool websocket::send_frame_data(void* data, size_t len)
|
||||
return false;
|
||||
}
|
||||
|
||||
payload_nsent_ += len;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user