• 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
Socket timeout issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Socket timeout issue


  • Subject: Socket timeout issue
  • From: Mitchell Laurren-Ring <email@hidden>
  • Date: Thu, 6 Sep 2007 14:23:51 -0700

I have an application that keeps a socket open to a server nearly continuously. If the socket connection is established and then the underlying network connection is changed (for example, from ethernet to Airport), the next attempt to send via that socket fails but only after a timeout period of around 9 minutes and 50 seconds. After the timeout, our code can recover correctly by closing the old socket and establishing a new socket. The problem, obviously, is the very long timeout. I've tried setting the send and receive timeouts thusly:

bzero(&tval, sizeof(tval));
tval.tv_sec = 2;
tval.tv_usec = 0;
result = setsockopt(m_AgencySock, SOL_SOCKET, SO_SNDTIMEO, &tval, sizeof(tval));
result = setsockopt(m_AgencySock, SOL_SOCKET, SO_RCVTIMEO, &tval, sizeof(tval));


I tried this code after establishing the socket and then also after connecting the socket, but it has no effect on the timeout period. During my research on this problem, I read that the default timeout is zero so it seems like setting the timeout should not be necessary in this case. Regardless, to confirm that I had properly set the timeout, I added the following code immediately before the send operation:

getsockopt(m_AgencySock, SOL_SOCKET, SO_SNDTIMEO, (void*)&tval, &optlen);

I confirmed that tval contains the correct values. The following code is the method by which we attempt to send data over the socket:

	while(send(m_Sock, request, len, 0) <= 0)
	{
		EnsureConnected();
		if(--Attempts <= 0)
			return false;
	}

Note that EnsureConnected closes the socket connection and attempts to re-open it. That part works beautifully, but as I said earlier, the timeout on the send is nearly 10 minutes.

I've already embarked on a series of failed workarounds so I thought it prudent to consult the wisdom here before continuing. Is there an aspect to setting the timeout in this case that I am missing?



Mitchell J Laurren-Ring
Critical Path Software



_______________________________________________
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 timeout issue
      • From: Quinn <email@hidden>
    • Re: Socket timeout issue
      • From: "Peter Sichel" <email@hidden>
  • Prev by Date: Re: How to set destination address on UDP?
  • Next by Date: Re: Socket timeout issue
  • Previous by thread: Re: How to set destination address on UDP?
  • Next by thread: Re: Socket timeout issue
  • Index(es):
    • Date
    • Thread