I am writing a TCP server application using Winsock. The client that connects to me (for which I have no source and therefore cannot make changes) behaves as follows: If it connects and I close the connection (because it is an undesired client), it will immediately reconnect. As a result of this, I will spin like mad over my accept() calls if there's a client out there that wants to connect to me but whom I don't want to talk to (i.e. what I've called an undesired client).
I would like to find a way to prevent that mad spinning over my accept() calls. If there were only 1 desired client, I could bind my listening socket to that client's IP address rather than INADDR_ANY. But alas, there is more than 1 desired client. As far as I know, there's no way to allow connections from only a set of desired IP addresses when the size of that set is greater than 1.
I've looked at WSAAccept. Unfortunately, it looks like this would merely shift the mad spinning to a callback.
Is there a way to reject an attempted connection that doesn't involve accept() waking up and returning (and therefore leading to all this mad spinning)?