Jump to content
  • Advertisement
Sign in to follow this  
ajm113

Have recv actually wait on another thread? (Winsock & C++)

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

Hello, I'm working on a server that is running on 3 threads. It's a public server so I thought if two threads did maybe the hard work it would take of the wait time and heap of to do on the threads. Thread 1 (Main): Handles incoming connections and directs the client to the correct function. (File upload, account check, etc...) Thread 2: Handles downloads of files for the user. Thread 3: Handles uploads of files from the user. So since I'm using this code to tell recv to not wait for input on the first thread is there a way to tell the recvs on another thread to wait to it recives a message? Multithreading and winsock is making me tare my hair out since the recv function isn't as always accurate when it continues on some threads since the recv function doesn't exactly wait forever. Snippet:

//Initialize after threads initialize.
				timeval val;
			val.tv_sec = 0;
			val.tv_usec = 5;
			select(NULL, NULL, NULL, NULL, &val);




[Edited by - ajm113 on April 23, 2010 6:57:13 PM]

Share this post


Link to post
Share on other sites
Advertisement
I don't understand what you want that code to do, but what it WILL do is simply to sleep for 5 microseconds, no matter whether any sockets are open or not.

In general, if you use select, and are I/O bound, then threads aren't necessary at all. Meanwhile, on Windows, there is a 64 handle per thread wait limitation, which translates into a 64 sockets per select() "soft limit" (it becomes less efficient after that number). If you expect to have more than 64 connections open at the same time, you really want to use I/O completion ports on Windows.

And if you want to use I/O completion ports in C++, your best bet is to use boost::asio...

Share this post


Link to post
Share on other sites
Well alright thank you anyways for clarifying what they do! I wasn't too sure about the select function.

Well what I did was instead of only doing recv on one end of the server. Was just sending a ready message back to the client saying it's ready for more messages and it seemed to fix the problem, but thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!