-
February 22nd, 2015, 03:18 AM
#1
How can I accept() multiple sockets using Overlapped IO?
I am having a problem understanding how can I accept multiple sockets (quickly) when using Overlapped IO (with Completion Routines).
So in my server this is the pseudo code:
Code:
while(true)
{
sock = accept();
WSARecv(sock, callback_function);
Wait(); // need to make the calling thread alertable
}
callback_function()
{
// process data here
}
So as you can see I can only accept one socket, and then I enter a wait state, and only when sock receive something that I will be able to accept another socket!
-
February 22nd, 2015, 03:45 AM
#2
Re: How can I accept() multiple sockets using Overlapped IO?
If you mean that your callback requires much time to process socket connection then try moving it to a worker thread.
Victor Nijegorodov
-
February 22nd, 2015, 04:17 AM
#3
Re: How can I accept() multiple sockets using Overlapped IO?
Originally Posted by VictorN
If you mean that your callback requires much time to process socket connection then try moving it to a worker thread.
No, I mean that in order for Windows to be able to call my callback, my thread must wait, and so I can't accept anymore sockets until the wait state is over, which only happens after Windows call my callback (and my callback returns of course).
-
February 22nd, 2015, 04:50 AM
#4
Re: How can I accept() multiple sockets using Overlapped IO?
Have a look at this WSARecv article in MSDN and at the code example in there.
Victor Nijegorodov
-
February 22nd, 2015, 06:30 AM
#5
Re: How can I accept() multiple sockets using Overlapped IO?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|