Author: hbelusca
Date: Fri Mar  3 23:31:32 2017
New Revision: 74041

URL: http://svn.reactos.org/svn/reactos?rev=74041&view=rev
Log:
[WS2_32]: Cosmetic changes first, before real fixes - CORE-12880 :
- Use IsListEmpty where needed;
- Initialize NextEntry using Catalog->ProtocolList after the lock on the 
catalog has been acquired;
- Rearrange WsNqLookupServiceNext to reduce the code indent level; also, 
convert the construct "if (var) { do { ... } while (var); }" into a mere "while 
(var) { ... }";
- WsNqPreviousProvider: the "next" provider is the previous one...;
- WsNqAddProvider: Use a more standard name for the boolean return value;
- Fix the annotation of MapUnicodeQuerySetToAnsi;
- Factor out setting the SetLastError WSALookupServiceBeginA.

Modified:
    trunk/reactos/dll/win32/ws2_32/src/async.c
    trunk/reactos/dll/win32/ws2_32/src/dcatalog.c
    trunk/reactos/dll/win32/ws2_32/src/nscatalo.c
    trunk/reactos/dll/win32/ws2_32/src/nsquery.c
    trunk/reactos/dll/win32/ws2_32/src/qshelpr.c
    trunk/reactos/dll/win32/ws2_32/src/rnr.c

Modified: trunk/reactos/dll/win32/ws2_32/src/async.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/async.c?rev=74041&r1=74040&r2=74041&view=diff
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/async.c  [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/async.c  [iso-8859-1] Fri Mar  3 
23:31:32 2017
@@ -721,7 +721,7 @@
         WsAsyncLock();
 
         /* Process the queue */
-        while (ListHead->Flink != ListHead)
+        while (!IsListEmpty(ListHead))
         {
             /* Remove this entry and get the async block */
             Entry = RemoveHeadList(ListHead);

Modified: trunk/reactos/dll/win32/ws2_32/src/dcatalog.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/dcatalog.c?rev=74041&r1=74040&r2=74041&view=diff
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/dcatalog.c       [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/dcatalog.c       [iso-8859-1] Fri Mar  3 
23:31:32 2017
@@ -384,7 +384,7 @@
                    IN PTCATALOG_ENTRY *CatalogEntry)
 {
     INT ErrorCode = WSAEINVAL;
-    PLIST_ENTRY NextEntry = Catalog->ProtocolList.Flink;
+    PLIST_ENTRY NextEntry;
     PTCATALOG_ENTRY Entry;
 
     /* Assume failure */
@@ -394,6 +394,7 @@
     WsTcLock();
 
     /* Match the Id with all the entries in the List */
+    NextEntry = Catalog->ProtocolList.Flink;
     while (NextEntry != &Catalog->ProtocolList)
     {
         /* Get the Current Entry */
@@ -435,13 +436,14 @@
                                IN PTCATALOG_ENTRY *CatalogEntry)
 {
     INT ErrorCode = WSAEINVAL;
-    PLIST_ENTRY NextEntry = Catalog->ProtocolList.Flink;
+    PLIST_ENTRY NextEntry;
     PTCATALOG_ENTRY Entry;
 
     /* Lock the catalog */
     WsTcLock();
 
     /* Match the Id with all the entries in the List */
+    NextEntry = Catalog->ProtocolList.Flink;
     while (NextEntry != &Catalog->ProtocolList)
     {
         /* Get the Current Entry */
@@ -483,7 +485,7 @@
                         IN PTCATALOG_ENTRY *CatalogEntry)
 {
     INT ErrorCode = WSAEINVAL;
-    PLIST_ENTRY NextEntry = Catalog->ProtocolList.Flink;
+    PLIST_ENTRY NextEntry;
     PTCATALOG_ENTRY Entry;
     DPRINT("WsTcGetEntryFromTriplet: %lx, %lx, %lx, %lx\n", af, type, 
protocol, StartId);
 
@@ -492,6 +494,8 @@
 
     /* Lock the catalog */
     WsTcLock();
+
+    NextEntry = Catalog->ProtocolList.Flink;
 
     /* Check if we are starting past 0 */
     if (StartId)
@@ -674,14 +678,14 @@
     RemoveEntryList(&Catalog->ProtocolList);
     InitializeListHead(&Catalog->ProtocolList);
 
-    /* Loop every item on the list */
+    /* Loop every item in the list */
     while (!IsListEmpty(List))
     {
         /* Get the catalog entry */
         Entry = RemoveHeadList(List);
         CatalogEntry = CONTAINING_RECORD(Entry, TCATALOG_ENTRY, CatalogLink);
 
-        /* Check if this item is already on our list */
+        /* Check if this item is already in our list */
         Entry = TempList.Flink;
         while (Entry != &TempList)
         {
@@ -709,7 +713,7 @@
         Catalog->ItemCount++;
     }
 
-    /* If there's anything left on the temporary list */
+    /* If there's anything left in the temporary list */
     while (!IsListEmpty(&TempList))
     {
         /* Get the entry */

Modified: trunk/reactos/dll/win32/ws2_32/src/nscatalo.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/nscatalo.c?rev=74041&r1=74040&r2=74041&view=diff
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/nscatalo.c       [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/nscatalo.c       [iso-8859-1] Fri Mar  3 
23:31:32 2017
@@ -498,13 +498,14 @@
                              IN LPGUID ProviderId,
                              OUT PNSCATALOG_ENTRY *CatalogEntry)
 {
-    PLIST_ENTRY NextEntry = Catalog->CatalogList.Flink;
+    PLIST_ENTRY NextEntry;
     PNSCATALOG_ENTRY Entry;
 
     /* Lock the catalog */
     WsNcLock();
 
     /* Match the Id with all the entries in the List */
+    NextEntry = Catalog->CatalogList.Flink;
     while (NextEntry != &Catalog->CatalogList)
     {
         /* Get the Current Entry */

Modified: trunk/reactos/dll/win32/ws2_32/src/nsquery.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/nsquery.c?rev=74041&r1=74040&r2=74041&view=diff
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/nsquery.c        [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/nsquery.c        [iso-8859-1] Fri Mar  3 
23:31:32 2017
@@ -134,9 +134,9 @@
         if (!(Provider = Entry->Provider))
         {
             /* None was loaded, load it */
-            if ((WsNcLoadProvider(EnumContext->Catalog, Entry) != 
ERROR_SUCCESS))
+            if (WsNcLoadProvider(EnumContext->Catalog, Entry) != ERROR_SUCCESS)
             {
-                /* return TRUE to continue enumerating */
+                /* Return TRUE to continue enumerating */
                 return TRUE;
             }
 
@@ -145,7 +145,7 @@
         }
 
         /* Add it to the query */
-        if (!(WsNqAddProvider(NsQuery, Provider)))
+        if (!WsNqAddProvider(NsQuery, Provider))
         {
             /* We failed */
             EnumContext->ErrorCode = WSASYSCALLFAILURE;
@@ -194,157 +194,150 @@
                       OUT PDWORD BufferLength,
                       OUT LPWSAQUERYSETW Results)
 {
+    INT ErrorCode = SOCKET_ERROR, OldErrorCode;
     PNSQUERY_PROVIDER Provider, NextProvider;
-    INT ErrorCode = SOCKET_ERROR, OldErrorCode;
     PLIST_ENTRY Entry;
 
     /* Make sure we're not shutting down */
-    if (!NsQuery->ShuttingDown)
-    {
-        /* Acquire query lock */
+    if (NsQuery->ShuttingDown)
+    {
+        /* We are shutting down, fail */
+        SetLastError(WSAECANCELLED);
+        return ErrorCode;
+    }
+
+    /* Acquire query lock */
+    WsNqLock();
+
+    /* Check if we already have an active provider */
+    NextProvider = NsQuery->ActiveProvider;
+    if (!NextProvider)
+    {
+        /* Make sure we have a current provider */
+        if (!NsQuery->CurrentProvider)
+        {
+            /* We don't; fail */
+            WsNqUnlock();
+            SetLastError(WSA_E_NO_MORE);
+            return SOCKET_ERROR;
+        }
+
+        /* Get the last provider in the list and start looping */
+        Entry = NsQuery->ProviderList.Blink;
+        NextProvider = CONTAINING_RECORD(Entry, NSQUERY_PROVIDER, QueryLink);
+        while (NextProvider)
+        {
+            /* Check if this is a new-style provider */
+            if (NextProvider->Provider->Service.NSPIoctl)
+            {
+                /* Remove it and re-add it on top */
+                RemoveEntryList(&NextProvider->QueryLink);
+                InsertHeadList(&NsQuery->ProviderList, 
&NextProvider->QueryLink);
+
+                /* Set it as the active provider and exit the loop */
+                NsQuery->ActiveProvider = NextProvider;
+                break;
+            }
+
+            /* Get the previous provider */
+            NextProvider = WsNqPreviousProvider(NsQuery, NextProvider);
+        }
+    }
+
+    /* Release the lock */
+    WsNqUnlock();
+
+    /* Restart and keep looping as long as there is an active provider */
+    while (NextProvider)
+    {
+        /* Call its routine */
+        ErrorCode = WsNqProvLookupServiceNext(NextProvider,
+                                              ControlFlags,
+                                              BufferLength,
+                                              Results);
+        /* Check for error or shutdown */
+        if ((ErrorCode == ERROR_SUCCESS) ||
+            (GetLastError() == WSAEFAULT) || (NsQuery->ShuttingDown))
+        {
+            /* Get out */
+            break;
+        }
+
+        /* Acquire Query Lock */
         WsNqLock();
 
-        /* Check if we already have an active provider */
-        NextProvider = NsQuery->ActiveProvider;
-        if (!NextProvider)
-        {
-            /* Make sure we have a current provider */
-            if (!NsQuery->CurrentProvider)
+        /* Save the current active provider */
+        Provider = NsQuery->ActiveProvider;
+
+        /* Check if one exists */
+        if (Provider)
+        {
+            /* Get the next one */
+            NextProvider = WsNqNextProvider(NsQuery,
+                                            NsQuery->ActiveProvider);
+
+            /* Was the old provider our active? */
+            if (Provider == NsQuery->ActiveProvider)
             {
-                /* We don't; fail */
-                WsNqUnlock();
-                SetLastError(WSA_E_NO_MORE);
-                return SOCKET_ERROR;
+                /* Change our active provider to the new one */
+                NsQuery->ActiveProvider = NextProvider;
             }
-
-            /* Get the first provider on the list and start looping */
-            Entry = NsQuery->ProviderList.Blink;
-            NextProvider = CONTAINING_RECORD(Entry, NSQUERY_PROVIDER, 
QueryLink);
-            while (NextProvider)
+        }
+        else
+        {
+            /* No next provider */
+            NextProvider = NULL;
+        }
+
+        /* Check if we failed and if we can try again */
+        if (!(NextProvider) &&
+            (ErrorCode == SOCKET_ERROR) &&
+            (NsQuery->TryAgain))
+        {
+            /* Save the error code so RAS doesn't overwrite it */
+            OldErrorCode = GetLastError();
+
+            /* Make sure we won't try for a 3rd time */
+            NsQuery->TryAgain = FALSE;
+
+            /* Call the helper to auto-dial */
+            if (WSAttemptAutodialName(NsQuery->QuerySet))
             {
-                /* Check if this is a new-style provider */
-                if (NextProvider->Provider->Service.NSPIoctl)
+                /* It succeeded, so we'll delete the current state. */
+                while (!IsListEmpty(&NsQuery->ProviderList))
                 {
-                    /* Remove it and re-add it on top */
-                    RemoveEntryList(&NextProvider->QueryLink);
-                    InsertHeadList(&NsQuery->ProviderList, 
&NextProvider->QueryLink);
-
-                    /* Set it as the active provider and exit the loop */
-                    NsQuery->ActiveProvider = NextProvider;
-                    break;
+                    /* Remove the entry and get its provider */
+                    Entry = RemoveHeadList(&NsQuery->ProviderList);
+                    Provider = CONTAINING_RECORD(Entry,
+                                                 NSQUERY_PROVIDER,
+                                                 QueryLink);
+
+                    /* Reset it */
+                    WsNqProvLookupServiceEnd(Provider);
+                    WsNqProvDelete(Provider);
                 }
 
-                /* Get the previous provider */
-                NextProvider = WsNqPreviousProvider(NsQuery, NextProvider);
+                /* Start a new query */
+                if (WsNqLookupServiceBegin(NsQuery,
+                                           NsQuery->QuerySet,
+                                           NsQuery->ControlFlags,
+                                           NsQuery->Catalog) == ERROR_SUCCESS)
+                {
+                    /* New query succeeded, set active provider now */
+                    NsQuery->ActiveProvider =
+                        WsNqNextProvider(NsQuery,
+                                         NsQuery->ActiveProvider);
+                }
             }
-        }
-
-        /* Release the lock */
+            else
+            {
+                /* Reset the error code */
+                SetLastError(OldErrorCode);
+            }
+        }
+
+        /* Release lock */
         WsNqUnlock();
-
-        /* Check if we have an active provider now */
-        if (NextProvider)
-        {
-            /* Start loop */
-            do
-            {
-                /* Call its routine */
-                ErrorCode = WsNqProvLookupServiceNext(NextProvider,
-                                                      ControlFlags,
-                                                      BufferLength,
-                                                      Results);
-                /* Check for error or shutdown */
-                if ((ErrorCode == ERROR_SUCCESS) ||
-                    (GetLastError() == WSAEFAULT) || (NsQuery->ShuttingDown))
-                {
-                    /* Get out */
-                    break;
-                }
-
-                /* Acquire Query Lock */
-                WsNqLock();
-
-                /* Save the current active provider */
-                Provider = NsQuery->ActiveProvider;
-
-                /* Check if one exists */
-                if (Provider)
-                {
-                    /* Get the next one */
-                    NextProvider = WsNqNextProvider(NsQuery,
-                                                    NsQuery->ActiveProvider);
-
-                    /* Was the old provider our active? */
-                    if (Provider == NsQuery->ActiveProvider)
-                    {
-                        /* Change our active provider to the new one */
-                        NsQuery->ActiveProvider = NextProvider;
-                    }
-                }
-                else
-                {
-                    /* No next provider */
-                    NextProvider = NULL;
-                }
-
-                /* Check if we failed and if we can try again */
-                if (!(NextProvider) &&
-                    (ErrorCode == SOCKET_ERROR) &&
-                    (NsQuery->TryAgain))
-                {
-                    /* Save the error code so RAS doesn't overwrite it */
-                    OldErrorCode = GetLastError();
-
-                    /* Make sure we won't try for a 3rd time */
-                    NsQuery->TryAgain = FALSE;
-
-                    /* Call the helper to auto-dial */
-                    if (WSAttemptAutodialName(NsQuery->QuerySet))
-                    {
-                        /* It succeeded, so we'll delete the current state. */
-                        while (!IsListEmpty(&NsQuery->ProviderList))
-                        {
-                            /* Remove the entry and get its provider */
-                            Entry = RemoveHeadList(&NsQuery->ProviderList);
-                            Provider = CONTAINING_RECORD(Entry,
-                                                         NSQUERY_PROVIDER,
-                                                         QueryLink);
-
-                            /* Reset it */
-                            WsNqProvLookupServiceEnd(Provider);
-                            WsNqProvDelete(Provider);
-                        }
-
-                        /* Start a new query */
-                        if (!WsNqLookupServiceBegin(NsQuery,
-                                                    NsQuery->QuerySet,
-                                                    NsQuery->ControlFlags,
-                                                    NsQuery->Catalog))
-                        {
-                            /* New query succeeded, set active provider now */
-                            NsQuery->ActiveProvider =
-                                WsNqNextProvider(NsQuery,
-                                                 NsQuery->ActiveProvider);
-                        }
-                    }
-                    else
-                    {
-                        /* Reset the error code */
-                        SetLastError(OldErrorCode);
-                    }
-                }
-
-                /* Release lock */
-                WsNqUnlock();
-
-                /* Keep looping as long as there is a provider */
-            } while (NextProvider);
-        }
-    }
-    else
-    {
-        /* We are shuting down; fail */
-        SetLastError(WSAECANCELLED);
     }
 
     /* Return */
@@ -359,9 +352,8 @@
                        IN PNSCATALOG Catalog)
 {
     WSASERVICECLASSINFOW ClassInfo;
-    PNSQUERY_PROVIDER Provider;
     LPWSASERVICECLASSINFOW pClassInfo = &ClassInfo;
-    PNSQUERY_PROVIDER NextProvider;
+    PNSQUERY_PROVIDER Provider, NextProvider;
     PLIST_ENTRY Entry;
     INT ErrorCode;
     DWORD ClassInfoSize;
@@ -539,28 +531,28 @@
 WsNqPreviousProvider(IN PNSQUERY Query,
                      IN PNSQUERY_PROVIDER Provider)
 {
-    PNSQUERY_PROVIDER NextProvider = NULL;
+    PNSQUERY_PROVIDER PrevProvider = NULL;
     PLIST_ENTRY Entry;
 
-    /* Get the first entry and get its provider */
+    /* Get the last entry and get its provider */
     Entry = Provider->QueryLink.Blink;
     if (Entry != &Query->ProviderList)
     {
         /* Get the current provider */
-        NextProvider = CONTAINING_RECORD(Entry, NSQUERY_PROVIDER, QueryLink);
+        PrevProvider = CONTAINING_RECORD(Entry, NSQUERY_PROVIDER, QueryLink);
     }
 
     /* Return it */
-    return NextProvider;
-}
-
-DWORD
+    return PrevProvider;
+}
+
+BOOL
 WSAAPI
 WsNqAddProvider(IN PNSQUERY Query,
                 IN PNS_PROVIDER Provider)
 {
+    BOOL Success = TRUE;
     PNSQUERY_PROVIDER QueryProvider;
-    DWORD Return = TRUE;
 
     /* Allocate a new Query Provider */
     if ((QueryProvider = WsNqProvAllocate()))
@@ -575,11 +567,10 @@
     {
         /* We failed */
         SetLastError(WSASYSCALLFAILURE);
-        Return = FALSE;
+        Success = FALSE;
     }
 
     /* Return */
-    return Return;
-}
-
-
+    return Success;
+}
+

Modified: trunk/reactos/dll/win32/ws2_32/src/qshelpr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/qshelpr.c?rev=74041&r1=74040&r2=74041&view=diff
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/qshelpr.c        [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/qshelpr.c        [iso-8859-1] Fri Mar  3 
23:31:32 2017
@@ -926,9 +926,9 @@
 
 INT
 WSAAPI
-MapUnicodeQuerySetToAnsi(OUT LPWSAQUERYSETW UnicodeSet,
+MapUnicodeQuerySetToAnsi(IN LPWSAQUERYSETW UnicodeSet,
                          IN OUT PSIZE_T SetSize,
-                         IN LPWSAQUERYSETA AnsiSet)
+                         OUT LPWSAQUERYSETA AnsiSet)
 {
     INT ErrorCode = ERROR_SUCCESS;
     SIZE_T UnicodeSize, AnsiSize;

Modified: trunk/reactos/dll/win32/ws2_32/src/rnr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/ws2_32/src/rnr.c?rev=74041&r1=74040&r2=74041&view=diff
==============================================================================
--- trunk/reactos/dll/win32/ws2_32/src/rnr.c    [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/ws2_32/src/rnr.c    [iso-8859-1] Fri Mar  3 
23:31:32 2017
@@ -2,7 +2,7 @@
  * COPYRIGHT:   See COPYING in the top level directory
  * PROJECT:     ReactOS WinSock 2 API
  * FILE:        dll/win32/ws2_32_new/src/rnr.c
- * PURPOSE:     Registration n' Resolution Support
+ * PURPOSE:     Registration and Resolution Support
  * PROGRAMMER:  Alex Ionescu ([email protected])
  */
 
@@ -285,11 +285,6 @@
                                                    dwControlFlags,
                                                    lphLookup);
             }
-            else
-            {
-                /* Fail, conversion failed */
-                SetLastError(ErrorCode);
-            }
 
             /* Free our buffer */
             HeapFree(WsSockHeap, 0, UnicodeQuerySet);
@@ -297,14 +292,13 @@
         else
         {
             /* No memory to allocate */
-            SetLastError(WSAEFAULT);
+            ErrorCode = WSAEFAULT;
         }
     }
-    else
-    {
-        /* We couldn't get the size for some reason */
+
+    /* Set the error in case of failure */
+    if (ErrorCode != ERROR_SUCCESS)
         SetLastError(ErrorCode);
-    }
 
     /* Return to caller */
     return ErrorCode == ERROR_SUCCESS ? ErrorCode : SOCKET_ERROR;


Reply via email to