summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2017-08-28 02:06:41 +1000
committerChris Sherlock <chris.sherlock79@gmail.com>2017-08-27 19:38:39 +0200
commit3d5be8cd31bcf6fce8772133298d2ae076361362 (patch)
treef06b65976f5f6d9fa1cd98a9d66ccdeb2dcde005 /sal
parentbbf3da220e8c031022098a4414fd367c39e228c5 (diff)
osl: give warning on socket error (win32), move Flag definition (unx)
Change-Id: I34b773f32a055dfe85ec9c42e72a9f51ee8fea10 Reviewed-on: https://gerrit.libreoffice.org/41610 Reviewed-by: Chris Sherlock <chris.sherlock79@gmail.com> Tested-by: Chris Sherlock <chris.sherlock79@gmail.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/socket.cxx19
-rw-r--r--sal/osl/w32/socket.cxx23
2 files changed, 26 insertions, 16 deletions
diff --git a/sal/osl/unx/socket.cxx b/sal/osl/unx/socket.cxx
index 90cb1175d17e..594ecfdaaa81 100644
--- a/sal/osl/unx/socket.cxx
+++ b/sal/osl/unx/socket.cxx
@@ -1135,11 +1135,11 @@ oslSocketResult SAL_CALL osl_psz_getDottedInetAddrOfSocketAddr(oslSocketAddr pAd
return osl_Socket_Error;
}
-oslSocket SAL_CALL osl_createSocket(oslAddrFamily Family,
- oslSocketType Type,
- oslProtocol Protocol)
+oslSocket SAL_CALL osl_createSocket(
+ oslAddrFamily Family,
+ oslSocketType Type,
+ oslProtocol Protocol)
{
- int Flags;
oslSocket pSocket;
/* alloc memory */
@@ -1153,7 +1153,7 @@ oslSocket SAL_CALL osl_createSocket(oslAddrFamily Family,
/* creation failed => free memory */
if(pSocket->m_Socket == OSL_INVALID_SOCKET)
{
- int nErrno = errno;
+ sal_Int32 nErrno = errno;
SAL_WARN( "sal.osl", "socket creation failed: (" << nErrno << ") " << strerror(nErrno) );
destroySocketImpl(pSocket);
@@ -1161,14 +1161,15 @@ oslSocket SAL_CALL osl_createSocket(oslAddrFamily Family,
}
else
{
+ sal_Int32 nFlags=0;
/* set close-on-exec flag */
- if ((Flags = fcntl(pSocket->m_Socket, F_GETFD, 0)) != -1)
+ if ((nFlags = fcntl(pSocket->m_Socket, F_GETFD, 0)) != -1)
{
- Flags |= FD_CLOEXEC;
- if (fcntl(pSocket->m_Socket, F_SETFD, Flags) == -1)
+ nFlags |= FD_CLOEXEC;
+ if (fcntl(pSocket->m_Socket, F_SETFD, nFlags) == -1)
{
pSocket->m_nLastError=errno;
- int nErrno = errno;
+ sal_uInt32 nErrno = errno;
SAL_WARN( "sal.osl", "failed changing socket flags: (" << nErrno << ") " << strerror(nErrno) );
}
}
diff --git a/sal/osl/w32/socket.cxx b/sal/osl/w32/socket.cxx
index d1086cbaca4b..70d3b56e7d6b 100644
--- a/sal/osl/w32/socket.cxx
+++ b/sal/osl/w32/socket.cxx
@@ -771,10 +771,10 @@ oslSocketResult SAL_CALL osl_getDottedInetAddrOfSocketAddr (
return osl_Socket_Ok;
}
-oslSocket SAL_CALL osl_createSocket (
+oslSocket SAL_CALL osl_createSocket(
oslAddrFamily Family,
oslSocketType Type,
- oslProtocol Protocol)
+ oslProtocol Protocol)
{
/* alloc memory */
oslSocket pSocket = osl_createSocketImpl_(0);
@@ -783,19 +783,28 @@ oslSocket SAL_CALL osl_createSocket (
return nullptr;
/* create socket */
- pSocket->m_Socket= socket(FAMILY_TO_NATIVE(Family),
- TYPE_TO_NATIVE(Type),
- PROTOCOL_TO_NATIVE(Protocol));
+ pSocket->m_Socket = socket(FAMILY_TO_NATIVE(Family),
+ TYPE_TO_NATIVE(Type),
+ PROTOCOL_TO_NATIVE(Protocol));
/* creation failed => free memory */
if(pSocket->m_Socket == OSL_INVALID_SOCKET)
{
+ sal_uInt32 nErrno = WSAGetLastError();
+ wchar_t *sErr = nullptr;
+ FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, nErrno,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPWSTR)&sErr, 0, NULL);
+ SAL_WARN("sal.osl", "socket creation failed: (" << nErrno << ") " << sErr);
+ LocalFree(sErr);
+
osl_destroySocketImpl_(pSocket);
- pSocket= nullptr;
+ pSocket = nullptr;
}
else
{
- pSocket->m_Flags = 0;
+ pSocket->m_Flags = 0;
}
return pSocket;