Click to See Complete Forum and Search --> : Socket reallocations error 10055?


Stuard
January 7th, 2003, 02:58 PM
I create multithread application and in each thread create socket to connect to some port of local server. Each thread contain something like this:
{
s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
...
d = connect(s, (struct sockaddr *)&a, sizeof(a));
...
closesocket(d);
}
After about 4000 sequential calling this thread (max 100 threads active at a time!) connect function start returning error code 10055(No buffer space available).
WHY?
After termination each thread I call closesocket(...) but it seams that closesocket doesn't reallocate taken resource!
If I call inside thread just socket(...) function but not connect then works fine .(that means connect(...) has some problem!)

Any help would be appreciated!
Thanks.

Valen
January 7th, 2003, 03:21 PM
Connect returns an int value that is an error code only...not a socket. Try this:

{s = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
...
d = connect(s, (struct sockaddr *)&a, sizeof(a));

if(d == 0)
success

else
error handling
...
closesocket(s);
}


Hope it helps!

DanM
January 8th, 2003, 01:31 AM
You also have to call closesocket(s). Otherwise the resources associated with s won't be released.

Dan

Stuard
January 8th, 2003, 03:22 PM
I was such a full. Yes that is solution of my problem.
Thanks a lot to specially to Valen and to DanM who probably didn't see answer of Valen.
Ciao.

DanM
January 8th, 2003, 04:25 PM
Sorry, my mistake :)
Anyway, good that you got your problem solved.

Dan