Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

FriedDragon

Help!About the completion port.

This topic is 5718 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

When I have delivered two or more operations to the completion port, including input and output operations, how do I know which kind of the operation(input or output) the port has just returned?

Share this post


Link to post
Share on other sites
Advertisement
You will need to pass in your own structure pointer as a parameter to the queueing call (WSARecv/WSASend) with some enum that will dictate which operation was queued, which can be picked up by GetQueuedCompletionStatus(). Check out

http://msdn.microsoft.com/msdnmag/issues/1000/Winsock/

for how it''s done.

-cb

Share this post


Link to post
Share on other sites
> ... [from private email] ...
> I can''t understand why did the
> MS developers not add a context
> pointer into the overlapped structure
> or just something else. Is it a very
> common approach to change pointers
> between two kinds of structures
> with different sizes, or is it
> considered as a bad one most of the time?

Completion ports came after overlapped I/O; so in order not to break older code, MS decided to introduce this ''structure-hack-a-roo'' trick to pass in more information into the existing API.

> ... [from private email] ...
> I noticed that the author suggested
> creating an individual worker thread for
> looping AcceptEx(), as well as checking
> SO_CONNECT_TIME option occasionally with
> the sockets supplied to AcceptEx(). So
> shall we conclude that we need one more
> worker thread just for checking sockets''
> options?

In general, you should have at least one more worker thread than there are CPUs in your machine so that the accept()/connect() pair on each end of the connection can return quickly if you expect a higher-than-average connection rate. I usually bundle the accept/read/write operations in the same code that the worker thread pool runs on because I expect a low connection rate but a higher data transfer rate (i.e. sparse clients, but they stay on longer and exchange large data blocks). A stock ticker application will have the opposite requirements: very high connection rate and very low connection time/data transfers, thus the need to separate the connection thread from the data transfer thread pool (and assign them different priorities) to make sure the connected clients do not go into starvation because of all the attention given to the pending connections.

-cb

Share this post


Link to post
Share on other sites
Thank you for your quite clear explanation. I''ll try to keep
the balance between the performance and the threads'' number
of my thread pool. Wish not trouble you too much.

Share this post


Link to post
Share on other sites
Having used IOCPorts in commercial projects, keep your number of threads to the number of processors times two.

This assumes you write fairly decent multi-threaded code that will not deadlock each other.

Also, do performance checking on some of your function calls, determine the slow ones, and create a secondary completion port to handle those calls that take an extraordinary amount of time. i.e., CreateFile, etc...

[edited by - LordShade on April 20, 2003 4:59:24 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!