2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
5 * PURPOSE: Process Object
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
9 /* INCLUDES ******************************************************************/
12 /* DATA **********************************************************************/
13 PWSPROCESS CurrentWsProcess
;
15 #define WsProcLock() EnterCriticalSection((LPCRITICAL_SECTION)&Process->ThreadLock);
16 #define WsProcUnlock() LeaveCriticalSection((LPCRITICAL_SECTION)&Process->ThreadLock);
18 /* FUNCTIONS *****************************************************************/
22 WsProcInitialize(IN PWSPROCESS Process
)
24 INT ErrorCode
= WSAEFAULT
;
27 /* Initialize the thread list lock */
28 InitializeCriticalSection((LPCRITICAL_SECTION
)&Process
->ThreadLock
);
29 Process
->LockReady
= TRUE
;
31 /* Open the Winsock Key */
32 RootKey
= WsOpenRegistryRoot();
34 /* Create the LP Catalog change event and catalog */
35 Process
->ProtocolCatalogEvent
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
36 Process
->ProtocolCatalog
= WsTcAllocate();
39 WsTcInitializeFromRegistry(Process
->ProtocolCatalog
,
41 Process
->ProtocolCatalogEvent
);
43 /* Create the NS Catalog change event and catalog */
44 Process
->NamespaceCatalogEvent
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
45 Process
->NamespaceCatalog
= WsNcAllocate();
48 ErrorCode
= WsNcInitializeFromRegistry(Process
->NamespaceCatalog
,
50 Process
->NamespaceCatalogEvent
);
52 /* Close the root key */
63 /* Allocate the structure */
64 Process
= HeapAlloc(WsSockHeap
, HEAP_ZERO_MEMORY
, sizeof(*Process
));
66 /* Set default non-zero values */
67 Process
->Version
= MAKEWORD(2,2);
75 WsProcOpenAsyncHelperDevice(IN PWSPROCESS Process
,
78 INT ErrorCode
= WSASYSCALLFAILURE
;
80 /* Lock the process */
83 /* Check if we have a handle, and if not, create one */
84 if ((Process
->ApcHelper
) ||
85 (WahOpenApcHelper(&Process
->ApcHelper
) == ERROR_SUCCESS
))
87 /* Return the handle */
88 *Handle
= Process
->ApcHelper
;
89 ErrorCode
= ERROR_SUCCESS
;
92 /* Unload the process and return */
99 WsProcGetAsyncHelper(IN PWSPROCESS Process
,
102 /* Check if we have it already set up */
103 if (Process
->ApcHelper
)
106 *Handle
= Process
->ApcHelper
;
107 return ERROR_SUCCESS
;
111 /* Open it for the first time */
112 return WsProcOpenAsyncHelperDevice(Process
, Handle
);
120 INT ErrorCode
= WSAEFAULT
;
122 /* Create a new process */
123 CurrentWsProcess
= WsProcAllocate();
126 if (CurrentWsProcess
)
128 /* Initialize the process */
129 ErrorCode
= WsProcInitialize(CurrentWsProcess
);
133 /* No memory for the process object */
134 ErrorCode
= WSA_NOT_ENOUGH_MEMORY
;
142 WsProcGetTCatalog(IN PWSPROCESS Process
)
144 /* Check if the catalogs have been modified */
145 if (WsCheckCatalogState(Process
->ProtocolCatalogEvent
))
147 /* Modification happened, reload them */
148 WsTcRefreshFromRegistry(Process
->ProtocolCatalog
,
149 Process
->ProtocolCatalogEvent
);
153 return Process
->ProtocolCatalog
;
158 WsProcGetNsCatalog(IN PWSPROCESS Process
)
160 /* Check if the catalogs have been modified */
161 if (WsCheckCatalogState(Process
->NamespaceCatalogEvent
))
163 /* Modification happened, reload them */
164 WsNcRefreshFromRegistry(Process
->NamespaceCatalog
,
165 Process
->NamespaceCatalogEvent
);
169 return Process
->NamespaceCatalog
;
174 WsProcDetachSocket(IN PWSPROCESS Process
,
175 IN PWAH_HANDLE Handle
)
177 PWSSOCKET Socket
= (PWSSOCKET
)Handle
;
179 /* Disassociate this socket from the table */
180 WahRemoveHandleContext(WsSockHandleTable
, Handle
);
182 /* If this is isn't an IFS socket */
183 if (!Socket
->Provider
)
185 /* Check if we have an active handle helper */
186 if (Process
->HandleHelper
)
189 WahCloseSocketHandle(Process
->HandleHelper
, (SOCKET
)Socket
->Handle
);
193 /* Remove a reference and return */
194 WsSockDereference(Socket
);
200 CleanupNamespaceProviders(IN PVOID Callback
,
201 IN PNSCATALOG_ENTRY Entry
)
203 PNS_PROVIDER Provider
;
205 /* Get the provider */
206 Provider
= Entry
->Provider
;
210 WsNpNSPCleanup(Provider
);
219 CleanupProtocolProviders(IN PVOID Callback
,
220 IN PTCATALOG_ENTRY Entry
)
225 /* Get the provider */
226 Provider
= Entry
->Provider
;
230 WsTpWSPCleanup(Provider
, &ErrorCode
);
239 WsProcDelete(IN PWSPROCESS Process
)
241 /* Check if we didn't even initialize yet */
242 if (!Process
->LockReady
) return;
244 /* No more current process */
245 CurrentWsProcess
= NULL
;
247 /* If we have a socket table */
248 if (WsSockHandleTable
)
250 /* Enumerate the sockets with a delete callback */
251 WahEnumerateHandleContexts(WsSockHandleTable
,
256 /* Close APC Helper */
257 if (Process
->ApcHelper
) WahCloseApcHelper(Process
->ApcHelper
);
259 /* Close handle helper */
260 if (Process
->HandleHelper
) WahCloseHandleHelper(Process
->HandleHelper
);
262 /* Check for notification helper */
263 if (Process
->NotificationHelper
)
265 /* Close notification helper */
266 WahCloseNotificationHandleHelper(Process
->NotificationHelper
);
269 /* Check if we have a protocol catalog*/
270 if (Process
->ProtocolCatalog
)
272 /* Enumerate it to clean it up */
273 WsTcEnumerateCatalogItems(Process
->ProtocolCatalog
,
274 CleanupProtocolProviders
,
278 WsTcDelete(Process
->ProtocolCatalog
);
279 Process
->ProtocolCatalog
= NULL
;
282 /* Check if we have a namespace catalog*/
283 if (Process
->NamespaceCatalog
)
285 /* Enumerate it to clean it up */
286 WsNcEnumerateCatalogItems(Process
->NamespaceCatalog
,
287 CleanupNamespaceProviders
,
291 WsNcDelete(Process
->NamespaceCatalog
);
292 Process
->NamespaceCatalog
= NULL
;
295 /* Delete the thread lock */
296 DeleteCriticalSection((LPCRITICAL_SECTION
)&Process
->ThreadLock
);
301 WsProcSetVersion(IN PWSPROCESS Process
,
302 IN WORD VersionRequested
)
305 WORD OldMajor
, OldMinor
;
307 /* Get the version data */
308 Major
= LOBYTE(VersionRequested
);
309 Minor
= HIBYTE(VersionRequested
);
310 OldMajor
= LOBYTE(Process
->Version
);
311 OldMinor
= HIBYTE(Process
->Version
);
313 /* Check if we're going lower */
314 if ((Major
< OldMajor
) || ((Major
== OldMajor
) && (Minor
< OldMinor
)))
316 /* Set the new version */
317 Process
->Version
= VersionRequested
;