完善webSocket协议实现

优化代码
This commit is contained in:
xiongziliang
2018-09-26 23:12:03 +08:00
parent bf88cc018b
commit 05e6d32576
18 changed files with 275 additions and 155 deletions

View File

@@ -43,6 +43,16 @@ void HttpRequestSplitter::input(const char *data,uint64_t len) {
splitPacket:
/*确保ptr最后一个字节是0防止strstr越界
*由于ZLToolKit确保内存最后一个字节是保留未使用字节并置0
*所以此处可以不用再次置0
*但是上层数据可能来自其他渠道保险起见还是置0
*/
char &tail_ref = ((char *) ptr)[len];
char tail_tmp = tail_ref;
tail_ref = 0;
//数据按照请求头处理
const char *index = nullptr;
while (_content_len == 0 && (index = strstr(ptr,"\r\n\r\n")) != nullptr) {
@@ -51,6 +61,11 @@ splitPacket:
ptr = index + 4;
}
/*
* 恢复末尾字节
*/
tail_ref = tail_tmp;
uint64_t remain = len - (ptr - data);
if(remain <= 0){
//没有剩余数据,清空缓存