- RAII does't execute destructor when call
exit
.SoWSACleanup
doesn't run.What's the problem?I foundlibnet
useWSAStartup
without anyWSACleanup
, why? WSAStartup
can call many times in one process, so how can ensureWSACleanup
enough?- How to use
WSAStartup
andWSACleanup
easily and elegantly? - Additional I had wrote this test code for test
WSAStartup
withoutWSAClean
, did not found any abnormal(growth of the memory or crash...)
code:
int main(int argc, char *argv[])
{
int res;
while (1) {
WSADATA wsadata;
res = WSAStartup(0x0202, &wsadata);
printf("WSAStartup 1 times:%d\n", res);
if (res != 0) {
printf("WSAStartup error:%d\n", WSAGetLastError());
exit(1);
}
res = WSAStartup(0x0202, &wsadata);
printf("WSAStartup 2 times:%d\n", res);
if (res != 0) {
printf("WSAStartup error:%d\n", WSAGetLastError());
exit(1);
}
}
return 0;
}