Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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 [....]) {
//
// 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 ([....])
{
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 (![....])
{
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
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// 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 [....]) {
//
// 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 ([....])
{
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 (![....])
{
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
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FormsAuthenticationTicket.cs
- UIPropertyMetadata.cs
- CharStorage.cs
- DataViewManagerListItemTypeDescriptor.cs
- ImmutableObjectAttribute.cs
- ImmutableObjectAttribute.cs
- GlyphRunDrawing.cs
- SmiEventStream.cs
- BitmapImage.cs
- SeekableReadStream.cs
- TransformCryptoHandle.cs
- SchemaRegistration.cs
- OuterGlowBitmapEffect.cs
- TagPrefixAttribute.cs
- ParentUndoUnit.cs
- Wrapper.cs
- FontWeightConverter.cs
- MyContact.cs
- BamlBinaryWriter.cs
- SqlRemoveConstantOrderBy.cs
- ClientTargetCollection.cs
- CounterCreationData.cs
- CodeConditionStatement.cs
- TimerElapsedEvenArgs.cs
- PolyBezierSegment.cs
- X509SecurityTokenProvider.cs
- ping.cs
- RuntimeEnvironment.cs
- CoTaskMemUnicodeSafeHandle.cs
- LogEntry.cs
- BindingListCollectionView.cs
- _NegoState.cs
- DrawingContextDrawingContextWalker.cs
- OutputCacheSection.cs
- OdbcErrorCollection.cs
- IgnoreFlushAndCloseStream.cs
- ChangeProcessor.cs
- TextModifierScope.cs
- UserPersonalizationStateInfo.cs
- COM2IDispatchConverter.cs
- DataGridComboBoxColumn.cs
- MonitorWrapper.cs
- XmlComment.cs
- ActiveDocumentEvent.cs
- DataGridCellEditEndingEventArgs.cs
- Fx.cs
- WebPartDisplayModeCollection.cs
- MetadataItem_Static.cs
- BufferBuilder.cs
- ContentFilePart.cs
- _ProxyRegBlob.cs
- ReachSerializationUtils.cs
- MetadataPropertyCollection.cs
- SqlSelectClauseBuilder.cs
- ByteAnimationBase.cs
- DateRangeEvent.cs
- GroupJoinQueryOperator.cs
- SelectionItemPattern.cs
- DropShadowEffect.cs
- ConfigurationProviderException.cs
- SoapTypeAttribute.cs
- DataProviderNameConverter.cs
- TraceHandlerErrorFormatter.cs
- SearchExpression.cs
- SimpleRecyclingCache.cs
- RuntimeConfigurationRecord.cs
- XmlJsonReader.cs
- TrackingStringDictionary.cs
- ObjectListSelectEventArgs.cs
- BaseCodeDomTreeGenerator.cs
- XmlSchemaDatatype.cs
- HwndTarget.cs
- TransportSecurityBindingElement.cs
- OledbConnectionStringbuilder.cs
- HttpModulesSection.cs
- SqlInfoMessageEvent.cs
- NameValuePermission.cs
- ToolZone.cs
- DynamicILGenerator.cs
- DCSafeHandle.cs
- messageonlyhwndwrapper.cs
- WebPartsSection.cs
- FillBehavior.cs
- OutputWindow.cs
- InternalsVisibleToAttribute.cs
- BitmapCodecInfo.cs
- IPipelineRuntime.cs
- Wildcard.cs
- NumberFunctions.cs
- ForeignKeyFactory.cs
- DecimalSumAggregationOperator.cs
- ListViewSortEventArgs.cs
- CardSpaceException.cs
- ValidatorCompatibilityHelper.cs
- TemplatedMailWebEventProvider.cs
- WarningException.cs
- AnimationStorage.cs
- StylusDownEventArgs.cs
- ProxyWebPartConnectionCollection.cs
- QilSortKey.cs