[Libreoffice-commits] core.git: sal/osl

Chris Sherlock chris.sherlock79 at gmail.com
Sun Aug 27 17:42:07 UTC 2017


 sal/osl/unx/socket.cxx |   19 ++++++++++---------
 sal/osl/w32/socket.cxx |   23 ++++++++++++++++-------
 2 files changed, 26 insertions(+), 16 deletions(-)

New commits:
commit 3d5be8cd31bcf6fce8772133298d2ae076361362
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date:   Mon Aug 28 02:06:41 2017 +1000

    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 at gmail.com>
    Tested-by: Chris Sherlock <chris.sherlock79 at gmail.com>

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;


More information about the Libreoffice-commits mailing list