I noticed that whenever my listening socket accept a new connection, 2 new handles are used (by watching the Task Manager). Why? In this way, I can only accept upto 32k connections instead 64k since system will use up all available handles!
I am using the following code:
....
/* Create a new socket */
if (INVALID_SOCKET == (s = socket(AF_INET, SOCK_STREAM, 0)))
{
printf("Socket allocation failure.\n"
exit(-1);
}
/* Bind the socket */
if (SOCKET_ERROR == bind(s, (struct sockaddr*)&sa, sizeof(sa)))
{
printf("Socket binding error: %d. \n", WSAGetLastError());
exit(-1);
}
/* start to listen */
listen(s, SOMAXCONN);
/* Block and accept upto LIMIT connections */
for (n=0; n < LIMIT; n++)
{
char buf[16];
while ( INVALID_SOCKET == (s_arr[n] = accept(s, NULL, NULL)))
{
printf("Accept error: %d", WSAGetLastError());
exit(-1);
}
/* BUT see 2 handles per time ?? */
sprintf(buf, "%d", n);
printf("Accept request %d.\n", n);
}
...
Thanks!
-Tim
I am using the following code:
....
/* Create a new socket */
if (INVALID_SOCKET == (s = socket(AF_INET, SOCK_STREAM, 0)))
{
printf("Socket allocation failure.\n"
exit(-1);
}
/* Bind the socket */
if (SOCKET_ERROR == bind(s, (struct sockaddr*)&sa, sizeof(sa)))
{
printf("Socket binding error: %d. \n", WSAGetLastError());
exit(-1);
}
/* start to listen */
listen(s, SOMAXCONN);
/* Block and accept upto LIMIT connections */
for (n=0; n < LIMIT; n++)
{
char buf[16];
while ( INVALID_SOCKET == (s_arr[n] = accept(s, NULL, NULL)))
{
printf("Accept error: %d", WSAGetLastError());
exit(-1);
}
/* BUT see 2 handles per time ?? */
sprintf(buf, "%d", n);
printf("Accept request %d.\n", n);
}
...
Thanks!
-Tim