• 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
Re: Socket lockup when mac put to sleep and woken up
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Socket lockup when mac put to sleep and woken up


  • Subject: Re: Socket lockup when mac put to sleep and woken up
  • From: Josh Graessley <email@hidden>
  • Date: Tue, 19 Feb 2013 10:45:46 -0800

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

  • Follow-Ups:
    • Re: Socket lockup when mac put to sleep and woken up
      • From: Arjun SM <email@hidden>
References: 
 >Socket lockup when mac put to sleep and woken up (From: Arjun SM <email@hidden>)

  • Prev by Date: Socket lockup when mac put to sleep and woken up
  • Next by Date: Re: Socket lockup when mac put to sleep and woken up
  • Previous by thread: Socket lockup when mac put to sleep and woken up
  • Next by thread: Re: Socket lockup when mac put to sleep and woken up
  • Index(es):
    • Date
    • Thread