TransmitFileOptions 列挙型

定義

TransmitFileOptions 列挙体は、ファイル転送要求で使用する値を定義します。

この列挙体は、メンバー値のビットごとの組み合わせをサポートしています。

public enum class TransmitFileOptions
[System.Flags]
public enum TransmitFileOptions
[<System.Flags>]
type TransmitFileOptions = 
Public Enum TransmitFileOptions
継承
TransmitFileOptions
属性

フィールド

Disconnect 1

すべてのファイル データが伝送キューに置かれた後で、トランスポート レベルの接続解除を開始します。 ReuseSocket で使用する場合、これらのフラグは、ファイルの送信後に、ソケットを接続解除された再利用可能な状態に戻します。

ReuseSocket 2

要求が完了すると、ソケット ハンドルは再利用できます。 このフラグは、同時に Disconnect も指定されている場合にだけ有効です。 Disconnect で使用する場合、これらのフラグは、ファイルの送信後に、ソケットを接続解除された再利用可能な状態に戻します。

UseDefaultWorkerThread 0

既定スレッドを使用して長いファイルの転送要求を処理します。

UseKernelApc 32

長いファイルの転送要求を処理するには、ワーカー スレッドの代わりに、カーネルの非同期プロシージャ呼び出し (APC: asynchronous procedure call) を使用します。 長い要求は、ファイルやキャッシュから複数回読み取りを行う必要がある要求として定義されます。したがって、この要求はファイルのサイズや送信パケットに指定した長さに依存します。

UseSystemThread 16

システム スレッドを使用して長いファイルの転送要求を処理します。

WriteBehind 4

ファイル転送要求を、保留せず、すぐに完了させます。 このフラグが指定されていてファイル転送も成功した場合、データはシステムによって受け入れられますが、リモート エンドによって応答されるとは限りません。 このフラグを、Disconnect フラグおよび ReuseSocket フラグと共に使用しないでください。

次の例では、 の呼び出しでの の TransmitFileOptions 使用を Socket.SendFile示します。 ファイル "test.txt" は、ローカル コンピューターのルート ディレクトリにあります。 この例では、データのプリバッファーとポストバッファーが作成され、ファイルを使用してリモート ホストに送信されます。 システムの既定のスレッドを使用するには、 UseDefaultWorkerThread を指定します。

// 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();

注釈

注意

フラグを設定 Disconnect し、 ReuseSocket ファイルが送信された後に、ソケットを切断された再利用可能な状態に戻します。 サービス プロバイダーは、ファイル転送が完了する前にソケットに関連付けられているサービスの品質を直ちに削除する可能性があるため、これらのフラグは、サービス品質 (QOS) が要求されたソケットでは使用しないでください。 QOS 対応ソケットの最適な方法は、これらのフラグに依存するのではなく、ファイル転送が完了したときに を呼び出 Socket.Close す方法です。

適用対象