简体   繁体   中英

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. Depending on your needs, you can use the value of errno if a call like send(socket, buffer, buffer_length, MSG_DONTWAIT); is made and returns -1 . errno having a value of EAGAIN indicates that the buffer handling the out traffic is currently full.

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. In that case, you'd simply 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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