2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
4 * FILE: dll/win32/ws2_32_new/src/dprovide.c
5 * PURPOSE: Transport Provider Object
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
9 /* INCLUDES ******************************************************************/
16 /* FUNCTIONS *****************************************************************/
24 DPRINT("WsTpAllocate: WsSockHeap %d\n", WsSockHeap
);
25 /* Allocate the object */
26 Provider
= HeapAlloc(WsSockHeap
, HEAP_ZERO_MEMORY
, sizeof(*Provider
));
28 /* Setup non-zero data */
29 Provider
->RefCount
= 1;
37 WsTpInitialize(IN PTPROVIDER Provider
,
39 IN LPWSAPROTOCOL_INFOW ProtocolInfo
)
41 WORD VersionRequested
= MAKEWORD(2,2);
42 LPWSPSTARTUP WSPStartupProc
;
44 CHAR ExpandedDllPath
[MAX_PATH
];
46 DPRINT("WsTpInitialize: %p, %p, %p\n", Provider
, DllName
, ProtocolInfo
);
48 /* Clear the tables */
49 RtlZeroMemory(&Provider
->UpcallTable
, sizeof(WSPUPCALLTABLE
));
50 RtlZeroMemory(&Provider
->Service
.lpWSPAccept
, sizeof(WSPPROC_TABLE
));
52 /* Set up the Upcall Table */
53 Provider
->UpcallTable
.lpWPUCloseEvent
= WPUCloseEvent
;
54 Provider
->UpcallTable
.lpWPUCloseSocketHandle
= WPUCloseSocketHandle
;
55 Provider
->UpcallTable
.lpWPUCreateEvent
= WPUCreateEvent
;
56 Provider
->UpcallTable
.lpWPUCreateSocketHandle
= WPUCreateSocketHandle
;
57 Provider
->UpcallTable
.lpWPUFDIsSet
= WPUFDIsSet
;
58 Provider
->UpcallTable
.lpWPUGetProviderPath
= WPUGetProviderPath
;
59 Provider
->UpcallTable
.lpWPUModifyIFSHandle
= WPUModifyIFSHandle
;
60 Provider
->UpcallTable
.lpWPUPostMessage
= WPUPostMessage
;
61 Provider
->UpcallTable
.lpWPUQueryBlockingCallback
= WPUQueryBlockingCallback
;
62 Provider
->UpcallTable
.lpWPUQuerySocketHandleContext
= WPUQuerySocketHandleContext
;
63 Provider
->UpcallTable
.lpWPUQueueApc
= WPUQueueApc
;
64 Provider
->UpcallTable
.lpWPUResetEvent
= WPUResetEvent
;
65 Provider
->UpcallTable
.lpWPUSetEvent
= WPUSetEvent
;
66 Provider
->UpcallTable
.lpWPUOpenCurrentThread
= WPUOpenCurrentThread
;
67 Provider
->UpcallTable
.lpWPUCloseThread
= WPUCloseThread
;
69 /* Expand the DLL Path */
70 ExpandEnvironmentStrings(DllName
, ExpandedDllPath
, MAX_PATH
);
73 Provider
->DllHandle
= LoadLibrary(ExpandedDllPath
);
75 if(!Provider
->DllHandle
)
79 /* Get the pointer to WSPStartup */
80 WSPStartupProc
= (LPWSPSTARTUP
)GetProcAddress(Provider
->DllHandle
, "WSPStartup");
87 ErrorCode
= (*WSPStartupProc
)(VersionRequested
,
90 Provider
->UpcallTable
,
91 (LPWSPPROC_TABLE
)&Provider
->Service
.lpWSPAccept
);
99 WsTpWSPCleanup(IN PTPROVIDER Provider
,
102 LPWSPCLEANUP WSPCleanup
= NULL
;
103 INT ErrorCode
= ERROR_SUCCESS
;
105 /* Make sure we have a loaded handle */
106 if (Provider
->DllHandle
)
108 /* Get the pointer and clear it */
109 WSPCleanup
= InterlockedExchangePointer((PVOID
*)&Provider
->Service
.lpWSPCleanup
,
111 /* If it's not NULL, call it */
112 if (WSPCleanup
) ErrorCode
= WSPCleanup(lpErrNo
);
121 WsTpDelete(IN PTPROVIDER Provider
)
125 /* Make sure we have a loaded handle */
126 if (Provider
->DllHandle
)
129 WsTpWSPCleanup(Provider
, &ErrorCode
);
131 /* Unload the library */
132 FreeLibrary(Provider
->DllHandle
);
134 /* Clear the handle value */
135 Provider
->DllHandle
= NULL
;
141 WsTpDereference(IN PTPROVIDER Provider
)
143 /* Decrease the reference count and check if it's zero */
144 if (!InterlockedDecrement(&Provider
->RefCount
))
147 WsTpDelete(Provider
);