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.

273 lines
9.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: pipe.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <precomp.hxx>
  11. #include "pipe.h"
  12. void I_RpcReadPipeElementsFromBuffer (
  13. PIPE_STATE PAPI *state,
  14. char PAPI *TargetBuffer,
  15. int TargetBufferSize,
  16. int PAPI *NumCopied
  17. )
  18. {
  19. char PAPI *temp, PAPI *temp1 ;
  20. int size ;
  21. int totalsize ;
  22. ASSERT(state->CurrentState == start ||
  23. (state->PartialCountSize < sizeof(DWORD) &&
  24. state->PartialPipeElementSize < state->PipeElementSize)) ;
  25. if (TargetBufferSize < state->PipeElementSize)
  26. {
  27. return ;
  28. }
  29. while (1)
  30. {
  31. switch(state->CurrentState)
  32. {
  33. case start:
  34. // read in an element count
  35. if (state->BytesRemaining == 0)
  36. {
  37. return ;
  38. }
  39. // transition: end of src
  40. if (state->BytesRemaining <sizeof(DWORD))
  41. {
  42. state->CurrentState = return_partial_count ;
  43. break;
  44. }
  45. // transition: scan chunk count
  46. state->PartialCount = 0 ;
  47. state->PartialCountSize = 0 ;
  48. state->PartialPipeElementSize = 0 ;
  49. state->ElementsRemaining = *((DWORD *) state->CurPointer) ;
  50. #if DBG
  51. PrintToDebugger("PIPES: <start> ElementsRemainaing: %d\n",
  52. state->ElementsRemaining) ;
  53. #endif
  54. state->CurPointer += sizeof(DWORD) ;
  55. state->BytesRemaining -= sizeof(DWORD) ;
  56. if (state->ElementsRemaining == 0)
  57. {
  58. state->EndOfPipe = 1 ;
  59. return ;
  60. }
  61. else
  62. {
  63. state->CurrentState = copy_pipe_elem ;
  64. }
  65. break;
  66. case read_partial_count: // also a start state & final state
  67. size = sizeof(DWORD) ;
  68. totalsize = 0 ;
  69. ASSERT(state->PartialCountSize > 0 && state->PartialCountSize < 4) ;
  70. ASSERT(state->ElementsRemaining == 0) ;
  71. temp = (char *) &(state->PartialCount) ;
  72. temp1 = (char *) &(state->ElementsRemaining) ;
  73. for (;state->PartialCountSize;
  74. state->PartialCountSize--, size--, totalsize++)
  75. {
  76. *temp1++ = *temp++ ;
  77. }
  78. for (;size && state->BytesRemaining;
  79. size--,state->BytesRemaining--, totalsize++)
  80. {
  81. *temp1++ = *state->CurPointer++ ;
  82. }
  83. #if DBG
  84. PrintToDebugger("PIPES: <read_partial_count>ElementsRemainaing: %d\n",
  85. state->ElementsRemaining) ;
  86. #endif
  87. if (size == 0)
  88. {
  89. state->CurrentState = copy_pipe_elem ;
  90. }
  91. else
  92. {
  93. // copy the stuff back into Partial count
  94. // and keep it around for the next call
  95. // the next time around, we'll end up in the same
  96. // state
  97. temp = (char *) &(state->PartialCount) ;
  98. temp1 = (char *) &(state->ElementsRemaining) ;
  99. ASSERT(totalsize < sizeof(DWORD)) ;
  100. for (;totalsize; totalsize--, state->PartialCountSize++)
  101. {
  102. *temp++ = *temp1++ ;
  103. }
  104. return ;
  105. }
  106. break;
  107. case read_partial_pipe_elem: //also a start state
  108. ASSERT(state->PartialPipeElementSize > 0 &&
  109. state->PartialPipeElementSize < state->PipeElementSize) ;
  110. if (TargetBufferSize < state->PipeElementSize)
  111. {
  112. // this is not an error
  113. return ;
  114. }
  115. size = state->PipeElementSize ;
  116. if (state->BytesRemaining >= size-state->PartialPipeElementSize)
  117. {
  118. temp = (char *) state->PartialPipeElement ;
  119. for (;state->PartialPipeElementSize;
  120. state->PartialPipeElementSize--, size--,
  121. TargetBufferSize--)
  122. {
  123. *TargetBuffer++ = *temp++ ;
  124. }
  125. for (;size && state->BytesRemaining;
  126. size--, state->BytesRemaining--,
  127. TargetBufferSize--)
  128. {
  129. *TargetBuffer++ = *state->CurPointer++ ;
  130. }
  131. state->CurrentState = copy_pipe_elem ;
  132. *NumCopied += 1 ;
  133. }
  134. else
  135. {
  136. // copy the stuff back into partial pipe buffer
  137. // and keep it around for the next call
  138. // the next time around, we'll end up in the same
  139. // state
  140. temp = (char *) state->PartialPipeElement+
  141. state->PartialPipeElementSize ;
  142. for (;state->BytesRemaining; state->BytesRemaining--,
  143. state->PartialPipeElementSize++)
  144. {
  145. *temp++ = *state->CurPointer++ ;
  146. }
  147. return ;
  148. }
  149. break;
  150. case copy_pipe_elem: // also a start state
  151. if (state->BytesRemaining >= state->PipeElementSize)
  152. {
  153. if (TargetBufferSize >= state->PipeElementSize)
  154. {
  155. for (size = state->PipeElementSize; size;
  156. size--, TargetBufferSize--, state->BytesRemaining--)
  157. {
  158. *TargetBuffer++ = *state->CurPointer++ ;
  159. }
  160. state->ElementsRemaining-- ;
  161. *NumCopied += 1 ;
  162. if (state->ElementsRemaining == 0)
  163. {
  164. state->CurrentState = start ;
  165. if (TargetBufferSize < state->PipeElementSize)
  166. {
  167. return ;
  168. }
  169. }
  170. }
  171. else
  172. {
  173. // end of target buffer
  174. // return the appropriate count
  175. return ;
  176. }
  177. }
  178. else
  179. {
  180. if (state->BytesRemaining)
  181. {
  182. state->CurrentState = return_partial_pipe_elem ;
  183. }
  184. else
  185. {
  186. return ;
  187. }
  188. }
  189. break;
  190. case return_partial_pipe_elem: // also save pipe elem
  191. ASSERT(state->BytesRemaining < state->PipeElementSize) ;
  192. state->PartialPipeElementSize = 0;
  193. for (temp = (char *) state->PartialPipeElement; state->BytesRemaining;
  194. state->BytesRemaining--, state->PartialPipeElementSize++)
  195. {
  196. *temp++ = *state->CurPointer++ ;
  197. }
  198. state->CurrentState = read_partial_pipe_elem ;
  199. return;
  200. case return_partial_count: // also save count
  201. state->PartialCountSize = 0 ;
  202. ASSERT(state->BytesRemaining < sizeof(DWORD)) ;
  203. for (temp = (char *) &(state->PartialCount); state->BytesRemaining;
  204. state->BytesRemaining--, state->PartialCountSize++)
  205. {
  206. *temp++ = *state->CurPointer++ ;
  207. }
  208. state->CurrentState = read_partial_count ;
  209. return;
  210. default:
  211. ASSERT(0) ;
  212. break;
  213. }
  214. }
  215. }
  216. RPC_STATUS RPC_ENTRY
  217. MyRpcCompleteAsyncCall (
  218. IN PRPC_ASYNC_STATE pAsync,
  219. IN void *Reply
  220. )
  221. /*++
  222. Function Name:MyRpcCompleteAsyncCall
  223. This is function is used by the bvts, the real stuff will call
  224. RpcCompleteAsyncCall.
  225. Parameters:
  226. Description:
  227. Returns:
  228. --*/
  229. {
  230. return STUB(pAsync)->CompletionRoutine (pAsync, Reply) ;
  231. }