Re: Socket lockup when mac put to sleep and woken up
Re: Socket lockup when mac put to sleep and woken up
- Subject: Re: Socket lockup when mac put to sleep and woken up
- From: Arjun SM <email@hidden>
- Date: Wed, 20 Feb 2013 17:45:45 +0530
Thanks for your reply Josh,
Just want to re-confirm if I am following the right procedure here. Please bear with me as i am trying to understand some of the concepts
When machine is woken up from sleep, before making a connection to remote server the daemon,
1. Checks to see if the socket is valid (using getifaddrs function)
2. Send data to remote server
3. if send() fail, clear the sock object and make a new connection.
4. Try to connect again.
Below is the excerpt of the daemon logs
05:09:34 CCatFetcher::AttemptSend - Determinging if socket is valid
05:09:34 CCatFetcher::AttemptSend - Calling send to send data to agency
05:09:34 CCatFetcher::AttemptSend - send didn't work. In Loop. Calling EnsureConnected
05:09:34 CCatFetcher::EnsureConnected() - We just disconnected and reconnected to the Agency!
05:09:34 CCatFetcher::Disconnect
05:09:34 Calling MakeConnectAttempt
05:09:34 SIGPIPE!
post this SIGPIPE I am not able to send any data to the server and I have to restart my machine. Although I have added the code you mentioned below, I fail to understand how it would solve my problem.
Thanks in advance,
~Arjun
On Wed, Feb 20, 2013 at 12:15 AM, Josh Graessley
<email@hidden> wrote:
If you try to write to a socket that is no longer connected, instead of providing a helpful error, the system happily generates a SIGPIPE signal, as you've found. If you don't handle SIGPIPE, your process ends.
To ensure this doesn't happen, you can disable SIGPIPE for the socket:
int val = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &val, sizeof(val)) != 0)
// something went wrong - this is unlikely to happen
-josh
On Feb 19, 2013, at 10:40 AM, Arjun SM <
email@hidden> wrote:
> Hi all,
>
> I have implemented a daemon which tries to make a connection to a server using non-blocking sockets and works fine. But the problem surfaces, when I put my Mac machine to sleep for few hours and wake it up. My daemon hangs and i get a SIGPIPE on the error console after some time.
> I am running Mountain Lion OS X 10.8.2 version.
>
> The MakeConnect() function which I am using in my daemon is fairly simple and below is an excerpt,
> m_AgencySock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
>
> set the socket to non-Blocking
> int err = fcntl(m_AgencySock, F_SETFL, O_NONBLOCK);
>
> int status = connect(m_AgencySock, (struct sockaddr *)&m_AgencyAddress, sizeof(m_AgencyAddress));
> if (status < 0)
> {
> status = errno; // Check the error number to get our current status
> if (status == EINPROGRESS)
> {
> FD_ZERO(&readFDs);
> FD_ZERO(&writeFDs);
> FD_SET(m_AgencySock, &readFDs);
> FD_SET(m_AgencySock, &writeFDs);
>
> Call select with struct timeval waitd in a while loop and check for selectResult > 0 and break;
> waitd.tv_sec = 10;
> waitd.tv_usec = 0;
> selectResult = select(m_AgencySock + 1, &readFDs, &writeFDs, NULL, &waitd);
>
> }
> }
>
> I am resetting the struct timeval waitd before calling select() again.
>
> is there any other parameters that needs to addressed?
>
> thanks in advance,
> ~Arjun
>
> _______________________________________________
> 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