websockify-nginx-module icon indicating copy to clipboard operation
websockify-nginx-module copied to clipboard

websocket_server_write_frame_header函数建议返回头部长度

Open wangyongxiao opened this issue 4 years ago • 3 comments

websocket_server_write_frame_header函数建议返回头部长度,这样使用完这个函数可以得到dst应该偏移多少,比如如下

static ngx_inline int websocket_server_write_frame_header(u_char *dst, u_char opcode, size_t payload_length) { dst[0] = (u_char)((opcode & 0x0F) | 0x80); if ( payload_length <= 125 ) { dst[1] = (u_char)(payload_length);

return 2;

}

dst[1] = (u_char) 126; *(u_short *)&(dst[2]) = htons((u_short)(payload_length));

return 4; }

使用时: ... int len = websocket_server_write_frame_header(dst, opcode, payload_length); dst += len; ...

wangyongxiao avatar May 27 '21 02:05 wangyongxiao

有个macro 用来计算 websocket_server_encoded_header_length 不过返回没有坏处

tg123 avatar May 27 '21 14:05 tg123

问个问题,为什么不补充当数据长度大于65535的情况呢,我在基于nginx-http-flv-module模块扩展websocket-flv功能时借鉴了websockify-nginx-module模块,遇到了数据长度大于65535,把这个函数做了修改让他支持数据长度大于65535的情况

wangyongxiao avatar May 28 '21 02:05 wangyongxiao

多于65535 会自动拆成 多个 websocket frame 自动 实践上 如果过大 浏览器 端 也不好处理 容易出现卡顿

这个值相当于MTU 个人觉得目前的大小足够了

tg123 avatar May 28 '21 04:05 tg123