TransmitFileOptions TransmitFileOptions TransmitFileOptions TransmitFileOptions Enum

定义

TransmitFileOptions 枚举定义文件传输请求中使用的值。The TransmitFileOptions enumeration defines values used in file transfer requests.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class TransmitFileOptions
[System.Flags]
public enum TransmitFileOptions
type TransmitFileOptions = 
Public Enum TransmitFileOptions
继承
TransmitFileOptionsTransmitFileOptionsTransmitFileOptionsTransmitFileOptions
属性

字段

Disconnect Disconnect Disconnect Disconnect 1

所有要传输的数据文件完成排队后,启动传输层断开连接。Start a transport-level disconnect after all the file data has been queued for transmission. 如果与 ReuseSocket 一起使用,这些标志将在完成文件传输后使套接字返回到断开连接的可重用状态。When used with ReuseSocket, these flags return the socket to a disconnected, reusable state after the file has been transmitted.

ReuseSocket ReuseSocket ReuseSocket ReuseSocket 2

完成请求后,可以重用套接字句柄。The socket handle may be reused when the request completes. 此标志仅在同时指定了 Disconnect 时才有效。This flag is valid only if Disconnect is also specified. 如果与 Disconnect 一起使用,这些标志将在完成文件传输后使套接字返回到断开连接的可重用状态。When used with Disconnect, these flags return the socket to a disconnected, reusable state after the file has been transmitted.

UseDefaultWorkerThread UseDefaultWorkerThread UseDefaultWorkerThread UseDefaultWorkerThread 0

使用默认线程处理长文件传输请求。Use the default thread to process long file transfer requests.

UseKernelApc UseKernelApc UseKernelApc UseKernelApc 32

使用内核异步过程调用 (APC) 而不是辅助线程来处理长文件传输请求。Use kernel asynchronous procedure calls (APCs) instead of worker threads to process long file transfer requests. 长请求定义为要求从文件或缓存中进行多次读取的请求,因此请求取决于文件的大小和发送数据包的指定长度。Long requests are defined as requests that require more than a single read from the file or a cache; the request therefore depends on the size of the file and the specified length of the send packet.

UseSystemThread UseSystemThread UseSystemThread UseSystemThread 16

使用系统线程处理长文件传输请求。Use system threads to process long file transfer requests.

WriteBehind WriteBehind WriteBehind WriteBehind 4

立即完成文件传输请求,而不挂起。Complete the file transfer request immediately, without pending. 如果指定了此标志并且文件传输成功,则表明系统已接受数据,但远端并不一定识别该数据。If this flag is specified and the file transfer succeeds, the data has been accepted by the system but not necessarily acknowledged by the remote end. 请勿将此标志与 DisconnectReuseSocket 标志一起使用。Do not use this flag with the Disconnect and ReuseSocket flags.

示例

下面的示例演示如何TransmitFileOptionsSocket.SendFile调用中使用。The following example demonstrates the use of TransmitFileOptions in a call to Socket.SendFile. 文件 "test.txt" 位于本地计算机的根目录中。The file "test.txt" is located in the root directory of the local machine. 在此示例中, 将创建 prebuffer 和以增大 postbuffer 数据, 并使用该文件将其发送到远程主机。In this example, a prebuffer and postbuffer of data are created and sent to the remote host with the file. 若要使用系统的默认线程, UseDefaultWorkerThread请指定。To use the system's default thread, UseDefaultWorkerThread is specified.

// Establish the local endpoint for the socket.
IPHostEntry^ ipHost = Dns::GetHostEntry( Dns::GetHostName() );
IPAddress^ ipAddr = ipHost->AddressList[ 0 ];
IPEndPoint^ ipEndPoint = gcnew IPEndPoint( ipAddr,11000 );

// Create a TCP socket.
Socket^ client = gcnew Socket( AddressFamily::InterNetwork,SocketType::Stream,ProtocolType::Tcp );

// Connect the socket to the remote endpoint.
client->Connect( ipEndPoint );

// Send file fileName to the remote host with preBuffer and postBuffer data.
// There is a text file test.txt located in the root directory.
String^ fileName = "C:\\test.txt";

// Create the preBuffer data.
String^ string1 = String::Format( "This is text data that precedes the file.{0}", Environment::NewLine );
array<Byte>^preBuf = Encoding::ASCII->GetBytes( string1 );

// Create the postBuffer data.
String^ string2 = String::Format( "This is text data that will follow the file.{0}", Environment::NewLine );
array<Byte>^postBuf = Encoding::ASCII->GetBytes( string2 );

//Send file fileName with buffers and default flags to the remote device.
Console::WriteLine( "Sending {0} with buffers to the host.{1}", fileName, Environment::NewLine );
client->SendFile( fileName, preBuf, postBuf, TransmitFileOptions::UseDefaultWorkerThread );

// Release the socket.
client->Shutdown( SocketShutdown::Both );
client->Close();
     // Establish the local endpoint for the socket.
     IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
     IPAddress  ipAddr = ipHost.AddressList[0];
     IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11000);

     // Create a TCP socket.
     Socket client = new Socket(AddressFamily.InterNetwork,
             SocketType.Stream, ProtocolType.Tcp);

     // Connect the socket to the remote endpoint.
     client.Connect(ipEndPoint);

     // Send file fileName to the remote host with preBuffer and postBuffer data.
     // There is a text file test.txt located in the root directory.
     string fileName = "C:\\test.txt";

     // Create the preBuffer data.
     string string1 = String.Format("This is text data that precedes the file.{0}", Environment.NewLine);
     byte[] preBuf = Encoding.ASCII.GetBytes(string1);

     // Create the postBuffer data.
     string string2 = String.Format("This is text data that will follow the file.{0}", Environment.NewLine);
     byte[] postBuf = Encoding.ASCII.GetBytes(string2);

     //Send file fileName with buffers and default flags to the remote device.
     Console.WriteLine("Sending {0} with buffers to the host.{1}", fileName, Environment.NewLine);
     client.SendFile(fileName, preBuf, postBuf, TransmitFileOptions.UseDefaultWorkerThread);

     // Release the socket.
     client.Shutdown(SocketShutdown.Both);
     client.Close();

注解

备注

标志DisconnectReuseSocket在传输文件后将套接字返回到断开连接的可重用状态。The flags Disconnect and ReuseSocket return the socket to a disconnected, reusable state after the file has been transmitted. 不应在请求服务质量 (QOS) 的套接字上使用这些标志, 因为在文件传输完成之前, 服务提供商可能会立即删除与套接字关联的任何服务质量。These flags should not be used on a socket where quality of service (QOS) has been requested, because the service provider might immediately delete any quality of service associated with the socket before the file transfer has completed. 启用 QOS 的套接字的最佳方式是在文件传输Socket.Close完成后调用, 而不是依赖这些标志。The best approach for a QOS-enabled socket is to call Socket.Close when the file transfer has completed, rather than relying on these flags.

适用于