本文整理汇总了C#中TransmitFileOptions类的典型用法代码示例。如果您正苦于以下问题:C# TransmitFileOptions类的具体用法?C# TransmitFileOptions怎么用?C# TransmitFileOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransmitFileOptions类属于命名空间,在下文中一共展示了TransmitFileOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransmitFile
internal static extern unsafe bool TransmitFile(
SafeHandle socket,
SafeHandle fileHandle,
int numberOfBytesToWrite,
int numberOfBytesPerSend,
SafeHandle overlapped,
TransmitFileBuffers* buffers,
TransmitFileOptions flags);
示例2: CheckTransmitFileOptions
private static void CheckTransmitFileOptions(TransmitFileOptions flags)
{
// Note, UseDefaultWorkerThread is the default and is == 0.
// Unfortunately there is no TransmitFileOptions.None.
if (flags != TransmitFileOptions.UseDefaultWorkerThread)
{
throw new PlatformNotSupportedException(SR.net_sockets_transmitfileoptions_notsupported);
}
}
示例3: SendFileAPM
public static void SendFileAPM(this Socket socket, string filename, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags, Action handler)
{
var callback = new AsyncCallback(asyncResult =>
{
((Socket)asyncResult.AsyncState).EndSendFile(asyncResult);
handler();
});
socket.BeginSendFile(filename, preBuffer, postBuffer, flags, callback, socket);
}
示例4: SetUnmanagedStructures
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);
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:53,代码来源:TransmitFileOverlappedAsyncResult.cs
示例5: SendFileInternal
private void SendFileInternal(string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags)
{
CheckTransmitFileOptions(flags);
// Open the file, if any
// Open it before we send the preBuffer so that any exception happens first
FileStream fileStream = OpenFile(fileName);
SocketError errorCode = SocketError.Success;
using (fileStream)
{
// Send the preBuffer, if any
// This will throw on error
if (preBuffer != null && preBuffer.Length > 0)
{
Send(preBuffer);
}
// Send the file, if any
if (fileStream != null)
{
// This can throw ObjectDisposedException.
errorCode = SocketPal.SendFile(_handle, fileStream);
}
}
if (errorCode != SocketError.Success)
{
SocketException socketException = new SocketException((int)errorCode);
UpdateStatusAfterSocketError(socketException);
if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
throw socketException;
}
// Send the postBuffer, if any
// This will throw on error
if (postBuffer != null && postBuffer.Length > 0)
{
Send(postBuffer);
}
}
示例6: SendFile_internal
static bool SendFile_internal (SafeSocketHandle safeHandle, string filename, byte [] pre_buffer, byte [] post_buffer, TransmitFileOptions flags)
{
try {
safeHandle.RegisterForBlockingSyscall ();
return SendFile_internal (safeHandle.DangerousGetHandle (), filename, pre_buffer, post_buffer, flags);
} finally {
safeHandle.UnRegisterForBlockingSyscall ();
}
}
示例7: SendFile
public void SendFile (string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags)
{
ThrowIfDisposedAndClosed ();
if (!is_connected)
throw new NotSupportedException ();
if (!is_blocking)
throw new InvalidOperationException ();
if (!SendFile_internal (safe_handle, fileName, preBuffer, postBuffer, flags)) {
SocketException exc = new SocketException ();
if (exc.ErrorCode == 2 || exc.ErrorCode == 3)
throw new FileNotFoundException ();
throw exc;
}
}
示例8: BeginSendFile
public IAsyncResult BeginSendFile (string fileName,
byte[] preBuffer,
byte[] postBuffer,
TransmitFileOptions flags,
AsyncCallback callback,
object state)
{
if (disposed && closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (!connected)
throw new NotSupportedException ();
if (!File.Exists (fileName))
throw new FileNotFoundException ();
SendFileHandler d = new SendFileHandler (SendFile);
return new SendFileAsyncResult (d, d.BeginInvoke (fileName, preBuffer, postBuffer, flags, ar => {
SendFileAsyncResult sfar = new SendFileAsyncResult (d, ar);
callback (sfar);
}, state));
}
示例9: SetUnmanagedStructures
} // SetUnmanagedStructures()
internal void SetUnmanagedStructures(byte[] preBuffer, byte[] postBuffer, FileStream fileStream, TransmitFileOptions flags, ref OverlappedCache overlappedCache)
{
SetupCache(ref overlappedCache);
SetUnmanagedStructures(preBuffer, postBuffer, fileStream, flags, false);
}
示例10: DoBeginSendFile
private void DoBeginSendFile(
string fileName,
byte[] preBuffer,
byte[] postBuffer,
TransmitFileOptions flags,
TransmitFileOverlappedAsyncResult asyncResult)
{
if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "BeginSendFile", "");
if (CleanedUp) {
throw new ObjectDisposedException(this.GetType().FullName);
}
if (CleanedUp) {
throw new ObjectDisposedException(this.GetType().FullName);
}
#if FEATURE_PAL
throw new PlatformNotSupportedException(SR.GetString(SR.WinNTRequired));
#endif // FEATURE_PAL
if (!Connected) {
throw new NotSupportedException(SR.GetString(SR.net_notconnected));
}
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginSendFile() SRC:" + ValidationHelper.ToString(LocalEndPoint) + " DST:" + ValidationHelper.ToString(RemoteEndPoint) + " fileName:" + fileName);
FileStream fileStream = null;
if (fileName != null && fileName.Length>0) {
fileStream = new FileStream(fileName,FileMode.Open,FileAccess.Read,FileShare.Read);
}
SafeHandle fileHandle = null;
if (fileStream != null) {
ExceptionHelper.UnmanagedPermission.Assert();
try {
fileHandle = fileStream.SafeFileHandle;
}
finally {
SecurityPermission.RevertAssert();
}
}
// Guarantee to call CheckAsyncCallOverlappedResult if we call SetUnamangedStructures with a cache in order to
// avoid a Socket leak in case of error.
SocketError errorCode = SocketError.SocketError;
try
{
asyncResult.SetUnmanagedStructures(preBuffer, postBuffer, fileStream, flags, ref Caches.SendOverlappedCache);
bool result = false;
// This can throw ObjectDisposedException.
if (fileHandle != null){
result = UnsafeNclNativeMethods.OSSOCK.TransmitFile(m_Handle,fileHandle,0,0,asyncResult.OverlappedHandle,asyncResult.TransmitFileBuffers,flags);
}
else{
result = UnsafeNclNativeMethods.OSSOCK.TransmitFile2(m_Handle,IntPtr.Zero,0,0,asyncResult.OverlappedHandle,asyncResult.TransmitFileBuffers,flags);
}
if(!result)
{
errorCode = (SocketError)Marshal.GetLastWin32Error();
}
else
{
errorCode = SocketError.Success;
}
}
finally
{
errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
}
//
// if the native call fails we'll throw a SocketException
//
if (errorCode!=SocketError.Success) {
//
// update our internal state after this socket error and throw
//
asyncResult.ExtractCache(ref Caches.SendOverlappedCache);
SocketException socketException = new SocketException(errorCode);
UpdateStatusAfterSocketError(socketException);
if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "BeginSendFile", socketException);
throw socketException;
}
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::DoBeginSendFile() UnsafeNclNativeMethods.OSSOCK.send returns:" + errorCode.ToString());
if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "BeginSendFile", errorCode);
}
示例11: SendFile
public void SendFile(string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags) {
if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "SendFile", "");
if (CleanedUp) {
throw new ObjectDisposedException(this.GetType().FullName);
}
if (!Connected) {
throw new NotSupportedException(SR.GetString(SR.net_notconnected));
}
ValidateBlockingMode();
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::SendFile() SRC:" + ValidationHelper.ToString(LocalEndPoint) + " DST:" + ValidationHelper.ToString(RemoteEndPoint) + " fileName:" + fileName);
TransmitFileOverlappedAsyncResult asyncResult = new TransmitFileOverlappedAsyncResult(this);
FileStream fileStream = null;
if (fileName != null && fileName.Length>0) {
fileStream = new FileStream(fileName,FileMode.Open,FileAccess.Read,FileShare.Read);
}
SafeHandle fileHandle = null;
if (fileStream != null) {
ExceptionHelper.UnmanagedPermission.Assert();
try {
fileHandle = fileStream.SafeFileHandle;
}
finally {
SecurityPermission.RevertAssert();
}
}
SocketError errorCode = SocketError.Success;
try {
asyncResult.SetUnmanagedStructures(preBuffer, postBuffer, fileStream, 0, true);
// This can throw ObjectDisposedException.
if (fileHandle != null ?
!UnsafeNclNativeMethods.OSSOCK.TransmitFile_Blocking(m_Handle.DangerousGetHandle(), fileHandle, 0, 0, SafeNativeOverlapped.Zero, asyncResult.TransmitFileBuffers, flags) :
!UnsafeNclNativeMethods.OSSOCK.TransmitFile_Blocking2(m_Handle.DangerousGetHandle(), IntPtr.Zero, 0, 0, SafeNativeOverlapped.Zero, asyncResult.TransmitFileBuffers, flags))
{
errorCode = (SocketError) Marshal.GetLastWin32Error();
}
}
finally {
asyncResult.SyncReleaseUnmanagedStructures();
}
#if TRAVE
try
{
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::SendFile() SRC:" + ValidationHelper.ToString(LocalEndPoint) + " DST:" + ValidationHelper.ToString(RemoteEndPoint) + " UnsafeNclNativeMethods.OSSOCK.TransmitFile returns errorCode:" + errorCode);
}
catch (ObjectDisposedException) { }
#endif
//
// if the native call fails we'll throw a SocketException
//
if (errorCode!=SocketError.Success) {
//
// update our internal state after this socket error and throw
//
SocketException socketException = new SocketException(errorCode);
UpdateStatusAfterSocketError(socketException);
if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "SendFile", socketException);
throw socketException;
}
if ((asyncResult.Flags & (TransmitFileOptions.Disconnect | TransmitFileOptions.ReuseSocket) )!=0) {
SetToDisconnected();
m_RemoteEndPoint = null;
}
if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "SendFile", errorCode);
return;
}
示例12: SendFileObservable
public static IObservable<Unit> SendFileObservable(this Socket socket, string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags)
{
Contract.Requires(socket != null);
Contract.Ensures(Contract.Result<IObservable<Unit>>() != null);
return Task.Factory.FromAsync<string, Tuple<byte[], byte[]>, TransmitFileOptions>(
(fn, buffers, fg, callback, state) => socket.BeginSendFile(fn, buffers.Item1, buffers.Item2, fg, callback, state),
socket.EndSendFile,
fileName,
Tuple.Create(preBuffer, postBuffer),
flags,
state: null)
.ToObservable();
}
示例13: BeginSendFile
/// <summary>
/// Extends BeginSendFile so that when a state object is not needed, null does not need to be passed.
/// <example>
/// socket.BeginSendFile(fileName, preBuffer, postBuffer, flags, callback);
/// </example>
/// </summary>
public static IAsyncResult BeginSendFile(this Socket socket, String fileName, Byte[] preBuffer, Byte[] postBuffer, TransmitFileOptions flags, AsyncCallback callback)
{
if(socket == null) throw new ArgumentNullException("socket");
return socket.BeginSendFile(fileName, preBuffer, postBuffer, flags, callback, null);
}
示例14: BeginSendFileInternal
private IAsyncResult BeginSendFileInternal(string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags, AsyncCallback callback, object state)
{
FileStream fileStream = OpenFile(fileName);
TransmitFileAsyncResult asyncResult = new TransmitFileAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
SocketError errorCode = SocketPal.SendFileAsync(_handle, fileStream, preBuffer, postBuffer, flags, asyncResult);
// Check for synchronous exception
if (errorCode != SocketError.Success)
{
SocketException socketException = new SocketException((int)errorCode);
UpdateStatusAfterSocketError(socketException);
if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
throw socketException;
}
asyncResult.FinishPostingAsyncOp(ref Caches.SendClosureCache);
return asyncResult;
}
示例15: SendFileInternal
private void SendFileInternal(string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags)
{
// Open the file, if any
FileStream fileStream = OpenFile(fileName);
SocketError errorCode;
using (fileStream)
{
SafeFileHandle fileHandle = fileStream?.SafeFileHandle;
// This can throw ObjectDisposedException.
errorCode = SocketPal.SendFile(_handle, fileHandle, preBuffer, postBuffer, flags);
}
if (errorCode != SocketError.Success)
{
SocketException socketException = new SocketException((int)errorCode);
UpdateStatusAfterSocketError(socketException);
if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
throw socketException;
}
// If the user passed the Disconnect and/or ReuseSocket flags, then TransmitFile disconnected the socket.
// Update our state to reflect this.
if ((flags & (TransmitFileOptions.Disconnect | TransmitFileOptions.ReuseSocket)) != 0)
{
SetToDisconnected();
_remoteEndPoint = null;
}
}