本文整理汇总了C#中TransmitFileOptions类的典型用法代码示例。如果您正苦于以下问题:C# TransmitFileOptions类的具体用法?C# TransmitFileOptions怎么用?C# TransmitFileOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransmitFileOptions类属于命名空间,在下文中一共展示了TransmitFileOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TransmitFile
internal static extern unsafe bool TransmitFile(
SafeHandle socket,
SafeHandle fileHandle,
int numberOfBytesToWrite,
int numberOfBytesPerSend,
SafeHandle overlapped,
TransmitFileBuffers* buffers,
TransmitFileOptions flags);
开发者ID:chcosta,项目名称:corefx,代码行数:8,代码来源:Interop.TransmitFile.cs
示例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);
}
}
开发者ID:chcosta,项目名称:corefx,代码行数:9,代码来源:Socket.Unix.cs
示例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);
}
开发者ID:chcosta,项目名称:corefx,代码行数:9,代码来源:SocketAPMExtensions.cs
示例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);
}
}
开发者ID:chcosta,项目名称:corefx,代码行数:41,代码来源:Socket.Unix.cs
示例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 ();
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:9,代码来源:Socket.cs
示例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;
}
}
开发者ID:Profit0004,项目名称:mono,代码行数:16,代码来源:Socket.cs
示例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));
}
开发者ID:frje,项目名称:SharpLang,代码行数:22,代码来源:Socket.cs
示例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);
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:_TransmitFileOverlappedAsyncResult.cs
示例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);
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:93,代码来源:Socket.cs
示例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;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:78,代码来源:Socket.cs
示例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();
}
开发者ID:Gohla,项目名称:ReactiveIRC,代码行数:14,代码来源:SocketExtensions+-+Send.cs
示例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);
}
开发者ID:peteraritchie,项目名称:ProductivityExtensions,代码行数:12,代码来源:Socketable.g.cs
示例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;
}
开发者ID:chcosta,项目名称:corefx,代码行数:22,代码来源:Socket.Windows.cs
示例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;
}
}
开发者ID:chcosta,项目名称:corefx,代码行数:30,代码来源:Socket.Windows.cs
示例16: SendFileAsync
public static unsafe SocketError SendFileAsync(SafeCloseSocket handle, FileStream fileStream, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags, TransmitFileAsyncResult asyncResult)
{
asyncResult.SetUnmanagedStructures(fileStream, preBuffer, postBuffer, (flags & (TransmitFileOptions.Disconnect | TransmitFileOptions.ReuseSocket)) != 0);
SocketError errorCode = TransmitFileHelper(handle, fileStream?.SafeFileHandle, asyncResult.OverlappedHandle, preBuffer, postBuffer, flags);
// This will release resources if necessary
errorCode = asyncResult.CheckAsyncCallOverlappedResult(errorCode);
return errorCode;
}
开发者ID:chcosta,项目名称:corefx,代码行数:11,代码来源:SocketPal.Windows.cs
示例17: SendPackets
private void SendPackets(SocketImplementationType type, SendPacketsElement element, TransmitFileOptions flags, int bytesExpected)
{
Assert.True(Capability.IPv6Support());
EventWaitHandle completed = new ManualResetEvent(false);
int port;
using (SocketTestServer.SocketTestServerFactory(type, _serverAddress, out port))
{
using (Socket sock = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp))
{
sock.Connect(new IPEndPoint(_serverAddress, port));
using (SocketAsyncEventArgs args = new SocketAsyncEventArgs())
{
args.Completed += OnCompleted;
args.UserToken = completed;
args.SendPacketsElements = new[] { element };
args.SendPacketsFlags = flags;
if (sock.SendPacketsAsync(args))
{
Assert.True(completed.WaitOne(TestSettings.PassingTestTimeout), "Timed out");
}
Assert.Equal(SocketError.Success, args.SocketError);
Assert.Equal(bytesExpected, args.BytesTransferred);
}
switch (flags)
{
case TransmitFileOptions.Disconnect:
// Sending data again throws with socket shut down error.
Assert.Throws<SocketException>(() => { sock.Send(new byte[1] { 01 }); });
break;
case TransmitFileOptions.ReuseSocket & TransmitFileOptions.Disconnect:
// Able to send data again with reuse socket flag set.
Assert.Equal(1, sock.Send(new byte[1] { 01 }));
break;
}
}
}
}
开发者ID:chcosta,项目名称:corefx,代码行数:41,代码来源:SendPacketsAsync.cs
示例18: SendFile
private static bool SendFile (IntPtr sock, string filename, byte [] pre_buffer, byte [] post_buffer, TransmitFileOptions flags)
{
throw new System.NotImplementedException();
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:4,代码来源:Socket.Mosa.cs
示例19: BeginSendFile
public IAsyncResult BeginSendFile(
string fileName,
byte[] preBuffer,
byte[] postBuffer,
TransmitFileOptions flags,
AsyncCallback callback,
object state)
{
// Start the context flowing. No lock necessary.
TransmitFileOverlappedAsyncResult asyncResult = new TransmitFileOverlappedAsyncResult(this,state,callback);
asyncResult.StartPostingAsyncOp(false);
// Start the operation.
DoBeginSendFile(fileName, preBuffer, postBuffer, flags, asyncResult);
// Finish the op, collect the context or maybe call the callback.
asyncResult.FinishPostingAsyncOp(ref Caches.SendClosureCache);
return asyncResult;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:20,代码来源:Socket.cs
示例20: BeginSendFile
public IAsyncResult BeginSendFile(string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags, AsyncCallback callback, object state)
{
TransmitFileOverlappedAsyncResult asyncResult = new TransmitFileOverlappedAsyncResult(this, state, callback);
asyncResult.StartPostingAsyncOp(false);
this.DoBeginSendFile(fileName, preBuffer, postBuffer, flags, asyncResult);
asyncResult.FinishPostingAsyncOp(ref this.Caches.SendClosureCache);
return (IAsyncResult) asyncResult;
}
开发者ID:korifey,项目名称:hackathon-Ideaphone,代码行数:8,代码来源:Socket.cs
注:本文中的TransmitFileOptions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论