Jump to content
  • Advertisement
Sign in to follow this  

Multi-threaded WSAEventSelect() I/O model help

This topic is 4494 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am developing a Winsock Server Application based off the WSAEventSelect() I/O model and I am having some trouble. The Server needs to be able to handle 500 connections, and because WSAWaitForMultipleEvents() can only wait on 64 objects I am forced to make my server multi-threaded (this is where the problem comes in). I have searched google, codeproject, ect.. for multi-threaded Winsock Servers based off WSAEventSelect() so I could get a somewhat basic idea on how people have done it and I have not found anything, only ideas on how it would be done. Still searching the forums here (have been for hours), here's a basic layout of my program's structure: I created a class called WsaSocketClass that contains the following
DWORD EventTotal;
When the Application starts a thread is created that checks for new connections / socket data
WSAEventSelect(AcceptedSocket, ...)
this->CreateSockInfo(AcceptedSocket); // see below, this is called after a connection is recieved
Once a connection is recieved
typedef struct _SOCKET_INFORMATION {
   WSABUF DataBuf;
   SOCKET Socket;

BOOL WsaSocketClass::CreateSockInfo(SOCKET s)
   if ((this->EventArray[this->EventTotal] = WSACreateEvent()) == WSA_INVALID_EVENT)
      printf("WSACreateEvent() failed with error %d\n", WSAGetLastError());
      return FALSE;

      printf("GlobalAlloc() failed with error %d\n", GetLastError());
      return FALSE;
   SI->Socket = s;
   SI->BytesSEND = 0;
   SI->BytesRECV = 0;
   this->SocketArray[this->EventTotal] = SI;
   return (TRUE) ;
So this is where I am stuck and I do not know what to do.. I have tried creating a new thread once 63 Clients connect to the server and reading everything based off a new class, but it doesn't work because the old thread (the first one used when the Server started for the first 63 Clients) is still trying to accept connections and because of that I recieve errors that WSA_MAXIMUM_WAIT_EVENTS has been reached. I don't know how I would wait on more then one I/O notification (for receiving Client connections) if everything is based off a new class and the listen socket (FD_ACCEPT|FD_CLOSE) is already waiting on an I/O notification from the first thread on the same socket. Has anyone here developed (or know of) a multi-threaded Winsock Application based off the WSAEventSelect() I/O model that cares to share source? or any articles (books)? anything I could possibly learn off of? Any help is very much appreciated as I am clueless on how to go any further and am stressed, thanks in advance.

Share this post

Link to post
Share on other sites
WSAEventSelect and WSAAsyncSelect are intended as convenience functions, not as high-performance functions. If you have lots of connections, you should either try select() (with a #defined FD_SETSIZE that's bigger), or, ideally, using I/O completion ports with overlapped I/O on sockets.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!