Kaydet (Commit) ad896151 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) Noel Grandin

osl: Remember the last error before returning osl_Socket_Error

This prevents from e.g. com.sun.star.bridge.UnoUrlResolver's
emitting confusing messages, when trying to connect to a port
on which no LibreOffice process is listening, like:
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  __main__.NoConnectException: Connector : couldn't connect to socket (Success)
                                                                        ^^^^^^^
After applying this patch:
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
>  __main__.NoConnectException: Connector : couldn't connect to socket (Connection refused)

You can see the above behavior with the following python code:

import uno
x = uno.getComponentContext()
y = x.ServiceManager
z = y.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", x)
url = "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
a = z.resolve(url)

... provided that no process is waiting on port 2002.

Change-Id: Id094cf9271fe77d84f2284d91a0e452448de2bc2
Reviewed-on: https://gerrit.libreoffice.org/52018Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 8091d214
...@@ -1401,7 +1401,6 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket, ...@@ -1401,7 +1401,6 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket,
fd_set ExcptSet; fd_set ExcptSet;
int ReadyHandles; int ReadyHandles;
struct timeval tv; struct timeval tv;
oslSocketResult Result= osl_Socket_Ok;
SAL_WARN_IF( !pSocket, "sal.osl", "undefined socket" ); SAL_WARN_IF( !pSocket, "sal.osl", "undefined socket" );
...@@ -1490,13 +1489,19 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket, ...@@ -1490,13 +1489,19 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket,
nSockOpt = getsockopt ( pSocket->m_Socket, SOL_SOCKET, SO_ERROR, nSockOpt = getsockopt ( pSocket->m_Socket, SOL_SOCKET, SO_ERROR,
&nErrorCode, &nErrorSize ); &nErrorCode, &nErrorSize );
if ( (nSockOpt == 0) && (nErrorCode == 0)) if ( (nSockOpt == 0) && (nErrorCode == 0))
Result = osl_Socket_Ok; {
osl_enableNonBlockingMode(pSocket, false);
return osl_Socket_Ok;
}
else else
Result = osl_Socket_Error; {
pSocket->m_nLastError = (nSockOpt == 0) ? nErrorCode : errno;
return osl_Socket_Error;
}
} }
else else
{ {
Result= osl_Socket_Error; return osl_Socket_Error;
} }
} }
else if (ReadyHandles < 0) /* error */ else if (ReadyHandles < 0) /* error */
...@@ -1508,17 +1513,13 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket, ...@@ -1508,17 +1513,13 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket,
return osl_Socket_Interrupted; return osl_Socket_Interrupted;
} }
pSocket->m_nLastError=errno; pSocket->m_nLastError=errno;
Result= osl_Socket_Error; return osl_Socket_Error;
} }
else /* timeout */ else /* timeout */
{ {
pSocket->m_nLastError=errno; pSocket->m_nLastError=errno;
Result= osl_Socket_TimedOut; return osl_Socket_TimedOut;
} }
osl_enableNonBlockingMode(pSocket, false);
return Result;
} }
oslSocket SAL_CALL osl_acceptConnectionOnSocket(oslSocket pSocket, oslSocket SAL_CALL osl_acceptConnectionOnSocket(oslSocket pSocket,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment