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

建议:在需要发送的结构中使用uint32_t代替所有int并在发送时转为网络序 #145

Open
TsXor opened this issue Oct 9, 2023 · 0 comments

Comments

@TsXor
Copy link

TsXor commented Oct 9, 2023

以结构体scws_response为例

xunsearch/src/task.cc

Lines 1977 to 1982 in d1b72c7

struct scws_response
{
int off; // for tops: times
char attr[4]; // attribute
char word[0]; // dynamic
};

根据后续代码,这个结构体是直接发送内存的。

如果客户端和服务端不在同一台服务器上,那么有可能客户端和服务端int大小不同或者字节序不同,关键是客户端和服务端都无法检测这一点。
最简单的方法是统一使用网络序(即大端)32位整数,已经足够表示4GB空间。如果32位整数可能不够,至少给客户端一个检测的手段(增加一个命令或在配置文件中加入这一项)

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

1 participant