Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
2.9 KiB

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