ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dprovide.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS WinSock 2 API
00004  * FILE:        dprovide.c
00005  * PURPOSE:     Transport Provider Object
00006  * PROGRAMMER:  Alex Ionescu (alex@relsoft.net)
00007  */
00008 
00009 /* INCLUDES ******************************************************************/
00010 #include "ws2_32.h"
00011 
00012 /* FUNCTIONS *****************************************************************/
00013 
00014 PTPROVIDER
00015 WSAAPI
00016 WsTpAllocate(VOID)
00017 {
00018     PTPROVIDER Provider;
00019     
00020     /* Allocate the object */
00021     Provider = HeapAlloc(WsSockHeap, HEAP_ZERO_MEMORY, sizeof(*Provider));
00022 
00023     /* Setup non-zero data */
00024     Provider->RefCount = 1;
00025     
00026     /* Return it */
00027     return Provider;
00028 }
00029 
00030 DWORD
00031 WSAAPI
00032 WsTpInitialize(IN PTPROVIDER Provider,
00033                IN LPSTR DllName,
00034                IN LPWSAPROTOCOL_INFOW ProtocolInfo)
00035 {
00036     WORD VersionRequested = MAKEWORD(2,2);
00037     WSPUPCALLTABLE UpcallTable;
00038     LPWSPSTARTUP WSPStartupProc;
00039     WSPDATA WspData;
00040     CHAR ExpandedDllPath[MAX_PATH];
00041     
00042     /* Clear the tables */
00043     RtlZeroMemory(&UpcallTable, sizeof(UpcallTable));
00044     RtlZeroMemory(&Provider->Service.lpWSPAccept, sizeof(WSPPROC_TABLE));
00045 
00046     /* Set up the Upcall Table */
00047     UpcallTable.lpWPUCloseEvent = WPUCloseEvent;
00048     UpcallTable.lpWPUCloseSocketHandle = WPUCloseSocketHandle;
00049     UpcallTable.lpWPUCreateEvent = WPUCreateEvent;
00050     UpcallTable.lpWPUCreateSocketHandle = WPUCreateSocketHandle;
00051     UpcallTable.lpWPUFDIsSet = WPUFDIsSet;
00052     UpcallTable.lpWPUGetProviderPath = WPUGetProviderPath;
00053     UpcallTable.lpWPUModifyIFSHandle = WPUModifyIFSHandle;
00054     UpcallTable.lpWPUPostMessage = WPUPostMessage;
00055     UpcallTable.lpWPUQueryBlockingCallback = WPUQueryBlockingCallback;
00056     UpcallTable.lpWPUQuerySocketHandleContext = WPUQuerySocketHandleContext;
00057     UpcallTable.lpWPUQueueApc = WPUQueueApc;
00058     UpcallTable.lpWPUResetEvent = WPUResetEvent;
00059     UpcallTable.lpWPUSetEvent = WPUSetEvent;
00060     UpcallTable.lpWPUOpenCurrentThread = WPUOpenCurrentThread;
00061     UpcallTable.lpWPUCloseThread = WPUCloseThread;
00062 
00063     /* Expand the DLL Path */
00064     ExpandEnvironmentStrings(DllName, ExpandedDllPath, MAX_PATH);
00065 
00066     /* Load the DLL */
00067     Provider->DllHandle = LoadLibrary(ExpandedDllPath);
00068 
00069     /* Get the pointer to WSPStartup */
00070     WSPStartupProc = (LPWSPSTARTUP)GetProcAddress(Provider->DllHandle, "WSPStartup");
00071 
00072     /* Call it */
00073     (*WSPStartupProc)(VersionRequested,
00074                       &WspData,
00075                       ProtocolInfo,
00076                       UpcallTable,
00077                       (LPWSPPROC_TABLE)&Provider->Service.lpWSPAccept);
00078 
00079     /* Return */
00080     return ERROR_SUCCESS;
00081 }
00082 
00083 DWORD
00084 WSAAPI
00085 WsTpWSPCleanup(IN PTPROVIDER Provider,
00086                IN LPINT lpErrNo)
00087 {
00088     LPWSPCLEANUP WSPCleanup = NULL;
00089     INT ErrorCode = ERROR_SUCCESS;
00090     
00091     /* Make sure we have a loaded handle */
00092     if (Provider->DllHandle)
00093     {
00094         /* Get the pointer and clear it */
00095         WSPCleanup = InterlockedExchangePointer((PVOID*)&Provider->Service.lpWSPCleanup,
00096                                                 NULL);
00097         /* If it's not NULL, call it */
00098         if (WSPCleanup) ErrorCode = WSPCleanup(lpErrNo);
00099     }
00100 
00101     /* Return */
00102     return ErrorCode;
00103 }
00104 
00105 VOID
00106 WSAAPI
00107 WsTpDelete(IN PTPROVIDER Provider)
00108 {
00109     INT ErrorCode;
00110     
00111     /* Make sure we have a loaded handle */
00112     if (Provider->DllHandle)
00113     {
00114         /* Clean us up */
00115         WsTpWSPCleanup(Provider, &ErrorCode);
00116 
00117         /* Unload the library */
00118         FreeLibrary(Provider->DllHandle);
00119 
00120         /* Clear the handle value */
00121         Provider->DllHandle = NULL;
00122     }
00123 }
00124 
00125 VOID
00126 WSAAPI
00127 WsTpDereference(IN PTPROVIDER Provider)
00128 {
00129     /* Decrease the reference count and check if it's zero */
00130     if (!InterlockedDecrement(&Provider->RefCount))
00131     {
00132         /* Delete us*/
00133         WsTpDelete(Provider);
00134     }
00135 }

Generated on Wed May 23 2012 04:24:58 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.