views:

83

answers:

2

Hello,

I am using sockets on my program. Due to I added the WSAStatup. My application runs fine (It is always up till it gets a signal to stop). After getting the signal it stops te problem that if I write the WSAClenup function at the end of my program it crashes and if I remove it it termintes fine.

Thanks

+1  A: 

This is excerpt from one of my projects.

Initialisation:

#if defined(WIN32)
WSADATA wsaData;
WORD wVersionRequested = MAKEWORD(2, 0);
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
  LOG("WSAStartup() error");
  return false;
}
#endif

serv_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

...

Cleanup:

#if defined(WIN32)
  /* winsock requires a special function for sockets */
  shutdown(serv_socket, SD_BOTH);
  closesocket(serv_socket);
  /* clean up winsock */
  WSACleanup();  
#else
  close(serv_socket);
#endif

Hope this helps.

Andrejs Cainikovs
Tried it it is not the problem.I am not using directlry socket but using Select on sockets.
Roman Dorevich
I don't see any problems with that. If on Win, you need to call WSACleanup anyways. BTW, are you using threads?
Andrejs Cainikovs
Also, I have found nice Windows sockets API reference for you - http://www.sockets.com/winsock.htm#Cleanup.
Andrejs Cainikovs
not using thread
Roman Dorevich
Can you post initialization and cleanup parts of your code? Maybe we will find something out if you haven't still solved this.
Andrejs Cainikovs
A: 

Couldn't resovle and find the problem.The application is using more than just sockets. Although Microsoft reference sais that onevery WSAStartup you must use WSACleanup, well this is not true and the system is releasing things regards that.

Roman Dorevich