summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2018-03-28 23:50:08 +0900
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-04-06 08:52:14 +0200
commitad8961511ad34e6159db092bde052a4fab4375c7 (patch)
tree2c1fac4ef5405b2850209e3c7928dd76e42306bb /sal
parent8091d2142e52447f4d880c979079dd1c2c2e1236 (diff)
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/52018 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/socket.cxx21
1 files changed, 11 insertions, 10 deletions
diff --git a/sal/osl/unx/socket.cxx b/sal/osl/unx/socket.cxx
index 347c3e915686..dcd7b5509aba 100644
--- a/sal/osl/unx/socket.cxx
+++ b/sal/osl/unx/socket.cxx
@@ -1401,7 +1401,6 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket,
fd_set ExcptSet;
int ReadyHandles;
struct timeval tv;
- oslSocketResult Result= osl_Socket_Ok;
SAL_WARN_IF( !pSocket, "sal.osl", "undefined socket" );
@@ -1490,13 +1489,19 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket,
nSockOpt = getsockopt ( pSocket->m_Socket, SOL_SOCKET, SO_ERROR,
&nErrorCode, &nErrorSize );
if ( (nSockOpt == 0) && (nErrorCode == 0))
- Result = osl_Socket_Ok;
+ {
+ osl_enableNonBlockingMode(pSocket, false);
+ return osl_Socket_Ok;
+ }
else
- Result = osl_Socket_Error;
+ {
+ pSocket->m_nLastError = (nSockOpt == 0) ? nErrorCode : errno;
+ return osl_Socket_Error;
+ }
}
else
{
- Result= osl_Socket_Error;
+ return osl_Socket_Error;
}
}
else if (ReadyHandles < 0) /* error */
@@ -1508,17 +1513,13 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket,
return osl_Socket_Interrupted;
}
pSocket->m_nLastError=errno;
- Result= osl_Socket_Error;
+ return osl_Socket_Error;
}
else /* timeout */
{
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,