943,691 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1658
  • C++ RSS
Jul 2nd, 2009
0

How to make a non-blocking socket?

Expand Post »
I have done alot of stuff with Winsock, but it's all with sockets that can olni process one at a time.


Can anyone tell me how to make a non-blocking socket? [send and recive]
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
azjherben is offline Offline
33 posts
since May 2009
Jul 2nd, 2009
0

Re: How to make a non-blocking socket?

Rather then do that, how about going with Worker Threads and I/O completion ports!

Very lightweight and you can associate a socket with a user value so since few threads are handling a multitude of sockets, the user value (an index) can be used to connect the traffic to the correct data buffers.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jul 2nd, 2009
0

Re: How to make a non-blocking socket?

Thanks, but do you know a tutorial on that?
Reputation Points: 10
Solved Threads: 1
Light Poster
azjherben is offline Offline
33 posts
since May 2009
Jul 2nd, 2009
-1

Re: How to make a non-blocking socket?

Ever heard of GOOGLE ??? You get loads there...!!!
Reputation Points: 485
Solved Threads: 88
Posting Pro
csurfer is offline Offline
564 posts
since Jan 2009
Jul 2nd, 2009
0

Re: How to make a non-blocking socket?

Yes, thank you CSurfer.

The very quick brief is first you calculate how many processors are in your computer then multiply by two and launch that many threads. You'll have to do a bit more to micro-manage them for the processor distribution if you want more balance. They get put to sleep waiting for an event generated by the I/O completion port. The I/O completion port also waits for events generated by your sockets. (IOCP's can be used for other event types too!) An I/O event occurs, a thread is wakened and a user value is handed to the thread as to what event object caused an event. So the thread wakes up, checks the status of the socket, and deals with it accordingly then goes back to sleep.

That's the short brief but its a very cool mechanism. I have used it for running thousands of sockets on quad and sixteen core systems.
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jul 2nd, 2009
0

Re: How to make a non-blocking socket?

If you could just tell me how to set a socket to non blocking and explain select() to me I'd be grateful.
Reputation Points: 10
Solved Threads: 1
Light Poster
azjherben is offline Offline
33 posts
since May 2009
Jul 3rd, 2009
1

Re: How to make a non-blocking socket?

Click to Expand / Collapse  Quote originally posted by azjherben ...
If you could just tell me how to set a socket to non blocking and explain select() to me I'd be grateful.
http://tangentsoft.net/wskfaq/exampl...ct-server.html
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Jul 3rd, 2009
1

Re: How to make a non-blocking socket?

Click to Expand / Collapse  Quote originally posted by azjherben ...
and explain select() to me I'd be grateful.
Beej is your friend. I can't explain it better then he did.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Intro and question
Next Thread in C++ Forum Timeline: Need some help understanding MFC





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC