Does a blocking recv take processor time?
Hi Everybody,
for a Multiplayer-Game which should compile under Windows as well as under Linux I need (of course) Network code. The question is, if I should use blocking or non-blocking sockets. I have read of the Idea of opening a new thread and in that thread constantly pulling out data from the Socket using recv. On the Server-Side I would have too use Select.
Question: when recv or select blocks, does it use any sgnificant processor time?
I also would like to know, if you guys think, that this is a good way of doing it and how high you would set the priority if this thread.
Thanks!
Nathan
[edited by - LonelyStar on June 27, 2003 2:21:47 AM]
I believe the only processor time a blocking recv() calls takes, is the time for the thread to transition from user-mode to kernel-mode. Once the recv() call blocks, no processor time is used until data arrives.
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
www.digitalfiends.com
if you dont want that thread to go on processing other stuff I think it is best to use the blocking call, since it doesnt takes processor time (the system awakes it when data arrives, and in the free time that makes more proccesor time available for other threads ...), but if you use a while and keep checking, everyone of those times you check to see if it is ready it is using the processor ...
honestly that is what I now and nothing else, that might not work for your situation, also one can use a "blocking" socket in such a way that it returns with an "error" if some amount of time defined by you passed ... (I dont remember how to tough ...)
Just think about what you are needing, for example you might be using just one thread, in which case you probably want to do some stuff instead of keep waiting which your hands tied (because of the blocked call), such as update the display, ... if that is the case you really need not blocking (you could also use a the one with a max time I mentioned above, using a really short time) ... but, if instead you have a thread that only cares about receiving client data and placing it in some place/structure in memory you better choose a blocking one which makes more processing time available for the other threads ...
honestly that is what I now and nothing else, that might not work for your situation, also one can use a "blocking" socket in such a way that it returns with an "error" if some amount of time defined by you passed ... (I dont remember how to tough ...)
Just think about what you are needing, for example you might be using just one thread, in which case you probably want to do some stuff instead of keep waiting which your hands tied (because of the blocked call), such as update the display, ... if that is the case you really need not blocking (you could also use a the one with a max time I mentioned above, using a really short time) ... but, if instead you have a thread that only cares about receiving client data and placing it in some place/structure in memory you better choose a blocking one which makes more processing time available for the other threads ...
Eglasius - I can see how the power flows within you, open your eyes and live in a new world.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement