I have frequent
socket.error: [Errno 24] Too many open files
All the sockets are closed using closesocket function;
Linger?
When closesocket is call it will not return until all queued messages for the socket have been successfully sent or the linger timeout has been reached.
It looks like that independently from the result of send all the socket wait the linger timeout to expire before free itself.
In my specific application this in not desired since it needs to keep opening temporary connection inside a while loop.
while(1){
struct sockaddr_in server;
// configure sockaddr_in with correct s_addr and sin_port
int tcp_socket = 0;
tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
// connect to server
// send message
// recv response
closesocket(tcp_socket);
}
By setting SO_LINGER to
struct linger so_linger;
so_linger.l_onoff = 1;
so_linger.l_linger = 2; // linger in seconds
setsockopt(tcp_socket, SOL_SOCKET, SO_LINGER, (void*)&so_linger, sizeof(so_linger);
It makes no difference it looks like 2 sec linger is ignored.
using:
so_linger.l_linger = 0;
this solvers the socket.error: [Errno 24] problem but now I have a RST instead of a FIN and this is not the way I’d like to handle the issue
After some research i’ve found that TIME_WAIT is the reason sockets are not made available immediately still I do not know hot to solve this.