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
>