Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 handles for each connection??

Status
Not open for further replies.

tzhong

MIS
Mar 22, 2001
11
US
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(&quot;Accept error: %d&quot;, WSAGetLastError());
exit(-1);
}

/* BUT see 2 handles per time ?? */
sprintf(buf, &quot;%d&quot;, n);
printf(&quot;Accept request %d.\n&quot;, n);
}
...




Thanks!

-Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top