Author: cgutman
Date: Mon Jun 7 02:24:27 2010
New Revision: 47646
URL:
http://svn.reactos.org/svn/reactos?rev=47646&view=rev
Log:
[MSAFD]
- Use a linked list to store the socket information instead of allocating a massive array
(1024 elements!) for each process in DllMain to hold all of the pointers
- Fix a massive memory leak (free the socket information which we leaked for every socket
we allocated)
- This improves performance because we don't have to look through an array of stale
socket information pointers (which we never actually removed from the socket information
array in the old code) and the new code queues the socket information at the head of the
list which makes newer sockets faster to access
Modified:
trunk/reactos/dll/win32/msafd/misc/dllmain.c
trunk/reactos/dll/win32/msafd/msafd.h
Modified: trunk/reactos/dll/win32/msafd/misc/dllmain.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msafd/misc/dllma…
==============================================================================
--- trunk/reactos/dll/win32/msafd/misc/dllmain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msafd/misc/dllmain.c [iso-8859-1] Mon Jun 7 02:24:27 2010
@@ -23,7 +23,7 @@
WSPUPCALLTABLE Upcalls;
LPWPUCOMPLETEOVERLAPPEDREQUEST lpWPUCompleteOverlappedRequest;
ULONG SocketCount = 0;
-PSOCKET_INFORMATION *Sockets = NULL;
+PSOCKET_INFORMATION SocketListHead = NULL;
LIST_ENTRY SockHelpersListHead = { NULL, NULL };
ULONG SockAsyncThreadRefCount;
HANDLE SockAsyncHelperAfdHandle;
@@ -292,8 +292,8 @@
NULL);
/* Save in Process Sockets List */
- Sockets[SocketCount] = Socket;
- SocketCount ++;
+ Socket->NextSocket = SocketListHead;
+ SocketListHead = Socket;
/* Create the Socket Context */
CreateContext(Socket);
@@ -423,7 +423,7 @@
OUT LPINT lpErrno)
{
IO_STATUS_BLOCK IoStatusBlock;
- PSOCKET_INFORMATION Socket = NULL;
+ PSOCKET_INFORMATION Socket = NULL, CurrentSocket;
NTSTATUS Status;
HANDLE SockEvent;
AFD_DISCONNECT_INFO DisconnectInfo;
@@ -561,6 +561,27 @@
Socket->TdiAddressHandle = NULL;
NtClose(Socket->TdiConnectionHandle);
Socket->TdiConnectionHandle = NULL;
+
+ if (SocketListHead == Socket)
+ {
+ SocketListHead = SocketListHead->NextSocket;
+ }
+ else
+ {
+ CurrentSocket = SocketListHead;
+ while (CurrentSocket->NextSocket)
+ {
+ if (CurrentSocket->NextSocket == Socket)
+ {
+ CurrentSocket->NextSocket =
CurrentSocket->NextSocket->NextSocket;
+ break;
+ }
+
+ CurrentSocket = CurrentSocket->NextSocket;
+ }
+ }
+
+ HeapFree(GlobalHeap, 0, Socket);
/* Close the handle */
NtClose((HANDLE)Handle);
@@ -2244,16 +2265,22 @@
PSOCKET_INFORMATION
GetSocketStructure(SOCKET Handle)
{
- ULONG i;
-
- for (i=0; i<SocketCount; i++)
- {
- if (Sockets[i]->Handle == Handle)
- {
- return Sockets[i];
- }
- }
- return 0;
+ PSOCKET_INFORMATION CurrentSocket;
+
+ /* This is a special case */
+ if (SocketListHead->Handle == Handle)
+ return SocketListHead;
+
+ CurrentSocket = SocketListHead;
+ while (CurrentSocket->NextSocket)
+ {
+ if (CurrentSocket->Handle == Handle)
+ return CurrentSocket;
+
+ CurrentSocket = CurrentSocket->NextSocket;
+ }
+
+ return NULL;
}
int CreateContext(PSOCKET_INFORMATION Socket)
@@ -2771,10 +2798,6 @@
/* Heap to use when allocating */
GlobalHeap = GetProcessHeap();
- /* Allocate Heap for 1024 Sockets, can be expanded later */
- Sockets = HeapAlloc(GetProcessHeap(), 0, sizeof(PSOCKET_INFORMATION) * 1024);
- if (!Sockets) return FALSE;
-
AFD_DbgPrint(MAX_TRACE, ("MSAFD.DLL has been loaded\n"));
break;
Modified: trunk/reactos/dll/win32/msafd/msafd.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msafd/msafd.h?re…
==============================================================================
--- trunk/reactos/dll/win32/msafd/msafd.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msafd/msafd.h [iso-8859-1] Mon Jun 7 02:24:27 2010
@@ -100,6 +100,7 @@
BOOL TrySAN;
SOCKADDR WSLocalAddress;
SOCKADDR WSRemoteAddress;
+ struct _SOCKET_INFORMATION *NextSocket;
} SOCKET_INFORMATION, *PSOCKET_INFORMATION;