< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index Next in Thread >

Re: [reSIProcate-users] Unexpected TCP connection termination disturbing call setup


Hello,

  Using getErrno() instead of errno in Connection.cxx as suggested did NOT
work.
  
  I added then some additional calls to getErrno() inside TcpConnection.cxx
after the original 
  
int e = getErrno(); 
  
  and could see that after the call

InfoLog (<< "Failed write on " << getSocket() << " " << strerror(e));

  getErrno() returns 0.
  
  MSDN doc for WSAGetLastError()
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms741580%28v=vs.85%
29.aspx)  
advises: 
"If a function call's return value indicates that error or other relevant
data was returned in the error code, 
WSAGetLastError should be called immediately. This is necessary because some
functions may reset the last extended 
error code to 0 if they succeed, overwriting the extended error code
returned by a previously failed function. "    

  That reset seems to be happening inside InfoLog() or getSocket() or
strerror().
  
Regards,
Julio.

----------------------------------------------------------------------------
----------------------------------------------------------

From: slgodin@xxxxxxxxx [mailto:slgodin@xxxxxxxxx] On Behalf Of Scott Godin
Sent: terça-feira, 15 de outubro de 2013 18:28
To: Julio Cabezas
Cc: resiprocate-users@xxxxxxxxxxxxxxx
Subject: Re: [reSIProcate-users] Unexpected TCP connection termination
disturbing call setup

Hi Julio,

I think I see the problem - the code in TcpTransport uses getErrno() helper
API (which calls WSAGetLastError instead of using the global errno that *nix
systems use) and the code in conneciton just uses errno.  Can you please try
just changing the following lines in Connection.cxx (near line 168) to use
the getErrno() call instead?

If this works for you I will commit this fix.  Thanks for your patience and
help in tracking this down.

   int nBytes = write(data.data() + mSendPos,int(data.size() - mSendPos));
   if (nBytes < 0)
   {  
      if (getErrno() != EAGAIN && getErrno() != EWOULDBLOCK) // Treat EGAIN
and EWOULDBLOCK as the
same: http://stackoverflow.com/questions/7003234/which-systems-define-eagain
-and-ewouldblock-as-different-values
      {
         //fail(data.transactionId);
         InfoLog(<< "Write failed on socket: " << this->getSocket() << ",
closing connection");
         return -1;
      }
      else
      {
         return 0;
      }
   }

Scott