2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS WinSock 2 API
5 * PURPOSE: Transport Provider Object
6 * PROGRAMMER: Alex Ionescu (alex@relsoft.net)
9 /* INCLUDES ******************************************************************/
13 /* FUNCTIONS *****************************************************************/
21 /* Allocate the object */
22 Provider
= HeapAlloc(WsSockHeap
, HEAP_ZERO_MEMORY
, sizeof(*Provider
));
24 /* Setup non-zero data */
25 Provider
->RefCount
= 1;
33 WsTpInitialize(IN PTPROVIDER Provider
,
35 IN LPWSAPROTOCOL_INFOW ProtocolInfo
)
37 WORD VersionRequested
= MAKEWORD(2,2);
38 WSPUPCALLTABLE UpcallTable
;
39 LPWSPSTARTUP WSPStartupProc
;
41 CHAR ExpandedDllPath
[MAX_PATH
];
43 /* Clear the tables */
44 RtlZeroMemory(&UpcallTable
, sizeof(UpcallTable
));
45 RtlZeroMemory(&Provider
->Service
.lpWSPAccept
, sizeof(WSPPROC_TABLE
));
47 /* Set up the Upcall Table */
48 UpcallTable
.lpWPUCloseEvent
= WPUCloseEvent
;
49 UpcallTable
.lpWPUCloseSocketHandle
= WPUCloseSocketHandle
;
50 UpcallTable
.lpWPUCreateEvent
= WPUCreateEvent
;
51 UpcallTable
.lpWPUCreateSocketHandle
= WPUCreateSocketHandle
;
52 UpcallTable
.lpWPUFDIsSet
= WPUFDIsSet
;
53 UpcallTable
.lpWPUGetProviderPath
= WPUGetProviderPath
;
54 UpcallTable
.lpWPUModifyIFSHandle
= WPUModifyIFSHandle
;
55 UpcallTable
.lpWPUPostMessage
= WPUPostMessage
;
56 UpcallTable
.lpWPUQueryBlockingCallback
= WPUQueryBlockingCallback
;
57 UpcallTable
.lpWPUQuerySocketHandleContext
= WPUQuerySocketHandleContext
;
58 UpcallTable
.lpWPUQueueApc
= WPUQueueApc
;
59 UpcallTable
.lpWPUResetEvent
= WPUResetEvent
;
60 UpcallTable
.lpWPUSetEvent
= WPUSetEvent
;
61 UpcallTable
.lpWPUOpenCurrentThread
= WPUOpenCurrentThread
;
62 UpcallTable
.lpWPUCloseThread
= WPUCloseThread
;
64 /* Expand the DLL Path */
65 ExpandEnvironmentStrings(DllName
, ExpandedDllPath
, MAX_PATH
);
68 Provider
->DllHandle
= LoadLibrary(ExpandedDllPath
);
70 /* Get the pointer to WSPStartup */
71 WSPStartupProc
= (LPWSPSTARTUP
)GetProcAddress(Provider
->DllHandle
, "WSPStartup");
74 (*WSPStartupProc
)(VersionRequested
,
78 (LPWSPPROC_TABLE
)&Provider
->Service
.lpWSPAccept
);
86 WsTpWSPCleanup(IN PTPROVIDER Provider
,
89 LPWSPCLEANUP WSPCleanup
= NULL
;
90 INT ErrorCode
= ERROR_SUCCESS
;
92 /* Make sure we have a loaded handle */
93 if (Provider
->DllHandle
)
95 /* Get the pointer and clear it */
96 WSPCleanup
= InterlockedExchangePointer((PVOID
*)&Provider
->Service
.lpWSPCleanup
,
98 /* If it's not NULL, call it */
99 if (WSPCleanup
) ErrorCode
= WSPCleanup(lpErrNo
);
108 WsTpDelete(IN PTPROVIDER Provider
)
112 /* Make sure we have a loaded handle */
113 if (Provider
->DllHandle
)
116 WsTpWSPCleanup(Provider
, &ErrorCode
);
118 /* Unload the library */
119 FreeLibrary(Provider
->DllHandle
);
121 /* Clear the handle value */
122 Provider
->DllHandle
= NULL
;
128 WsTpDereference(IN PTPROVIDER Provider
)
130 /* Decrease the reference count and check if it's zero */
131 if (!InterlockedDecrement(&Provider
->RefCount
))
134 WsTpDelete(Provider
);