Beispiel #1
0
        internal static unsafe uint GetChunks(IntPtr memoryBlob, IntPtr originalAddress, ref int dataChunkIndex, ref uint dataChunkOffset, byte[] buffer, int offset, int size)
        {
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Enter(null, $"HttpApi::GetChunks() memoryBlob:{memoryBlob}");
            }

            // Return value.
            uint          dataRead    = 0;
            byte *        pMemoryBlob = (byte *)memoryBlob;
            HTTP_REQUEST *request     = (HTTP_REQUEST *)pMemoryBlob;
            long          fixup       = pMemoryBlob - (byte *)originalAddress;

            if (request->EntityChunkCount > 0 && dataChunkIndex < request->EntityChunkCount && dataChunkIndex != -1)
            {
                HTTP_DATA_CHUNK *pDataChunk = (HTTP_DATA_CHUNK *)(fixup + (byte *)&request->pEntityChunks[dataChunkIndex]);

                fixed(byte *pReadBuffer = buffer)
                {
                    byte *pTo = &pReadBuffer[offset];

                    while (dataChunkIndex < request->EntityChunkCount && dataRead < size)
                    {
                        if (dataChunkOffset >= pDataChunk->BufferLength)
                        {
                            dataChunkOffset = 0;
                            dataChunkIndex++;
                            pDataChunk++;
                        }
                        else
                        {
                            byte *pFrom = pDataChunk->pBuffer + dataChunkOffset + fixup;

                            uint bytesToRead = pDataChunk->BufferLength - (uint)dataChunkOffset;
                            if (bytesToRead > (uint)size)
                            {
                                bytesToRead = (uint)size;
                            }
                            for (uint i = 0; i < bytesToRead; i++)
                            {
                                *(pTo++) = *(pFrom++);
                            }
                            dataRead        += bytesToRead;
                            dataChunkOffset += bytesToRead;
                        }
                    }
                }
            }
            //we're finished.
            if (dataChunkIndex == request->EntityChunkCount)
            {
                dataChunkIndex = -1;
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Exit(null);
            }
            return(dataRead);
        }
Beispiel #2
0
        internal static uint GetChunks(byte[] memoryBlob, IntPtr originalAddress, ref int dataChunkIndex, ref uint dataChunkOffset, byte[] buffer, int offset, int size)
        {
            GlobalLog.Enter("HttpApi::GetChunks() memoryBlob:" + ValidationHelper.ToString(memoryBlob));

            // Return value.
            uint dataRead = 0;

            fixed(byte *pMemoryBlob = memoryBlob)
            {
                HTTP_REQUEST *request = (HTTP_REQUEST *)pMemoryBlob;
                long          fixup   = pMemoryBlob - (byte *)originalAddress;

                if (request->EntityChunkCount > 0 && dataChunkIndex < request->EntityChunkCount && dataChunkIndex != -1)
                {
                    HTTP_DATA_CHUNK *pDataChunk = (HTTP_DATA_CHUNK *)(fixup + (byte *)&request->pEntityChunks[dataChunkIndex]);

                    fixed(byte *pReadBuffer = buffer)
                    {
                        byte *pTo = &pReadBuffer[offset];

                        while (dataChunkIndex < request->EntityChunkCount && dataRead < size)
                        {
                            if (dataChunkOffset >= pDataChunk->BufferLength)
                            {
                                dataChunkOffset = 0;
                                dataChunkIndex++;
                                pDataChunk++;
                            }
                            else
                            {
                                byte *pFrom = pDataChunk->pBuffer + dataChunkOffset + fixup;

                                uint bytesToRead = pDataChunk->BufferLength - (uint)dataChunkOffset;
                                if (bytesToRead > (uint)size)
                                {
                                    bytesToRead = (uint)size;
                                }
                                for (uint i = 0; i < bytesToRead; i++)
                                {
                                    *(pTo++) = *(pFrom++);
                                }
                                dataRead        += bytesToRead;
                                dataChunkOffset += bytesToRead;
                            }
                        }
                    }
                }
                //we're finished.
                if (dataChunkIndex == request->EntityChunkCount)
                {
                    dataChunkIndex = -1;
                }
            }

            GlobalLog.Leave("HttpApi::GetChunks()");
            return(dataRead);
        }
Beispiel #3
0
 internal static extern uint HttpSendResponseEntityBody(SafeHandle requestQueueHandle, ulong requestId, uint flags, ushort entityChunkCount, HTTP_DATA_CHUNK *pEntityChunks, uint *pBytesSent, IntPtr pReserved1, uint Reserved2, SafeNativeOverlapped pOverlapped, IntPtr pLogData);
Beispiel #4
0
 internal static extern unsafe uint HttpSendResponseEntityBody(SafeHandle requestQueueHandle, ulong requestId, uint flags, ushort entityChunkCount, HTTP_DATA_CHUNK *pEntityChunks, uint *pBytesSent, SafeLocalAllocHandle pRequestBuffer, uint requestBufferLength, NativeOverlapped *pOverlapped, void *pLogData);