home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / winnt / remote / srvlist.c < prev    next >
C/C++ Source or Header  |  1997-10-12  |  3KB  |  147 lines

  1.  
  2. /******************************************************************************\
  3. *       This is a part of the Microsoft Source Code Samples. 
  4. *       Copyright 1995 - 1997 Microsoft Corporation.
  5. *       All rights reserved. 
  6. *       This source code is only intended as a supplement to 
  7. *       Microsoft Development Tools and/or WinHelp documentation.
  8. *       See these sources for detailed information regarding the 
  9. *       Microsoft samples programs.
  10. \******************************************************************************/
  11.  
  12. /*++
  13.  
  14. Copyright (c) 1997  Microsoft Corporation
  15.  
  16. Module Name:
  17.  
  18.     SrvList.c
  19.  
  20. Abstract:
  21.  
  22.     The server component of Remote.  This module
  23.     implements three lists of REMOTE_CLIENT structures,
  24.     for handshaking, connected, and closing clients.
  25.     To simplify the interface items always progress
  26.     through the three lists in order, with list node
  27.     memory being freed as it is removed from the
  28.     closing list.
  29.  
  30.  
  31. Author:
  32.  
  33.     Dave Hart  30 May 1997
  34.  
  35. Environment:
  36.  
  37.     Console App. User mode.
  38.  
  39. Revision History:
  40.  
  41. --*/
  42.  
  43. #include <windows.h>
  44. #include "Remote.h"
  45. #include "Server.h"
  46. #include "SrvList.h"
  47.  
  48.  
  49. VOID
  50. FASTCALL
  51. InitializeClientLists(
  52.     VOID
  53.     )
  54. {
  55.     InitializeCriticalSection( &csHandshakingList );
  56.     InitializeCriticalSection( &csClientList );
  57.     InitializeCriticalSection( &csClosingClientList );
  58.  
  59.     InitializeListHead( &HandshakingListHead );
  60.     InitializeListHead( &ClientListHead );
  61.     InitializeListHead( &ClosingClientListHead );
  62. }
  63.  
  64.  
  65. VOID
  66. FASTCALL
  67. AddClientToHandshakingList(
  68.     PREMOTE_CLIENT pClient
  69.     )
  70. {
  71.     EnterCriticalSection( &csHandshakingList );
  72.  
  73.     InsertTailList( &HandshakingListHead, &pClient->Links );
  74.  
  75.     LeaveCriticalSection( &csHandshakingList );
  76. }
  77.  
  78.  
  79. VOID
  80. FASTCALL
  81. MoveClientToNormalList(
  82.     PREMOTE_CLIENT pClient
  83.     )
  84. {
  85.     EnterCriticalSection( &csHandshakingList );
  86.  
  87.     RemoveEntryList( &pClient->Links );
  88.  
  89.     LeaveCriticalSection( &csHandshakingList );
  90.  
  91.  
  92.     EnterCriticalSection( &csClientList );
  93.  
  94.     InsertTailList( &ClientListHead, &pClient->Links );
  95.  
  96.     LeaveCriticalSection( &csClientList );
  97. }
  98.  
  99.  
  100. VOID
  101. FASTCALL
  102. MoveClientToClosingList(
  103.     PREMOTE_CLIENT pClient
  104.     )
  105. {
  106.     EnterCriticalSection( &csClientList );
  107.  
  108.     RemoveEntryList( &pClient->Links );
  109.  
  110.     LeaveCriticalSection( &csClientList );
  111.  
  112.  
  113.     EnterCriticalSection( &csClosingClientList );
  114.  
  115.     InsertTailList( &ClosingClientListHead, &pClient->Links );
  116.  
  117.     LeaveCriticalSection( &csClosingClientList );
  118. }
  119.  
  120.  
  121. PREMOTE_CLIENT
  122. FASTCALL
  123. RemoveFirstClientFromClosingList(
  124.     VOID
  125.     )
  126. {
  127.     PREMOTE_CLIENT pClient;
  128.  
  129.     EnterCriticalSection( &csClosingClientList );
  130.  
  131.     if (IsListEmpty(&ClosingClientListHead)) {
  132.  
  133.         pClient = NULL;
  134.  
  135.     } else {
  136.  
  137.         pClient = (PREMOTE_CLIENT) RemoveHeadList( &ClosingClientListHead );
  138.  
  139.         ZeroMemory( &pClient->Links, sizeof(&pClient->Links) );
  140.  
  141.     }
  142.  
  143.     LeaveCriticalSection( &csClosingClientList );
  144.  
  145.     return pClient;
  146. }
  147.