locked
why to use FpwsCopyStreamDataToBuffer function's bytesCopied parameter? RRS feed

  • Question

  • i made a wrapper function.
    it is following code...

    STREAM_CopyInboundStreamDataToBuffer(
     IN FLOW_CONTEXT_V4 *pFlowContextV4,
     IN FWPS_STREAM_DATA *pStreamData
    )
    {
     SIZE_T nMessageBufferIndex = 0;
     SIZE_T nEmptyBufferSizeInByte = 0;
     SIZE_T nByteToCopy = 0;
     SIZE_T nByteCopied = 0;  
    
     nMessageBufferIndex = pFlowContextV4->byMessageBufferArray + pFlowContextV4->uiMessageLengthInByte;
     nEmptyBufferSizeInByte = sizeof(pFlowContextV4->byMessageBufferArray) - pFlowContextV4->uiMessageLengthInByte;
     if (nEmptyBufferSizeInByte >= pStreamData->dataLength) 
      nByteToCopy = pStreamData->dataLength;
     else 
      nByteToCopy = nEmptyBufferSizeInByte;
    
     if (nByteToCopy > 0)
     {
      // warning :
      // pStreamData->dataLength can be different from nByteCopied
      FwpsCopyStreamDataToBuffer(pStreamData, 
               &pFlowContextV4->byMessageBufferArray[ nMessageBufferIndex ],
               nByteToCopy, 
               &nByteCopied);
      if (pStreamData->dataLength != nByteCopied)
      {
       // what i have to do?
      }
      pFlowContextV4->uiMessageLengthInByte += nByteCopied;
     }
    }
    
    as you can see, FwpsCopyStreamDataToBuffer can copy bigger size's data to the buffer....
    MSDN Doc also tell "ensure that the buffer is at least calloutStreamData->dataLength in size"

    i didn't research about FWPS_STREAM_DATA0 structure
    but, is it possible that nByteToCopy is differerent from nByteCopied?
    i think nByteCopied is meaningless parameter.

    anyway...
    if pStreamData->dataLength is different from nByteCopied,
    what i have to do?
    Saturday, February 27, 2010 10:15 AM

Answers

  • bytesToCopy is saying how much of calloutStreamData do you want to copy into buffer

    bytesCopied
    is a confirmation of how many bytes actually got copied.  If an error were to occur then this is how one would determine so (the function has no return value).  If bytesCopied is less than bytesToCopy, then you know there was an issue and you need to address it appropriately.

    This function allows you to choose how much data you want to copy  so if pStreamData->dataLength is 100, you can choose to only copy 50 of it.

    Hope this helps.
    Dusty Harper [MSFT]
    Microsoft Corporation
    ------------------------------------------------------------
    This posting is provided "AS IS", with NO warranties and confers NO rights
    ------------------------------------------------------------
    Tuesday, March 2, 2010 9:21 PM
    Moderator