简体   繁体   English

TCP缓冲死锁,如何断开未接收数据的用户?

[英]TCP buffering deadlock, how can i disconnect a user who isn't receiving data?

I have a server that runs fine except when I performance test it by spamming packets through it. 我有一台运行良好的服务器,除非我通过对其发送垃圾邮件来进行性能测试。 The clients do not receive data only send and then the server ends up in a deadlock. 客户端不只接收发送的数据,然后服务器陷入死锁。

How can I check if the end user is not receiving data and disconnect them accordingly does it trigger some type of error that I can work off? 如何检查最终用户是否未接收到数据并相应地断开数据连接,是否会触发我可以解决的某种类型的错误?

Cheers 干杯

Beej's guide is a great reference to sockets. Beej的指南对套接字有很好的参考。 Depending on your needs, you can use the value of errno if a call like send(socket, buffer, buffer_length, MSG_DONTWAIT); 如果您喜欢send(socket, buffer, buffer_length, MSG_DONTWAIT);类的调用,则可以根据需要使用errno的值send(socket, buffer, buffer_length, MSG_DONTWAIT); is made and returns -1 . 进行并返回-1 errno having a value of EAGAIN indicates that the buffer handling the out traffic is currently full. 具有EAGAIN值的errno表示处理出站流量的缓冲区当前已满。

One question to ask is if your clients are actually the ones getting filled up. 要问的一个问题是,您的客户是否实际上就是那些已经满员的客户。 Is your server's buffer not able to be emptied faster than what you're trying to write? 服务器缓冲区的清空速度是否比您要写入的缓冲区快?

@EJB has a good point that my question could be somewhat meaningless, because in most cases, the reason for errno having the value EAGAIN during a send is that the client isn't keeping up with the transfer. @EJB的一个好点是我的问题可能毫无意义,因为在大多数情况下, errnosend期间具有值EAGAIN的原因是客户端无法跟上传输。 In that case, you'd simply close(client_socket); 在这种情况下,您只需close(client_socket); and be done with that specific client. 并与该特定客户一起完成。 If you are wanting something more advanced, you should create some sort of algorithm that will use a set of heuristics to determine the state of such client, and handle accordingly instead of simply dropping the connection, unless that's what you're really wanting. 如果您需要更高级的功能,则应创建某种算法,该算法将使用一组试探法来确定此类客户端的状态,并相应地进行处理,而不是简单地删除连接,除非您真正想要的是。

A very basic example heuristic you could use is to give each client an allotted time until they're considered unresponsive. 您可以使用的一个非常基本的启发式示例是给每个客户分配时间,直到他们被认为没有反应为止。 For example, if you keep getting EAGAIN on the same client for the next 5-10 seconds, that client could be considered unresponsive and you could close the connection. 例如,如果在接下来的5-10秒钟内您在同一客户端上继续获得EAGAIN ,则该客户端将被视为无响应,您可以关闭连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM