Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Socket: how to check wether new data arrived? timeout = NULL?
Re: Socket: how to check wether new data arrived? timeout = NULL? [message #7152 is a reply to message #7136] Fri, 15 December 2006 21:45 Go to previous messageGo to previous message
rylek is currently offline  rylek
Messages: 79
Registered: November 2005
Member
Hello!

You are right, current implementation doesn't support reporting the reason for termination of the last Socket::Wait call. The motivation here was that, in practice, select can return due to several reasons - data available on read sockets, ready to send on output sockets, broken connections, EOFs and other network-related situations (OOB data, for instance). I was afraid that, in order to be able to report all combinations of these events, a very complex result structure would be necessary, which seemed to me an overshot. Honestly it still does, although it is true that repeated calls to select (called internally from the PeekXXX method group) might slow down the connection somewhat. My personal reasoning behind letting it be (at least for the time being) is that under normal circumstances the physical network connection is typically orders of magnitude slower than the processing unit of the computer so that a few nanoseconds spent within the call to the select function can hardly substantially hamper performance.

However, the current interface enables (and it is quite possible we'll support this in the future) the introduction of internal status flags which would allow for optimization of the PeekXXX calls so that, after a call to Socket::Wait, the following Peek wouldn't have to call the select function again but just report the socket status as detected by the previous call to Socket::Wait.

It is also true that you cannot Wait infinitely long (although some other methods of the Socket interface, like PeekCount or ReadCount, support Null for their timeout argument and interpret it as the request to wait for an unlimited time until the requested condition is met); however, I personally see not much difference between waiting forever and waiting e.g. for a day (86400000 milliseconds) at a time; honestly, all servers I have written so far usually Wait for just a single second; it seems to me that being able to cycle through the main server loop every few seconds or so it a good idea in almost any case, as it lets you do hosts of other housekeeping actions (like cleaning up idle caches or connections, checking for externally triggered server shutdown or displaying a watchdog message indicating the server is alive).

Regards

Tomas
 
Read Message
Read Message
Read Message
Previous Topic: SmtpMail class
Next Topic: SSLSocket VerifyPeer -> how to set trusted CAs?
Goto Forum:
  


Current Time: Tue Sep 02 10:04:47 CEST 2025

Total time taken to generate the page: 0.06114 seconds