It sounds kinda like your connections start failing and then are automatically retried. If the retries happen quickly enough TCP could cycle through the entire port range and all your ports will be in TIME-WAIT state (IIRC that's what the state's called, it's been a little while since I've been debugging TCP in detail).
A couple of things to understand first:
Then you have to look for clues as to why the connection is failing. Probably the outgoing connection is to a server, is the server up and running? Why wouldn't the server accept the connection - is the process/thread responsible for accepting the connection deadlocked, blocked on something, or has it exited? Is the network between the originator and the server working normally?
вы используете что-то вроде
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)
, это позволяет повторно использовать один и тот же сокет дважды без предупреждения
Мне кажется, что это именно то, что предлагает сообщение об ошибке ... ваши порты исчерпаны. Это подразумевает МНОГО исходящих подключений.
По умолчанию не ограничивается количество TCP-подключений (я полагаю, вы ограничены только количеством портов, вероятно, порты с 1024 по 65534)
Я бы начал исследовать, почему вы видите так много исходящих соединений за такое короткое время.