internal void SetUnmanagedStructures(byte[] preBuffer, byte[] postBuffer, FileStream fileStream, TransmitFileOptions flags, bool sync) { this.m_fileStream = fileStream; this.m_flags = flags; this.m_buffers = null; int num = 0; if ((preBuffer != null) && (preBuffer.Length > 0)) { num++; } if ((postBuffer != null) && (postBuffer.Length > 0)) { num++; } object[] objectsToPin = null; if (num != 0) { num++; objectsToPin = new object[num]; this.m_buffers = new System.Net.TransmitFileBuffers(); objectsToPin[--num] = this.m_buffers; if ((preBuffer != null) && (preBuffer.Length > 0)) { this.m_buffers.preBufferLength = preBuffer.Length; objectsToPin[--num] = preBuffer; } if ((postBuffer != null) && (postBuffer.Length > 0)) { this.m_buffers.postBufferLength = postBuffer.Length; objectsToPin[--num] = postBuffer; } if (sync) { base.PinUnmanagedObjects(objectsToPin); } else { base.SetUnmanagedStructures(objectsToPin); } if ((preBuffer != null) && (preBuffer.Length > 0)) { this.m_buffers.preBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(preBuffer, 0); } if ((postBuffer != null) && (postBuffer.Length > 0)) { this.m_buffers.postBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(postBuffer, 0); } } else if (!sync) { base.SetUnmanagedStructures(null); } }
// // SetUnmanagedStructures - // Fills in Overlapped Structures used in an Async Overlapped Winsock call // these calls are outside the runtime and are unmanaged code, so we need // to prepare specific structures and ints that lie in unmanaged memory // since the Overlapped calls can be Async // internal void SetUnmanagedStructures(byte[] preBuffer, byte[] postBuffer, FileStream fileStream, TransmitFileOptions flags, bool sync) { // // fill in flags if we use it. // m_fileStream = fileStream; m_flags = flags; // // Fill in Buffer Array structure that will be used for our send/recv Buffer // m_buffers = null; int buffsNumber = 0; if (preBuffer != null && preBuffer.Length>0) ++buffsNumber; if (postBuffer != null && postBuffer.Length>0) ++buffsNumber; object[] objectsToPin = null; if (buffsNumber != 0) { ++buffsNumber; objectsToPin = new object[buffsNumber]; m_buffers = new TransmitFileBuffers(); objectsToPin[--buffsNumber] = m_buffers; if (preBuffer != null && preBuffer.Length>0) { m_buffers.preBufferLength = preBuffer.Length; objectsToPin[--buffsNumber] = preBuffer; } if (postBuffer != null && postBuffer.Length>0) { m_buffers.postBufferLength = postBuffer.Length; objectsToPin[--buffsNumber] = postBuffer; } if (sync) { base.PinUnmanagedObjects(objectsToPin); } else { base.SetUnmanagedStructures(objectsToPin); } if (preBuffer != null && preBuffer.Length > 0) { m_buffers.preBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(preBuffer, 0); } if (postBuffer != null && postBuffer.Length > 0) { m_buffers.postBuffer = Marshal.UnsafeAddrOfPinnedArrayElement(postBuffer, 0); } } else if (!sync) { base.SetUnmanagedStructures(null); } } // SetUnmanagedStructures()