Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Net / System / Net / Sockets / _TransmitFileOverlappedAsyncResult.cs / 1 / _TransmitFileOverlappedAsyncResult.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net.Sockets { using System; using System.Net; using System.IO; using System.Runtime.InteropServices; using System.Threading; using Microsoft.Win32; // // OverlappedAsyncResult - used to take care of storage for async Socket operation // from the BeginSend, BeginSendTo, BeginReceive, BeginReceiveFrom calls. // internal class TransmitFileOverlappedAsyncResult : BaseOverlappedAsyncResult { // // internal class members // private FileStream m_fileStream; private TransmitFileOptions m_flags; private TransmitFileBuffers m_buffers; // Constructor. We take in the socket that's creating us, the caller's // state object, and the buffer on which the I/O will be performed. // We save the socket and state, pin the callers's buffer, and allocate // an event for the WaitHandle. // internal TransmitFileOverlappedAsyncResult(Socket socket, Object asyncState, AsyncCallback asyncCallback) : base(socket, asyncState, asyncCallback) { } internal TransmitFileOverlappedAsyncResult(Socket socket):base(socket){ } // // 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() internal void SetUnmanagedStructures(byte[] preBuffer, byte[] postBuffer, FileStream fileStream, TransmitFileOptions flags, ref OverlappedCache overlappedCache) { SetupCache(ref overlappedCache); SetUnmanagedStructures(preBuffer, postBuffer, fileStream, flags, false); } // Utility cleanup routine. Frees pinned and unmanged memory. // protected override void ForceReleaseUnmanagedStructures() { if (m_fileStream != null ) { m_fileStream.Close(); m_fileStream = null; } // // clenaup base class // base.ForceReleaseUnmanagedStructures(); } // CleanupUnmanagedStructures() internal void SyncReleaseUnmanagedStructures() { ForceReleaseUnmanagedStructures(); } internal TransmitFileBuffers TransmitFileBuffers{ get{ return m_buffers; } } internal TransmitFileOptions Flags{ get{ return m_flags; } } }; // class OverlappedAsyncResult } // namespace System.Net.Sockets
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ErrorHandlingReceiver.cs
- BuilderPropertyEntry.cs
- FieldNameLookup.cs
- GenericRootAutomationPeer.cs
- ParseElement.cs
- CompatibleComparer.cs
- EntityContainerEntitySet.cs
- DashStyle.cs
- DurationConverter.cs
- FontInfo.cs
- Rect3DValueSerializer.cs
- CompositionTarget.cs
- AutomationIdentifierGuids.cs
- CodeObjectCreateExpression.cs
- TreeNodeStyle.cs
- OutputCacheModule.cs
- dataprotectionpermission.cs
- ButtonFieldBase.cs
- EntitySqlQueryBuilder.cs
- TextSpan.cs
- DataGridViewBand.cs
- Convert.cs
- OptimisticConcurrencyException.cs
- ProfileParameter.cs
- DoubleConverter.cs
- HttpWebRequestElement.cs
- SourceFileInfo.cs
- TypeDescriptor.cs
- MexBindingBindingCollectionElement.cs
- WizardDesigner.cs
- _AutoWebProxyScriptHelper.cs
- CellIdBoolean.cs
- BoolExpressionVisitors.cs
- HtmlInputRadioButton.cs
- DocumentNUp.cs
- BrowserTree.cs
- BoolExpressionVisitors.cs
- RepeaterItem.cs
- RegexWorker.cs
- HttpContextServiceHost.cs
- TemplateControlParser.cs
- TemplateEditingFrame.cs
- SqlPersonalizationProvider.cs
- SectionUpdates.cs
- DbQueryCommandTree.cs
- MD5HashHelper.cs
- RankException.cs
- TransactionScope.cs
- ICspAsymmetricAlgorithm.cs
- oledbmetadatacollectionnames.cs
- JavaScriptObjectDeserializer.cs
- ConfigPathUtility.cs
- XPathScanner.cs
- DbResourceAllocator.cs
- Event.cs
- CommandHelper.cs
- PageThemeParser.cs
- AdapterUtil.cs
- TypeLoadException.cs
- DataSvcMapFileSerializer.cs
- ErrorView.xaml.cs
- SetStoryboardSpeedRatio.cs
- WebPartChrome.cs
- DynamicMethod.cs
- TimeSpanSecondsOrInfiniteConverter.cs
- PageRanges.cs
- AutomationPeer.cs
- DbProviderFactory.cs
- ServiceDescriptionContext.cs
- MenuItemCollection.cs
- GlyphRunDrawing.cs
- CompilerTypeWithParams.cs
- GeneralTransform2DTo3DTo2D.cs
- ActivationServices.cs
- InkSerializer.cs
- DataRow.cs
- ProgressPage.cs
- Registry.cs
- GridViewRow.cs
- ProcessModule.cs
- XmlDataSourceView.cs
- DeadCharTextComposition.cs
- HttpModule.cs
- PropertyGridCommands.cs
- CodeGeneratorOptions.cs
- CssStyleCollection.cs
- FragmentNavigationEventArgs.cs
- CryptoHandle.cs
- BoundPropertyEntry.cs
- Int32Storage.cs
- BitmapSource.cs
- FlowDocumentReader.cs
- EmptyStringExpandableObjectConverter.cs
- CryptoProvider.cs
- FileSecurity.cs
- FormView.cs
- SqlConnectionFactory.cs
- SelectorAutomationPeer.cs
- WorkItem.cs
- HttpRuntimeSection.cs