• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Detecting cable unplug/Network failure
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Detecting cable unplug/Network failure


  • Subject: Detecting cable unplug/Network failure
  • From: David GarcĂ­a <email@hidden>
  • Date: Mon, 02 Mar 2009 18:27:02 +0100

Hi,

I'm quite new in Mac programming, and I've found some problems where I got stuck in the network. The matter is that, I need to know when there's a physical network error (most immediate cable being unplugged). First I had all the stuff done with CFSocket build from a native socket. It worked fine, I'm aware of |kCFSocketReadCallBack and ||kCFSocketWriteCallBack |event types. The problem is that I can't find any event type that warns me of a network error (cable unplug). When I perform writes to the socket, the OS seems to take bytes without problem (saving them into internal buffers I imagine), but doesn't return an error.

I've tried to perform also ioctl calls on the native socket descriptor, trying to get some information. (SIOCGIFSTATUS, SIOCGIFPHYS, SIOCSIFFLAGS) but the call always failed and I'm not sure why. A "Device not configured" or similar message was the result of strerror. (can't remember the exact error).

Later I decided to use CF{Read,Write}Stream created from the CFStreamCreatePairWithSocket function, those seem to have the ability to notify of many events, including kCFStreamEventErrorOccurred. So now I finally can detect network errors, such cable disconnect so my application can start performing its reconnection routines, and connect through wireless if available. That works fine too.

So my problem with CFStreams is that if I connect the cable again, I'm notified of a network error again (and with same error code), so now I start reconnection routines when it's not needed.

I would like to have my program running with CFSockets, and ioctl combination if that would solve my problem. But if it's not feasible, just knowing how to avoid the false network error provided by CFStreams.

Please, I would like to get some advice in the best way to solve that. I'm pretty disoriented in this Mac world, so any help will be very helpful.
Thanks a lot.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: Detecting cable unplug/Network failure
      • From: Jens Alfke <email@hidden>
    • Re: Detecting cable unplug/Network failure
      • From: Peter Sichel <email@hidden>
  • Next by Date: Re: Detecting cable unplug/Network failure
  • Next by thread: Re: Detecting cable unplug/Network failure
  • Index(es):
    • Date
    • Thread