TransmitFileOptions Enumerazione

Definizione

L'enumerazione TransmitFileOptions definisce i valori utilizzati nelle richieste di trasferimento dei file.

Questa enumerazione supporta una combinazione bit per bit dei rispettivi valori dei membri.

public enum class TransmitFileOptions
[System.Flags]
public enum TransmitFileOptions
[<System.Flags>]
type TransmitFileOptions = 
Public Enum TransmitFileOptions
Ereditarietà
TransmitFileOptions
Attributi

Campi

Disconnect 1

Avviare una disconnessione a livello di trasporto dopo che tutti i dati dei file sono stati accodati per la trasmissione. Se utilizzati con ReuseSocket, i flag riportano il socket a uno stato disconnesso consentendone il riutilizzo.

ReuseSocket 2

L'handle del socket può essere riutilizzato una volta completata la richiesta. Questo flag è valido solo se viene specificato anche Disconnect. Se utilizzati con Disconnect, i flag riportano il socket a uno stato disconnesso consentendone il riutilizzo.

UseDefaultWorkerThread 0

Utilizzare il thread predefinito per elaborare richieste di trasferimento di file di lunga durata.

UseKernelApc 32

Utilizzare chiamate asincrone di procedura del kernel anziché thread di lavoro per elaborare richieste di trasferimento dei file di lunga durata. Vengono definite richieste di lunga durata le richieste per le quali sono necessarie più letture del file o della cache. La richiesta dipende pertanto dalle dimensioni del file e dalla lunghezza del pacchetto di invio specificata.

UseSystemThread 16

Utilizzare thread di sistema per elaborare richieste di trasferimento dei file di lunga durata.

WriteBehind 4

Completare immediatamente la richiesta di trasferimento dei file, senza sospensioni. Se viene specificato questo flag e il trasferimento dei file viene completato correttamente, i dati sono stati accettati dal sistema ma potrebbero non essere stati riconosciuti dal punto finale remoto. Non utilizzare questo flag con i flag Disconnect e ReuseSocket.

Esempio

Nell'esempio seguente viene illustrato l'uso di TransmitFileOptions in una chiamata a Socket.SendFile. Il file "test.txt" si trova nella directory radice del computer locale. In questo esempio viene creata una prebuffer e postbuffer di dati e viene inviata all'host remoto con il file. Per usare il thread predefinito del sistema, UseDefaultWorkerThread viene specificato.

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

Commenti

Nota

I flag Disconnect e restituiscono il socket a uno stato disconnesso, ReuseSocket riutilizzabile dopo la trasmissione del file. Questi flag non devono essere usati in un socket in cui è stata richiesta la qualità del servizio (QOS), perché il provider di servizi potrebbe eliminare immediatamente qualsiasi qualità del servizio associato al socket prima del completamento del trasferimento del file. L'approccio migliore per un socket abilitato per QOS consiste nel chiamare Socket.Close quando il trasferimento del file è stato completato, anziché basarsi su questi flag.

Si applica a