We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
某些时候服务器与浏览器建立的连接没有及时断开。会出现timeout异常。
The text was updated successfully, but these errors were encountered:
初步分析。问题在于套接字recv阶段。 目前套接字层采用循环recv的方法
while True: data = recv(1024) if len(data) < 1024: break
选择该模式是由于无法准确预测请求的长度。因此循环recv 而当最后一次recv块的大小刚好等于一次recv的字节数时。则不会进入break分支 再次recv时,由于套接字连接未中断而等待接受的数据为0 程序就停留在recv处不再执行 等待套接字超时后就会抛出timeout异常
break
解决方案是寻找合适的方式预测套接字数据是否接受完毕。
Sorry, something went wrong.
暂时没有解决思路
socket的recv只是从本地TCP协议栈拷贝数据,recv(1024)只能保证数据不大于1024,应该针对应用层协议对TCP流分块
buf = [] cl = 0 while True: data = recv(1) buf.append(data) if buf[-4:] == b'\r\n\r\n': break if current_req_header() == 'Content-Length': cl= parse_content_length() buf.append(recv(cl)) close_conn()
No branches or pull requests
某些时候服务器与浏览器建立的连接没有及时断开。会出现timeout异常。
The text was updated successfully, but these errors were encountered: