DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   How to make a non-blocking socket? (http://www.daniweb.com/forums/thread201343.html)

azjherben Jul 2nd, 2009 7:15 pm
How to make a non-blocking socket?
 
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]

wildgoose Jul 2nd, 2009 7:26 pm
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.

azjherben Jul 2nd, 2009 8:17 pm
Re: How to make a non-blocking socket?
 
Thanks, but do you know a tutorial on that?

csurfer Jul 2nd, 2009 8:53 pm
Re: How to make a non-blocking socket?
 
Ever heard of GOOGLE ??? You get loads there...!!!

wildgoose Jul 2nd, 2009 9:00 pm
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.

azjherben Jul 2nd, 2009 9:25 pm
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.

jephthah Jul 3rd, 2009 2:11 am
Re: How to make a non-blocking socket?
 
Quote:

Originally Posted by azjherben (Post 906995)
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

niek_e Jul 3rd, 2009 4:21 am
Re: How to make a non-blocking socket?
 
Quote:

Originally Posted by azjherben (Post 906995)
and explain select() to me I'd be grateful.

Beej is your friend. I can't explain it better then he did.


All times are GMT -4. The time now is 7:11 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC