Re: "Broken Pipe" always fatal?
Re: "Broken Pipe" always fatal?
- Subject: Re: "Broken Pipe" always fatal?
- From: Josh Graessley <email@hidden>
- Date: Fri, 29 Apr 2011 15:09:01 -0700
On Apr 29, 2011, at 2:55 PM, Nathan Sims wrote:
> Interesting. So if I use SO_NOSIGPIPE on the socket and set SIGPIPE to SIG_IGN, what potential change in behavior would result?
If SO_NOSIGPIPE is set, an operation that would have generated SIGPIPE will just result in a failure and errno will be set to EPIPE. I think you only get SIGPIPE when you try to write to a pipe or socket and the write side of the socket is closed such as when you call shutdown(sockfd, SHUT_WR), the remote side closed the connection, etc.
Setting the SIGPIPE handler to SIG_IGN will eliminate the default SIGPIPE handler which just causes your process to exit.
A bit off topic but...If you're writing a library or framework it is considered best practice to use the SO_NOSIGPIPE socket option with sockets your library/framework manages and not mess with the SIGPIPE handler as the SIGPIPE handler really belongs to the process your library/framework is running in.
-josh
> On Apr 29, 2011, at 1:39 PM, Josh Graessley wrote:
>>
>> You can disable the signal for a socket using the SO_NOSIGPIPE socket option as an alternative to handling SIGPIPE. You can then set your process to ignore SIGPIPE.
>>
>> Once you get an EPIPE error when trying to perform an operation on a socket, that socket is toast. You need to close the socket and attempt to create a new connection. If the new connection fails you can use SCNetworkReachability to be notified when you should attempt the connection again.
>>
>> -josh
>>
>> On Apr 29, 2011, at 1:16 PM, Nathan Sims wrote:
>>
>>> When wifi signals get sufficiently weak, I sometimes receive "Broken Pipe" errors in my TCP/IP-based app, which I trap. I close the connection and reconnect. Is a broken pipe always truly fatal to the connection, or is there a way or socket setting to "ride it out"? I've noticed that it does not seem to ever reconnect by itself. All operations afterwards also receive the broken pipe error until I close() and reconnect...
>>>
>>>
>>> _______________________________________________
>>> 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
>>
>
_______________________________________________
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