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.

258 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. queue.cxx
  5. Abstract:
  6. Implements a queue
  7. Author:
  8. Rohan Phillips ( Rohanp ) 11-Dec-1995
  9. Project:
  10. SMTP Server DLL
  11. Functions Exported:
  12. Revision History:
  13. --*/
  14. /************************************************************
  15. * Include Headers
  16. ************************************************************/
  17. #define INCL_INETSRV_INCS
  18. #include "smtpinc.h"
  19. #include "remoteq.hxx"
  20. /*++
  21. Name :
  22. PERSIST_QUEUE::InitializeQueue
  23. Description:
  24. This function initializes all the class
  25. member functions.
  26. Arguments:
  27. pszQueueName - Name of the on disk queue
  28. Flags - Queue flags
  29. Retry - How long we should retry failed deliveries
  30. FlushQ - How often we should flush the queue to disk
  31. Returns:
  32. TRUE if all memory allocations and all I/O operations pass
  33. FALSE otherwise
  34. --*/
  35. BOOL PERSIST_QUEUE::InitializeQueue (void)
  36. {
  37. TraceFunctEnterEx((LPARAM)this, "PERSIST_QUEUE::InitializeQueue");
  38. // Now, initialize the queue structure:
  39. m_QData.Entries = 0;
  40. m_QData.RetryInterval = 0;
  41. m_QData.StoreInterval = 0;
  42. m_QData.Flags = 0;
  43. m_QData.LastStore = (LONGLONG) 0;
  44. //create the thread that processes things out of the
  45. //the queue
  46. DWORD ThreadId;
  47. DWORD Loop = 0;
  48. for (Loop = 0; Loop < m_NumThreads; Loop++)
  49. {
  50. m_ThreadHandle[Loop] = CreateThread (NULL, 0, PERSIST_QUEUE::QueueThreadRoutine, this, 0, &ThreadId);
  51. if (m_ThreadHandle[Loop] == NULL)
  52. {
  53. TraceFunctLeaveEx((LPARAM)this);
  54. return FALSE;
  55. }
  56. }
  57. TraceFunctLeaveEx((LPARAM)this);
  58. return TRUE;
  59. }
  60. /*++
  61. Name :
  62. PERSIST_QUEUE::CreateQueue
  63. Description:
  64. This is the static member function that creates the Queue
  65. Arguments:
  66. Qtype - the type of queue to create (i.e Local, Remote, etc.)
  67. Returns:
  68. TRUE if all memory allocations and all I/O operaations pass
  69. FALSE otherwise
  70. --*/
  71. PERSIST_QUEUE * PERSIST_QUEUE::CreateQueue(QUEUE_TYPE Qtype, SMTP_SERVER_INSTANCE * pSmtpInst)
  72. {
  73. PERSIST_QUEUE * pQueue = NULL;
  74. _ASSERT (pSmtpInst != NULL);
  75. if(Qtype == REMOTEQ)
  76. {
  77. pQueue = new REMOTE_QUEUE(pSmtpInst);
  78. if(pQueue)
  79. {
  80. pQueue->SetNumThreads(pSmtpInst->GetMaxRemoteQThreads());
  81. }
  82. else
  83. {
  84. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  85. return(NULL);
  86. }
  87. }
  88. else
  89. {
  90. _ASSERT(FALSE);
  91. return NULL;
  92. }
  93. //initialize the queue
  94. if(!pQueue->InitializeQueue())
  95. {
  96. delete pQueue;
  97. pQueue = NULL;
  98. }
  99. return pQueue;
  100. }
  101. /*++
  102. Name :
  103. PERSIST_QUEUE::ProcessQueueEvents
  104. Description:
  105. This is the virtual process function
  106. that all derived classes must override
  107. This function is different depending on
  108. what it is suppose to do. Take a look
  109. at localq.cxx and remoteq.cxx for examples.
  110. Arguments:
  111. Returns:
  112. Always TRUE
  113. --*/
  114. BOOL PERSIST_QUEUE::ProcessQueueEvents(ISMTPConnection *pISMTPConnection)
  115. {
  116. return TRUE;
  117. }
  118. /*++
  119. Name :
  120. PERSIST_QUEUE::FlushQueueEvents
  121. Description:
  122. This function deletes all entries from the queue
  123. Arguments:
  124. Returns:
  125. --*/
  126. void PERSIST_QUEUE::FlushQueueEvents(void)
  127. {
  128. PLIST_ENTRY pEntry;
  129. PQUEUE_ENTRY pQEntry;
  130. TraceFunctEnterEx((LPARAM)this, "PERSIST_QUEUE::FlushQueueEvents");
  131. _ASSERT (GetParentInst() != NULL);
  132. LockQ();
  133. //delete all entries from the list
  134. while(!IsListEmpty (&m_QHead))
  135. {
  136. GetParentInst()->StopHint();
  137. pEntry = RemoveHeadList (&m_QHead);
  138. pQEntry = CONTAINING_RECORD( pEntry, PERSIST_QUEUE_ENTRY, m_QEntry);
  139. pQEntry->BeforeDelete();
  140. delete pQEntry;
  141. }
  142. //reset the stop hint
  143. GetParentInst()->SetStopHint(2);
  144. UnLockQ();
  145. TraceFunctLeaveEx((LPARAM)this);
  146. }
  147. /*++
  148. Name :
  149. PERSIST_QUEUE::QueueThreadRoutine
  150. Description:
  151. This function is the static member
  152. function that gets passed to CreateThread
  153. to initialize the queue.
  154. Arguments:
  155. A pointer to a PERSIST_QUEUE
  156. Returns:
  157. --*/
  158. DWORD WINAPI PERSIST_QUEUE::QueueThreadRoutine(void * ThisPtr)
  159. {
  160. PQUEUE QueuePtr = (PQUEUE) ThisPtr;
  161. HRESULT hr = S_OK;
  162. ISMTPConnection *pISMTPConnection = NULL;
  163. TraceFunctEnterEx((LPARAM)QueuePtr, "PERSIST_QUEUE::QueueThreadRoutine");
  164. while(TRUE)
  165. {
  166. pISMTPConnection = NULL;
  167. hr = QueuePtr->GetParentInst()->GetConnManPtr()->GetNextConnection(&pISMTPConnection);
  168. if(!FAILED(hr))
  169. {
  170. //call the virtual process function
  171. QueuePtr->ProcessQueueEvents(pISMTPConnection);
  172. //if we are shutting down, break out of the loop
  173. if (QueuePtr->GetParentInst()->IsShuttingDown())
  174. goto Out;
  175. }
  176. else
  177. {
  178. //if we are shutting down, break out of the loop
  179. if (QueuePtr->GetParentInst()->IsShuttingDown())
  180. goto Out;
  181. }
  182. }
  183. Out:
  184. TraceFunctLeaveEx((LPARAM)QueuePtr);
  185. return 1;
  186. }