Remember the last allocated port and try to allocate the next one on the

following call (prevents 1024 from being allocated each time)

svn path=/trunk/; revision=20297
This commit is contained in:
Gé van Geldorp
2005-12-22 11:44:16 +00:00
parent 59946b074c
commit da2a71a27c
2 changed files with 27 additions and 1 deletions
+26 -1
View File
@@ -15,6 +15,8 @@ VOID PortsStartup( PPORT_SET PortSet,
UINT PortsToManage ) {
PortSet->StartingPort = StartingPort;
PortSet->PortsToOversee = PortsToManage;
PortSet->LastAllocatedPort = PortSet->StartingPort +
PortSet->PortsToOversee - 1;
PortSet->ProtoBitBuffer =
PoolAllocateBuffer( (PortSet->PortsToOversee + 7) / 8 );
RtlInitializeBitMap( &PortSet->ProtoBitmap,
@@ -52,12 +54,23 @@ BOOLEAN AllocatePort( PPORT_SET PortSet, ULONG Port ) {
ULONG AllocateAnyPort( PPORT_SET PortSet ) {
ULONG AllocatedPort;
ULONG Next;
__asm__("int $3\n");
if (PortSet->StartingPort + PortSet->PortsToOversee <=
PortSet->LastAllocatedPort + 1) {
Next = PortSet->StartingPort;
} else {
Next = PortSet->LastAllocatedPort + 1;
}
Next -= PortSet->StartingPort;
ExAcquireFastMutex( &PortSet->Mutex );
AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, 0 );
if( AllocatedPort != (ULONG)-1 ) {
RtlSetBit( &PortSet->ProtoBitmap, AllocatedPort );
AllocatedPort += PortSet->StartingPort;
PortSet->LastAllocatedPort = AllocatedPort;
}
ExReleaseFastMutex( &PortSet->Mutex );
@@ -68,16 +81,28 @@ ULONG AllocateAnyPort( PPORT_SET PortSet ) {
ULONG AllocatePortFromRange( PPORT_SET PortSet, ULONG Lowest, ULONG Highest ) {
ULONG AllocatedPort;
ULONG Next;
if (PortSet->StartingPort + PortSet->PortsToOversee <=
PortSet->LastAllocatedPort + 1) {
Next = PortSet->StartingPort;
} else {
Next = PortSet->LastAllocatedPort + 1;
}
if (Next < Lowest || Highest <= Next) {
Next = Lowest;
}
Next -= PortSet->StartingPort;
Lowest -= PortSet->StartingPort;
Highest -= PortSet->StartingPort;
ExAcquireFastMutex( &PortSet->Mutex );
AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, Lowest );
AllocatedPort = RtlFindClearBits( &PortSet->ProtoBitmap, 1, Next );
if( AllocatedPort != (ULONG)-1 && AllocatedPort >= Lowest &&
AllocatedPort <= Highest) {
RtlSetBit( &PortSet->ProtoBitmap, AllocatedPort );
AllocatedPort += PortSet->StartingPort;
PortSet->LastAllocatedPort = AllocatedPort;
}
ExReleaseFastMutex( &PortSet->Mutex );
@@ -16,6 +16,7 @@ typedef struct _PORT_SET {
PVOID ProtoBitBuffer;
UINT StartingPort;
UINT PortsToOversee;
UINT LastAllocatedPort;
FAST_MUTEX Mutex;
} PORT_SET, *PPORT_SET;