-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathws_parser.h
36 lines (31 loc) · 883 Bytes
/
ws_parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// ws_parser.h
//
// Created by zhengyixiong on 15/8/12.
// Copyright (c) 2015年 zhengyixiong. All rights reserved.
//
#ifndef _WS_PARSER_H_
#define _WS_PARSER_H_
#include "uv.h"
typedef enum OpcodeType
{
OPCODE_CONTINUE = 0, //分片帧
OPCODE_TEXT, //文本帧,用于json命令
OPCODE_FORWARD, //二进制帧,用于转发
OPCODE_CLOSE = 8, //连接关闭
OPCODE_PING, //ping
OPCODE_PONG //pong
}OpcodeType;
typedef struct WsHeader
{
uint8_t fin;
uint8_t res[3];
uint8_t type; //参考OpcodeType
uint8_t mask;
uint8_t maskkey[4];
uint64_t length;
}WsHeader;
int ParseHandShake(const char* req, int reqSize, char* res, const int maxResSize, int &resSize);
int Parse(const char* req, uint64_t reqSize, WsHeader &header, int &dataPos);
int Pack(OpcodeType type, char* pHeader, int &headerSize, uint64_t dataSize);
#endif