2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Winsock 2 SPI
4 * FILE: lib/mswsock/lib/init.c
5 * PURPOSE: DLL Initialization
8 /* INCLUDES ******************************************************************/
11 /* DATA **********************************************************************/
13 LIST_ENTRY ListAnchor
;
14 BOOLEAN g_fRnrLockInit
;
15 CRITICAL_SECTION g_RnrLock
;
17 #define AcquireRnR2Lock() EnterCriticalSection(&g_RnrLock);
18 #define ReleaseRnR2Lock() LeaveCriticalSection(&g_RnrLock);
20 /* FUNCTIONS *****************************************************************/
24 RnrCtx_Create(IN HANDLE LookupHandle
,
25 IN LPWSTR ServiceName
)
27 PRNR_CONTEXT RnrContext
;
28 SIZE_T StringSize
= 0;
30 /* Get the size of the string */
31 if (ServiceName
) StringSize
= wcslen(ServiceName
);
33 /* Allocate the Context */
34 RnrContext
= Temp_AllocZero(sizeof(RNR_CONTEXT
) + (DWORD
)StringSize
);
36 /* Check that we got one */
40 RnrContext
->RefCount
= 2;
41 RnrContext
->Handle
= (LookupHandle
? LookupHandle
: (HANDLE
)RnrContext
);
42 RnrContext
->Instance
= -1;
43 RnrContext
->Signature
= 0xaabbccdd;
44 wcscpy(RnrContext
->ServiceName
, ServiceName
);
46 /* Insert it into the list */
48 InsertHeadList(&ListAnchor
, &RnrContext
->ListEntry
);
58 RnrCtx_Release(PRNR_CONTEXT RnrContext
)
60 /* Acquire the lock */
63 /* Decrease reference count and check if it's still in use */
64 if(!(--RnrContext
->RefCount
))
66 /* Remove it from the List */
67 RemoveEntryList(&RnrContext
->ListEntry
);
69 /* Release the lock */
72 /* Deallocated any cached Hostent */
73 if(RnrContext
->CachedSaBlob
) SaBlob_Free(RnrContext
->CachedSaBlob
);
75 /* Deallocate the Blob */
76 if(RnrContext
->CachedBlob
.pBlobData
)
78 DnsApiFree(RnrContext
->CachedBlob
.pBlobData
);
81 /* Deallocate the actual context itself */
82 DnsApiFree(RnrContext
);
86 /* Release the lock */
93 RnrCtx_Get(HANDLE LookupHandle
,
98 PRNR_CONTEXT RnRContext
= NULL
;
100 /* Acquire the lock */
103 /* Loop the RNR Context List */
104 for(Entry
= ListAnchor
.Flink
; Entry
!= &ListAnchor
; Entry
= Entry
->Flink
)
106 /* Get the Current RNR Context */
107 RnRContext
= CONTAINING_RECORD(Entry
, RNR_CONTEXT
, ListEntry
);
109 /* Check if it matches the one we got */
110 if(RnRContext
== (PRNR_CONTEXT
)LookupHandle
) break;
113 /* If we found it, mark it in use */
114 if(RnRContext
) RnRContext
->RefCount
++;
116 /* Increase the Instance and return it */
117 *Instance
= ++RnRContext
->Instance
;
119 /* If we're flushing the previous one, then bias the Instance by one */
120 if(dwControlFlags
& LUP_FLUSHPREVIOUS
) *Instance
= ++RnRContext
->Instance
;
122 /* Release the lock */
125 /* Return the Context */
131 RnrCtx_DecInstance(IN PRNR_CONTEXT RnrContext
)
133 /* Acquire the lock */
136 /* Decrease instance count */
137 RnrContext
->Instance
--;
139 /* Release the lock */
145 RnrCtx_ListCleanup(VOID
)
149 /* Acquire RnR Lock */
152 /* Loop the contexts */
153 while ((Entry
= ListAnchor
.Flink
) != &ListAnchor
)
155 /* Release this context */
156 RnrCtx_Release(CONTAINING_RECORD(Entry
, RNR_CONTEXT
, ListEntry
));