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

read不满一个http包就返回EAGAIN,怎么办? #1

Open
zyearn opened this issue Apr 13, 2015 · 2 comments
Open

read不满一个http包就返回EAGAIN,怎么办? #1

zyearn opened this issue Apr 13, 2015 · 2 comments

Comments

@zyearn
Copy link

zyearn commented Apr 13, 2015

你好。

对于一个新的connection,就创建一个thread:tyhp_thread_func

然后对这个fd读,读到EAGAIN就break,接下来就调用tyhp_parse_http_request来处理这个http包,但是这个函数是假设http包已经完全读进来了。那么问题来了,如果网络有延迟或者其它原因,导致http包最后几个字节没有到达client,那么read也会返回EAGAIN,那么这次调tyhp_parse_http_request就不对了。这几个剩余的字节会伴随着下一次http请求的到来,那么下一次调tyhp_parse_http_request解析request line的时候也会出错。

所以有什么好的解决方案?可以把http包先buffer住,等到可以解析了再解析?

@zouxiaohang
Copy link
Owner

嗯,这个程序是我很久之前写的,可能当时考虑有点不周,或者是没有完全理解unp上的一些错误字段。你可以自己修改代码看看

@zyearn
Copy link
Author

zyearn commented Apr 14, 2015

好的,因为我最近也在实现一个server,想要实现得更robust一点,学习了一下你的代码。多谢,那我再研究研究

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