/* Copy data from socket buffer to an application provided receive buffer. */
VOID SockSetTcpRxData(IN SOCKET *Sock, IN VOID *TcpRxData, IN UINT32 RcvdBytes, IN BOOLEAN IsUrg)
/* Copy data from socket buffer to an application provided receive buffer. */
VOID SockSetTcpRxData(IN SOCKET *Sock, IN VOID *TcpRxData, IN UINT32 RcvdBytes, IN BOOLEAN IsUrg)
{
  UINT32                  Index;
  UINT32                  CopyBytes;
  UINT32                  OffSet;
  EFI_TCP4_RECEIVE_DATA   *RxData;
  EFI_TCP4_FRAGMENT_DATA  *Fragment;
  RxData = (EFI_TCP4_RECEIVE_DATA *)TcpRxData;
  OffSet = 0;
  ASSERT (RxData->DataLength >= RcvdBytes);
  RxData->DataLength = RcvdBytes;
  RxData->UrgentFlag = IsUrg;
  for (Index = 0; (Index < RxData->FragmentCount) && (RcvdBytes > 0); Index++) {
    Fragment  = &RxData->FragmentTable[Index];
    CopyBytes = MIN ((UINT32)(Fragment->FragmentLength), RcvdBytes);
    NetbufQueCopy (
      Sock->RcvBuffer.DataQueue,
      OffSet,
      CopyBytes,
      Fragment->FragmentBuffer
      );
    Fragment->FragmentLength = CopyBytes;
    RcvdBytes               -= CopyBytes;
    OffSet                  += CopyBytes;
  }
}