Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议:TcpPullServer增加一个"查找byte序列"的HP_TcpPullServer_Find()方法 #45

Closed
gmxyb opened this issue Aug 14, 2018 · 5 comments

Comments

@gmxyb
Copy link

gmxyb commented Aug 14, 2018

目前只能每次用 HP_TcpPullServer_Peek 先取出来自己在临时的buffer中查找分隔符,多了很多无效的内存拷贝。

建议提供一个可以直接在内部缓冲区查找特定BYTE序列的函数,这样就不需要全部Peek出来了。

int HP_TcpPullServer_Find(HP_TcpPullServer pServer, HP_CONNID dwConnID, BYTE* pFind, int iLength);

pFind是需要匹配的序列, iLength 是pFind 的字节数(必须>=1)

返回值:如果 >0 表示匹配到了,可以Fetch的字节数(包含末尾的pFind),如果 <=0 则未找到

@gmxyb gmxyb changed the title 建议:TcpPullServer增加一个"指定分隔字符串"的Fetch()方法 建议:TcpPullServer增加一个"查找byte序列"的HP_TcpPullServer_Find()方法 Aug 14, 2018
@ldcsaa
Copy link
Owner

ldcsaa commented Aug 14, 2018

可能你使用pull的方式有问题,正常情况下只要你的应用层协议定义得合理(包头包体清晰)是不需要调用HP_TcpPullServer_Peek方法的。可参考相关示例DEMO。

@gmxyb
Copy link
Author

gmxyb commented Aug 15, 2018

谢谢回答。我遇到的是别人定的不定长协议。。

@ldcsaa
Copy link
Owner

ldcsaa commented Aug 23, 2018

不定长也可以用PULL,只要包头能拿到包体的长度

@gmxyb
Copy link
Author

gmxyb commented Aug 24, 2018

大哥,就是因为包头也不定长,不然我也不会提这个了。。

@ldcsaa
Copy link
Owner

ldcsaa commented Aug 28, 2018

如果不同包类型的包头长度固定或包头的最前字节为包类型和包头长度还好处理,可以对包头进行二次解析。否则只能自己处理了,或者直接用PUSH模型。

@ldcsaa ldcsaa closed this as completed Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants