2
votes

I am trying to figure out the best way to handle multiple connections to my C++ TCP server. I stumbled upon epoll() but sadly it's available only for Linux and I'm doing everything on Windows.

After some research it seems the best way to handle sockets on Windows is the use of I/O Completion Ports. I would like to use them, however the client application uses send() and recv() (I cannot change that), meaning I also need to use the same functions to send to and receive data from the client. These functions don't seem to be used for IOCP (WSASend() / WSARecv() are used instead).

I'd like to know if there's still any way I would be able to use IOCP with send() and recv()? Or should I look into other methods?

1
I did check it actually, I've read it doesn't do well with a lot of sockets and that's my main concern, performance. - Spook

1 Answers

2
votes

I also need to use the same functions to send to and receive data from the client

That's incorrect. The client has no idea how you get data into and out of a TCP connection, either way the same exact TCP segments get sent across the network.

If your server is I/O bound, then WSAAsyncSelect and/or WSAEventSelect work very well (and save you the trouble of multithreading). Only for compute-bound services are IOCP worthwhile, because they distribute work items to an available thread so simultaneous requests can spin up and do their calculations on multiple processor cores.

WSAPoll is another option.