[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.

svn path=/trunk/; revision=74041
This commit is contained in:
Hermès Bélusca-Maïto 2017-03-03 23:31:32 +00:00
parent 800e1d3803
commit 019a8d2be6
6 changed files with 160 additions and 170 deletions

View file

@ -721,7 +721,7 @@ WsAsyncThread(IN PVOID ThreadContext)
WsAsyncLock();
/* Process the queue */
while (ListHead->Flink != ListHead)
while (!IsListEmpty(ListHead))
{
/* Remove this entry and get the async block */
Entry = RemoveHeadList(ListHead);

View file

@ -384,7 +384,7 @@ WsTcGetEntryFromAf(IN PTCATALOG Catalog,
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 @@ WsTcGetEntryFromAf(IN PTCATALOG Catalog,
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 @@ WsTcGetEntryFromCatalogEntryId(IN PTCATALOG Catalog,
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 @@ WsTcGetEntryFromTriplet(IN PTCATALOG Catalog,
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);
@ -493,6 +495,8 @@ WsTcGetEntryFromTriplet(IN PTCATALOG Catalog,
/* Lock the catalog */
WsTcLock();
NextEntry = Catalog->ProtocolList.Flink;
/* Check if we are starting past 0 */
if (StartId)
{
@ -674,14 +678,14 @@ WsTcUpdateProtocolList(IN PTCATALOG Catalog,
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 @@ WsTcUpdateProtocolList(IN PTCATALOG Catalog,
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 */

View file

@ -498,13 +498,14 @@ WsNcGetCatalogFromProviderId(IN PNSCATALOG Catalog,
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 */

View file

@ -134,9 +134,9 @@ WsNqBeginEnumerationProc(PVOID Context,
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 @@ WsNqBeginEnumerationProc(PVOID Context,
}
/* Add it to the query */
if (!(WsNqAddProvider(NsQuery, Provider)))
if (!WsNqAddProvider(NsQuery, Provider))
{
/* We failed */
EnumContext->ErrorCode = WSASYSCALLFAILURE;
@ -194,157 +194,150 @@ WsNqLookupServiceNext(IN PNSQUERY NsQuery,
OUT PDWORD BufferLength,
OUT LPWSAQUERYSETW Results)
{
PNSQUERY_PROVIDER Provider, NextProvider;
INT ErrorCode = SOCKET_ERROR, OldErrorCode;
PNSQUERY_PROVIDER Provider, NextProvider;
PLIST_ENTRY Entry;
/* Make sure we're not shutting down */
if (!NsQuery->ShuttingDown)
if (NsQuery->ShuttingDown)
{
/* Acquire query lock */
WsNqLock();
/* We are shutting down, fail */
SetLastError(WSAECANCELLED);
return ErrorCode;
}
/* Check if we already have an active provider */
NextProvider = NsQuery->ActiveProvider;
if (!NextProvider)
/* 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)
{
/* 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 first provider on 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);
}
/* We don't; fail */
WsNqUnlock();
SetLastError(WSA_E_NO_MORE);
return SOCKET_ERROR;
}
/* Release the lock */
WsNqUnlock();
/* Check if we have an active provider now */
if (NextProvider)
/* Get the last provider in the list and start looping */
Entry = NsQuery->ProviderList.Blink;
NextProvider = CONTAINING_RECORD(Entry, NSQUERY_PROVIDER, QueryLink);
while (NextProvider)
{
/* Start loop */
do
/* Check if this is a new-style provider */
if (NextProvider->Provider->Service.NSPIoctl)
{
/* 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;
}
/* Remove it and re-add it on top */
RemoveEntryList(&NextProvider->QueryLink);
InsertHeadList(&NsQuery->ProviderList, &NextProvider->QueryLink);
/* Acquire Query Lock */
WsNqLock();
/* Set it as the active provider and exit the loop */
NsQuery->ActiveProvider = NextProvider;
break;
}
/* 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);
/* Get the previous provider */
NextProvider = WsNqPreviousProvider(NsQuery, NextProvider);
}
}
else
/* Release the lock */
WsNqUnlock();
/* Restart and keep looping as long as there is an active provider */
while (NextProvider)
{
/* We are shuting down; fail */
SetLastError(WSAECANCELLED);
/* 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) == ERROR_SUCCESS)
{
/* New query succeeded, set active provider now */
NsQuery->ActiveProvider =
WsNqNextProvider(NsQuery,
NsQuery->ActiveProvider);
}
}
else
{
/* Reset the error code */
SetLastError(OldErrorCode);
}
}
/* Release lock */
WsNqUnlock();
}
/* Return */
@ -359,9 +352,8 @@ WsNqLookupServiceBegin(IN PNSQUERY NsQuery,
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 @@ WSAAPI
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;
return PrevProvider;
}
DWORD
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 @@ WsNqAddProvider(IN PNSQUERY Query,
{
/* We failed */
SetLastError(WSASYSCALLFAILURE);
Return = FALSE;
Success = FALSE;
}
/* Return */
return Return;
return Success;
}

View file

@ -926,9 +926,9 @@ error:
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;

View file

@ -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 (alex@relsoft.net)
*/
@ -285,11 +285,6 @@ WSALookupServiceBeginA(IN LPWSAQUERYSETA lpqsRestrictions,
dwControlFlags,
lphLookup);
}
else
{
/* Fail, conversion failed */
SetLastError(ErrorCode);
}
/* Free our buffer */
HeapFree(WsSockHeap, 0, UnicodeQuerySet);
@ -297,14 +292,13 @@ WSALookupServiceBeginA(IN LPWSAQUERYSETA lpqsRestrictions,
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;