Leaked source code of windows server 2003
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.

132 lines
3.1 KiB

  1. //
  2. // apihandl.c
  3. //
  4. // This file contains functions used for handle allocation
  5. // and handle state control (the Pause state) on the
  6. // TCLIENT2 connection handle.
  7. //
  8. // Copyright (C) 2001 Microsoft Corporation
  9. //
  10. // Author: a-devjen (Devin Jenson)
  11. //
  12. #include "apihandl.h"
  13. #include "connlist.h"
  14. // T2CreateHandle
  15. //
  16. // Create an internal handle, it does this simply by allocating
  17. // the memory, having it zero'd, and adding it to the linked list.
  18. // It also creates the "Pause" event for the handle, so it can
  19. // be used for pausing the handle.
  20. //
  21. // Returns a pointer to the new handle if successful. Otherwise,
  22. // NULL is returned.
  23. TSAPIHANDLE *T2CreateHandle(void)
  24. {
  25. // Allocate
  26. TSAPIHANDLE *Handle = HeapAlloc(GetProcessHeap(),
  27. HEAP_ZERO_MEMORY, sizeof (TSAPIHANDLE));
  28. if (Handle == NULL)
  29. return NULL;
  30. // Initialize the pause event
  31. Handle->PauseEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
  32. // Add it to the linked list
  33. if (T2ConnList_AddHandle((HANDLE)Handle, 0, 0) == FALSE)
  34. {
  35. HeapFree(GetProcessHeap(), 0, Handle);
  36. return NULL;
  37. }
  38. return Handle;
  39. }
  40. // T2DestroyHandle
  41. //
  42. // It does this by first removing it from the global linked list.
  43. // Then it Closes the "Pause" event, and frees the memory object.
  44. // Finally, if a timer was associated with it for idle-callback,
  45. // it is halted.
  46. //
  47. // No return value.
  48. void T2DestroyHandle(HANDLE Connection)
  49. {
  50. UINT_PTR TimerId = 0;
  51. // Remove from the linked list
  52. T2ConnList_GetData(Connection, &TimerId, NULL);
  53. T2ConnList_RemoveHandle(Connection);
  54. // Enter the exception clause, we are again in a freaky place.
  55. __try {
  56. // Kill the pause event
  57. CloseHandle(((TSAPIHANDLE *)Connection)->PauseEvent);
  58. // Deallocate
  59. HeapFree(GetProcessHeap(), 0, Connection);
  60. if (TimerId != -1 && TimerId != 0)
  61. KillTimer(NULL, TimerId);
  62. }
  63. __except(EXCEPTION_EXECUTE_HANDLER) {
  64. // No failure indication, if we got here the handle is hosed or
  65. // non-existant anyway.
  66. _ASSERT(FALSE);
  67. return;
  68. }
  69. }
  70. // T2WaitForPauseInput
  71. //
  72. // This function only returns when the "Pause" event is in signaled mode.
  73. // Therefore, to pause a handle, set its handle to non-signaled.
  74. //
  75. // No return value.
  76. void T2WaitForPauseInput(HANDLE Connection)
  77. {
  78. // Use exception handling because the handle may be invalid
  79. __try
  80. {
  81. WaitForSingleObject(((TSAPIHANDLE *)Connection)->PauseEvent,
  82. INFINITE);
  83. }
  84. __except(EXCEPTION_EXECUTE_HANDLER)
  85. {
  86. _ASSERT(FALSE);
  87. return;
  88. }
  89. }
  90. // T2WaitForLatency
  91. //
  92. // This function simply waits for the handles latency before returning.
  93. //
  94. // No return value.
  95. void T2WaitForLatency(HANDLE Connection)
  96. {
  97. // Use exception handling because the handle may be invalid
  98. __try
  99. {
  100. Sleep(((TSAPIHANDLE *)Connection)->Latency);
  101. }
  102. __except(EXCEPTION_EXECUTE_HANDLER)
  103. {
  104. _ASSERT(FALSE);
  105. return;
  106. }
  107. }