Changeset 4446 for trunk/src/DPlayX/name_server.cpp
- Timestamp:
- Oct 6, 2000, 9:49:06 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/DPlayX/name_server.cpp
r4317 r4446 1 // $Id: name_server.cpp,v 1. 2 2000-09-24 22:47:38hugh Exp $1 // $Id: name_server.cpp,v 1.3 2000-10-06 19:49:06 hugh Exp $ 2 2 /* DPLAYX.DLL name server implementation 3 3 * … … 21 21 #include "heap.h" 22 22 #include "heapstring.h" 23 #include "mmsystem.h" 23 24 24 25 #include "dplayx_global.h" … … 32 33 DEFAULT_DEBUG_CHANNEL(dplay); 33 34 35 #undef debugstr_guid 34 36 #define debugstr_guid(a) a 35 37 … … 54 56 }; 55 57 typedef struct NSCache NSCache, *lpNSCache; 58 59 /* Function prototypes */ 60 DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData ); 56 61 57 62 /* Name Server functions … … 61 66 { 62 67 #if 0 68 /* FIXME: Remove this method? */ 63 69 DPLAYX_SetLocalSession( lpsd ); 64 70 #endif 71 } 72 73 DPQ_DECL_COMPARECB( cbUglyPig, GUID ) 74 { 75 return IsEqualGUID( elem1, elem2 ); 65 76 } 66 77 … … 77 88 78 89 /* FIXME: Should check to see if the reply is for an existing session. If 79 * so we just update the contents and update the timestamp.90 * so we remove the old and add the new so oldest is at front. 80 91 */ 92 93 /* See if we can find this session. If we can, remove it as it's a dup */ 94 DPQ_REMOVE_ENTRY_CB( lpCache->first, next, data->guidInstance, cbUglyPig, 95 lpMsg->sd.guidInstance, lpCacheNode ); 96 97 if( lpCacheNode != NULL ) 98 { 99 TRACE( "Duplicate session entry for %s removed - updated version kept\n", 100 debugstr_guid( &lpCacheNode->data->guidInstance ) ); 101 cbDeleteNSNodeFromHeap( lpCacheNode ); 102 } 103 104 /* Add this to the list */ 81 105 lpCacheNode = (lpNSCacheData)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 82 106 sizeof( *lpCacheNode ) ); … … 128 152 /* Ok. Cheat and don't search for the correct stuff just take the first. 129 153 * FIXME: In the future how are we to know what is _THE_ enum we used? 154 * This is going to have to go into dplay somehow. Perhaps it 155 * comes back with app server id for the join command! Oh...that 156 * must be it. That would make this method obsolete once that's 157 * in place. 130 158 */ 131 159 … … 171 199 } 172 200 173 DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData );174 201 DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData ) 175 202 { 203 /* NOTE: This proc doesn't deal with the walking pointer */ 204 176 205 /* FIXME: Memory leak on data (contained ptrs) */ 177 206 HeapFree( GetProcessHeap(), 0, elem->data ); … … 259 288 { 260 289 lpNSCache lpCache = (lpNSCache)lpNSInfo; 261 lpNSCacheData lpCacheEntry; 262 263 DWORD dwPresentTime = GetTickCount(); 264 #if defined( HACK_TIMEGETTIME ) 265 DWORD dwPruneTime = dwPresentTime - 2; /* One iteration with safety */ 266 #else 267 DWORD dwPruneTime = dwPresentTime - 10000 /* 10 secs? */; 268 #endif 269 270 FIXME( ": semi stub\n" ); 271 272 /* FIXME: This doesn't handle time roll over correctly */ 273 /* FIXME: Session memory leak on delete */ 274 do 275 { 276 DPQ_FIND_ENTRY( lpCache->first, next, dwTime, <=, dwPruneTime, lpCacheEntry ); 277 } 278 while( lpCacheEntry != NULL ); 290 291 const DWORD dwPresentTime = timeGetTime(); 292 const DWORD dwPrunePeriod = 60000; /* is 60 secs enough? */ 293 const DWORD dwPruneTime = dwPresentTime - dwPrunePeriod; 294 295 /* This silly little algorithm is based on the fact we keep entries in 296 * the queue in a time based order. It also assumes that it is not possible 297 * to wrap around over yourself (which is not unreasonable). 298 * The if statements verify if the first entry in the queue is less 299 * than dwPrunePeriod old depending on the "clock" roll over. 300 */ 301 for( ;; ) 302 { 303 lpNSCacheData lpFirstData; 304 305 if( DPQ_IS_EMPTY(lpCache->first) ) 306 { 307 /* Nothing to prune */ 308 break; 309 } 310 311 if( dwPruneTime > dwPresentTime ) /* 0 <= dwPresentTime <= dwPrunePeriod */ 312 { 313 if( ( DPQ_FIRST(lpCache->first)->dwTime <= dwPresentTime ) || 314 ( DPQ_FIRST(lpCache->first)->dwTime > dwPruneTime ) 315 ) 316 { 317 /* Less than dwPrunePeriod old - keep */ 318 break; 319 } 320 } 321 else /* dwPrunePeriod <= dwPresentTime <= max dword */ 322 { 323 if( ( DPQ_FIRST(lpCache->first)->dwTime <= dwPresentTime ) && 324 ( DPQ_FIRST(lpCache->first)->dwTime > dwPruneTime ) 325 ) 326 { 327 /* Less than dwPrunePeriod old - keep */ 328 break; 329 } 330 } 331 332 lpFirstData = DPQ_FIRST(lpCache->first); 333 DPQ_REMOVE( lpCache->first, DPQ_FIRST(lpCache->first), next ); 334 cbDeleteNSNodeFromHeap( lpFirstData ); 335 } 279 336 280 337 }
Note:
See TracChangeset
for help on using the changeset viewer.