sal/osl/w32/socket.cxx |   40 ++++++++--------------------------------
 1 file changed, 8 insertions(+), 32 deletions(-)

New commits:
commit afc41a467fdfabb2cd0879be3e4f1879a1d1dc91
Author:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
AuthorDate: Thu Dec 10 09:31:29 2020 +0100
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
CommitDate: Thu Dec 10 14:21:15 2020 +0100

    Do not call GetAddrInfoW if we just want the hostname
    
    Calling 'gethostname' already gives us the current host name on Windows.
    For some reason, if that name does not contain a dot, GetAddrInfoW is
    called, which "provides protocol-independent translation from a Unicode
    host name to an address".
    
    So all this function does, is returning an address for a hostname,
    while we still only need the hostname and not the address.
    
    This causes a lag when creating the lockfile on opening a document
    if the network is flaky/disabled.
    See tdf#97931 and tdf#47179 for some problems caused by this.
    
    Change-Id: I0c543ea12c23506b2daa50da40bae1a471f6fe16
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107513
    Tested-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>

diff --git a/sal/osl/w32/socket.cxx b/sal/osl/w32/socket.cxx
index f1c46e8f2568..ba96cc5ed838 100644
--- a/sal/osl/w32/socket.cxx
+++ b/sal/osl/w32/socket.cxx
@@ -613,39 +613,15 @@ oslSocketResult SAL_CALL osl_getLocalHostname 
(rtl_uString **strLocalHostname)
             char Host[256]= "";
             if (gethostname(Host, sizeof(Host)) == 0)
             {
-                /* check if we have an FQDN; if not, try to determine it via 
dns first: */
-                if (strchr(Host, '.') == nullptr)
+                OUString u;
+                if (rtl_convertStringToUString(
+                        &u.pData, Host, strlen(Host), 
osl_getThreadTextEncoding(),
+                        (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
+                            | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
+                            | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))
+                    && o3tl::make_unsigned(u.getLength()) < 
SAL_N_ELEMENTS(LocalHostname))
                 {
-                    oslHostAddr pAddr;
-                    rtl_uString     *hostName= nullptr;
-
-                    rtl_string2UString(
-                        &hostName, Host, strlen(Host),
-                        RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS);
-                    OSL_ASSERT(hostName != nullptr);
-
-                    pAddr = osl_createHostAddrByName(hostName);
-                    rtl_uString_release (hostName);
-
-                    if (pAddr && pAddr->pHostName)
-                        memcpy(LocalHostname, pAddr->pHostName->buffer, 
sizeof(sal_Unicode)*(rtl_ustr_getLength(pAddr->pHostName->buffer)+1));
-                    else
-                        memset(LocalHostname, 0, sizeof(LocalHostname));
-
-                    osl_destroyHostAddr (pAddr);
-                }
-                if (LocalHostname[0] == u'\0')
-                {
-                    OUString u;
-                    if (rtl_convertStringToUString(
-                            &u.pData, Host, strlen(Host), 
osl_getThreadTextEncoding(),
-                            (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR
-                             | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
-                             | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))
-                        && o3tl::make_unsigned(u.getLength()) < 
SAL_N_ELEMENTS(LocalHostname))
-                    {
-                        memcpy(LocalHostname, u.getStr(), (u.getLength() + 1) 
* sizeof (sal_Unicode));
-                    }
+                    memcpy(LocalHostname, u.getStr(), (u.getLength() + 1) * 
sizeof (sal_Unicode));
                 }
             }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to