From: Felix Windt Date: 2008-03-22T02:30:21+09:00 Subject: Re: Test for Internet Connection ------=_Part_1716_33451168.1206120632085 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Fri, Mar 21, 2008 at 8:04 AM, Lionel Bouton < lionel-subscription@bouton.name> wrote: > Cory Cory wrote: > >> sudo gem install dbus > > > > Well after all of that, I can't compile the dbus gem unless I download > > and compile the newest version of the real dbus (because the deb is > > still out of date). Interfering with my deb's is not something I like > > doing because of updates, so I guess I'll just have to wait. > > > > Maybe Hardy Heron will solve my problems. > > > > If Ruby just had system threading this would not even be an issue. > > Your problem isn't clear enough for a good advice : do you need an > answer to the "Is net available?" in finite time or do you want to > continue processing while you wait for the answer? > > If you want to continue processing, your only need is a non-blocking > communication channel with another process/thread. The usual solution is > to use an event loop, in this case something like popen with the ping > program or whatever you need would give you the asynchronous behaviour > you need. > > I've a strong opinion on threads (built on several projects where > avoiding deadlocks between them took most of my time instead of adding > functionnalities): if you can avoid them (don't need the power of > several CPU cores and even then multi-process is an option), go for the > event-loop. In Ruby's case, where multi-threading doesn't use multiple > cores, I only use threads in the simplest conditions (fetching several > URIs in parallel with no interlocking for example). > > If you only need an answer in finite time, see man ping on your OS. > > Lionel > > I'd just like to add to this thread that regardless of locking issues, pinging may not be the definitive test for whether or not you have internet connectivity. Just that you cannot ping doesn't mean you can't build TCP circuits to a port 80, and conversely just being able to ping doesn't mean you're not behind some evilly or otherwise misconfigured firewall that will drop all you traffic to destination port 80. In short, you may be getting false positives as well as false negatives, and testing for internet connectivity should involve testing what you actually intend to do. If you application needs to fetch something via TCP from destination port 80, do that. Felix ------=_Part_1716_33451168.1206120632085--