How to make a non-blocking socket?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 30
Reputation: azjherben is an unknown quantity at this point 
Solved Threads: 0
azjherben azjherben is offline Offline
Light Poster

How to make a non-blocking socket?

 
0
  #1
Jul 2nd, 2009
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]
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: How to make a non-blocking socket?

 
0
  #2
Jul 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 30
Reputation: azjherben is an unknown quantity at this point 
Solved Threads: 0
azjherben azjherben is offline Offline
Light Poster

Re: How to make a non-blocking socket?

 
0
  #3
Jul 2nd, 2009
Thanks, but do you know a tutorial on that?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 476
Reputation: csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice csurfer is just really nice 
Solved Threads: 76
csurfer's Avatar
csurfer csurfer is offline Offline
Posting Pro in Training

Re: How to make a non-blocking socket?

 
-1
  #4
Jul 2nd, 2009
Ever heard of GOOGLE ??? You get loads there...!!!
I Surf in "C"....
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: How to make a non-blocking socket?

 
0
  #5
Jul 2nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 30
Reputation: azjherben is an unknown quantity at this point 
Solved Threads: 0
azjherben azjherben is offline Offline
Light Poster

Re: How to make a non-blocking socket?

 
0
  #6
Jul 2nd, 2009
If you could just tell me how to set a socket to non blocking and explain select() to me I'd be grateful.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,602
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: How to make a non-blocking socket?

 
1
  #7
Jul 3rd, 2009
Originally Posted by azjherben View Post
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,828
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: How to make a non-blocking socket?

 
1
  #8
Jul 3rd, 2009
Originally Posted by azjherben View Post
and explain select() to me I'd be grateful.
Beej is your friend. I can't explain it better then he did.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC