CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2015
    Posts
    66

    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!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    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

  3. #3
    Join Date
    Feb 2015
    Posts
    66

    Re: How can I accept() multiple sockets using Overlapped IO?

    Quote Originally Posted by VictorN View Post
    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).

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    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

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    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
  •  





Click Here to Expand Forum to Full Width

Featured