Socket.IOControl Socket.IOControl Socket.IOControl Socket.IOControl Method

定义

Socket 设置低级别操作模式。Sets low-level operating modes for the Socket.

重载

IOControl(IOControlCode, Byte[], Byte[]) IOControl(IOControlCode, Byte[], Byte[]) IOControl(IOControlCode, Byte[], Byte[])

使用 Socket 枚举指定控制代码,为 IOControlCode 设置低级操作模式。Sets low-level operating modes for the Socket using the IOControlCode enumeration to specify control codes.

IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[])

使用数字控制代码,为 Socket 设置低级操作模式。Sets low-level operating modes for the Socket using numerical control codes.

IOControl(IOControlCode, Byte[], Byte[]) IOControl(IOControlCode, Byte[], Byte[]) IOControl(IOControlCode, Byte[], Byte[])

使用 Socket 枚举指定控制代码,为 IOControlCode 设置低级操作模式。Sets low-level operating modes for the Socket using the IOControlCode enumeration to specify control codes.

public:
 int IOControl(System::Net::Sockets::IOControlCode ioControlCode, cli::array <System::Byte> ^ optionInValue, cli::array <System::Byte> ^ optionOutValue);
public int IOControl (System.Net.Sockets.IOControlCode ioControlCode, byte[] optionInValue, byte[] optionOutValue);
member this.IOControl : System.Net.Sockets.IOControlCode * byte[] * byte[] -> int

参数

ioControlCode
IOControlCode IOControlCode IOControlCode IOControlCode

一个 IOControlCode 值,它指定要执行的操作的控制代码。A IOControlCode value that specifies the control code of the operation to perform.

optionInValue
Byte[]

Byte 类型的数组,包含操作要求的输入数据。An array of type Byte that contains the input data required by the operation.

optionOutValue
Byte[]

Byte 类型的数组,包含由操作返回的输出数据。An array of type Byte that contains the output data returned by the operation.

返回

optionOutValue 参数中的字节数。The number of bytes in the optionOutValue parameter.

异常

尝试访问套接字时出错。An error occurred when attempting to access the socket.

尝试不使用 Blocking 属性更改阻止模式。An attempt was made to change the blocking mode without using the Blocking property.

示例

下面的代码示例将调用的结果进行比较IOControlDataToReadAvailable属性。The following code example compares the results of calling IOControl with DataToRead and the Available property.

void DisplayPendingByteCount( Socket^ s )
{
   array<Byte>^ outValue = BitConverter::GetBytes( 0 );
   
   // Check how many bytes have been received.
   s->IOControl( IOControlCode::DataToRead, nullptr, outValue );

   UInt32 bytesAvailable = BitConverter::ToUInt32( outValue, 0 );
   Console::Write( "server has {0} bytes pending,",
      bytesAvailable );
   Console::WriteLine( "Available property says {1}.",
      s->Available );
   return;
}
static void DisplayPendingByteCount(Socket s)
{
    byte[] outValue = BitConverter.GetBytes(0);

    // Check how many bytes have been received.
    s.IOControl(IOControlCode.DataToRead, null, outValue);

    uint bytesAvailable = BitConverter.ToUInt32(outValue, 0);
    Console.Write("server has {0} bytes pending. ", 
        bytesAvailable);
    Console.WriteLine("Available property says {1}.",
                     s.Available);

    return;
}

注解

此方法提供对操作系统的低级别访问权限Socket基础的当前实例Socket类。This method provides low-level access to the operating system Socket underlying the current instance of the Socket class. 有关详细信息,请参阅WSAIoctl文档。For more, see the WSAIoctl documentation.

备注

如果你收到SocketException,使用SocketException.ErrorCode属性来获取特定错误代码。If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. 获取此代码后,请参阅Windows 套接字版本 2 API 错误代码有关错误的详细说明的文档。After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅在.NET Framework 中进行网络跟踪For more information, see Network Tracing in the .NET Framework.

安全性

SecurityPermission
若要执行非托管的代码。to execute unmanaged code. 关联枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode.

IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[]) IOControl(Int32, Byte[], Byte[])

使用数字控制代码,为 Socket 设置低级操作模式。Sets low-level operating modes for the Socket using numerical control codes.

public:
 int IOControl(int ioControlCode, cli::array <System::Byte> ^ optionInValue, cli::array <System::Byte> ^ optionOutValue);
public int IOControl (int ioControlCode, byte[] optionInValue, byte[] optionOutValue);
member this.IOControl : int * byte[] * byte[] -> int
Public Function IOControl (ioControlCode As Integer, optionInValue As Byte(), optionOutValue As Byte()) As Integer

参数

ioControlCode
Int32 Int32 Int32 Int32

一个 Int32 值,该值指定要执行的操作的控制代码。An Int32 value that specifies the control code of the operation to perform.

optionInValue
Byte[]

一个 Byte 数组,它包含操作需要的输入数据。A Byte array that contains the input data required by the operation.

optionOutValue
Byte[]

一个 Byte 数组,它包含操作返回的输出数据。A Byte array that contains the output data returned by the operation.

返回

optionOutValue 参数中的字节数。The number of bytes in the optionOutValue parameter.

异常

尝试访问套接字时出错。An error occurred when attempting to access the socket.

尝试不使用 Blocking 属性更改阻止模式。An attempt was made to change the blocking mode without using the Blocking property.

调用堆栈中的调用方没有所需的权限。A caller in the call stack does not have the required permissions.

示例

下面的代码示例将 FIONREAD 和可用属性的结果进行比较。The following code example compares the results of FIONREAD and the Available property.

// FIONREAD is also available as the "Available" property.
const int FIONREAD = 0x4004667F;

void DisplayPendingByteCount( Socket^ s )
{
   array<Byte>^ outValue = BitConverter::GetBytes( 0 );
   
   // Check how many bytes have been received.
   s->IOControl( FIONREAD, nullptr, outValue );

   UInt32 bytesAvailable = BitConverter::ToUInt32( outValue, 0 );
   Console::WriteLine( "server has {0} bytes pending. Available property says {1}.",
      bytesAvailable, s->Available );

   return;
}
 // FIONREAD is also available as the "Available" property.
public const int FIONREAD   = 0x4004667F;

static void DisplayPendingByteCount(Socket s)
 {
     byte[] outValue = BitConverter.GetBytes(0);

     // Check how many bytes have been received.
     s.IOControl(FIONREAD, null, outValue);
     
     uint bytesAvailable = BitConverter.ToUInt32(outValue, 0);
     Console.WriteLine("server has {0} bytes pending. Available property says {1}.",
         bytesAvailable, s.Available);
     
     return;
 }

注解

IOControl方法提供对操作系统的低级别访问权限Socket基础的当前实例Socket类。The IOControl method provides low-level access to the operating system Socket underlying the current instance of the Socket class. 有关详细信息,请参阅WSAIoctl文档。For more information, see the WSAIoctl documentation.

备注

如果你收到SocketException,使用SocketException.ErrorCode属性来获取特定错误代码。If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. 获取此代码后,请参阅Windows 套接字版本 2 API 错误代码有关错误的详细说明的文档。After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.

备注

当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅在.NET Framework 中进行网络跟踪For more information, see Network Tracing in the .NET Framework.

安全性

SecurityPermission
若要执行非托管的代码。to execute unmanaged code. 关联枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode.

适用于