[Libreoffice-commits] core.git: sal/osl
Takeshi Abe
tabe at fixedpoint.jp
Fri Apr 6 06:52:35 UTC 2018
sal/osl/unx/socket.cxx | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
New commits:
commit ad8961511ad34e6159db092bde052a4fab4375c7
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date: Wed Mar 28 23:50:08 2018 +0900
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 at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
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,
More information about the Libreoffice-commits
mailing list