Ignore:
Timestamp:
Oct 6, 2000, 9:49:06 PM (25 years ago)
Author:
hugh
Message:

Updated to latest WINE

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:38 hugh Exp $
     1// $Id: name_server.cpp,v 1.3 2000-10-06 19:49:06 hugh Exp $
    22/* DPLAYX.DLL name server implementation
    33 *
     
    2121#include "heap.h"
    2222#include "heapstring.h"
     23#include "mmsystem.h"
    2324
    2425#include "dplayx_global.h"
     
    3233DEFAULT_DEBUG_CHANNEL(dplay);
    3334
     35#undef  debugstr_guid
    3436#define debugstr_guid(a) a
    3537
     
    5456};
    5557typedef struct NSCache NSCache, *lpNSCache;
     58
     59/* Function prototypes */
     60DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData );
    5661
    5762/* Name Server functions
     
    6166{
    6267#if 0
     68  /* FIXME: Remove this method? */
    6369  DPLAYX_SetLocalSession( lpsd );
    6470#endif
     71}
     72
     73DPQ_DECL_COMPARECB( cbUglyPig, GUID )
     74{
     75  return IsEqualGUID( elem1, elem2 );
    6576}
    6677
     
    7788
    7889  /* 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.
    8091   */
     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 */
    81105  lpCacheNode = (lpNSCacheData)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
    82106                                          sizeof( *lpCacheNode ) );
     
    128152  /* Ok. Cheat and don't search for the correct stuff just take the first.
    129153   * 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.
    130158   */
    131159
     
    171199}
    172200
    173 DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData );
    174201DPQ_DECL_DELETECB( cbDeleteNSNodeFromHeap, lpNSCacheData )
    175202{
     203  /* NOTE: This proc doesn't deal with the walking pointer */
     204
    176205  /* FIXME: Memory leak on data (contained ptrs) */
    177206  HeapFree( GetProcessHeap(), 0, elem->data );
     
    259288{
    260289  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  }
    279336
    280337}
Note: See TracChangeset for help on using the changeset viewer.