Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:33:46+00:00 2026-06-05T08:33:46+00:00

I’m implementing a client/server pair, commnicating through TCP/IP sockets, using overlapped IO with completion

  • 0

I’m implementing a client/server pair, commnicating through TCP/IP sockets, using overlapped IO with completion routines in Windows. The debugging is being done with two VirtualBox virtual machines (client in one, server in another). The CPU is a Quad-Core.

The sequence of operations on the client is basically:

  • Issues a WSARecv call (will not complete as of yet).
  • Issues a WSASend call with a packet. The server will send a reply through the same socket.
  • Once the completion routine for the WSASend call is executed the packet is placed in a waiting-for-reply queue.
  • Once the completion routine for the WSARecv call executes (reply from server received), the code tries to locate the packet related to this reply in the queue.
  • Issues a WSARecv call (will not complete as of yet).
  • Repeat from the second step.

The sequence of operations on the server is basically:

  • Issues a WSARecv call (will not complete as of yet).
  • Once the completion routine for the WSARecv call executes (packet from the client received), the packet in processed in a secondary thread.
  • Issues a WSARecv call (will not complete as of yet).
  • Once the secondary thread completes a reply is sent to the client, issuing a WSASend call on the primary thread.
  • Repeat from the second step.

The problem I’m having is that sometimes a reply is received on the client without having a corresponding packet in the waiting-for-reply queue. As part of the debugging effort I have two questions:

1) Is it conceivable that, having a pending WSARecv call, the completion routine of the WSARecv is scheduled for execution ahead of the completion routine for the corresponding WSASend (the one that sent the packet to which the server replied) ?

2) If a WSASend call completes immediately is the completion routine still scheduled for execution ?

I’m using a WSAWaitForMultipleEvents call as the alertable wait function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:33:48+00:00Added an answer on June 5, 2026 at 8:33 am

    Your code is broken. Even if the operations were guaranteed to complete in a particular order, that would not ensure that the completion indications were received in any particular order or that the code that handles those completions will run in any particular order.

    The answer to your second question is yes. Generally, you can treat immediate completion the same as pending, since the completion routine will run in either case.

    The ideal solution to your problem is to consider the packet to be waiting for reply as soon as you decide to send it.

    If for some reason that requires too many code changes, you have another choice. If you receive a WSARecv completion and the WSASend completion has not occurred yet, simply defer processing the WSARecv completion. You can do this two ways:

    1. Spawn a thread to wait a fraction of a second and then re-post the completion notification (by calling PostQueuedCompletionStatus) from that thread. Presumably, the WSASend will have completed by then.

    2. Mark a flag that the WSARecv has completed and save the completion information. When the WSASend completes, notice that flag and process the WSARecv then. (Possibly by calling the completion handler directly.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.