SelectMode 枚举
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 Poll(Int32, SelectMode) 方法定义轮询模式。
public enum class SelectMode
C#
public enum SelectMode
type SelectMode =
Public Enum SelectMode
- 继承
名称 | 值 | 说明 |
---|---|---|
SelectError | 2 | 错误状态模式。 |
SelectRead | 0 | 读状态模式。 |
SelectWrite | 1 | 写状态模式。 |
以下示例使用所有三SelectMode个枚举值检查 的状态Socket。 使用 SelectWrite 枚举值的调用 Socket.Poll 应返回 true
。
//Creates the Socket for sending data over TCP.
Socket^ s = gcnew Socket( AddressFamily::InterNetwork, SocketType::Stream,
ProtocolType::Tcp );
// Connects to host using IPEndPoint.
s->Connect( EPhost );
if ( !s->Connected )
{
strRetPage = "Unable to connect to host";
}
// Use the SelectWrite enumeration to obtain Socket status.
if ( s->Poll( -1, SelectMode::SelectWrite ) )
{
Console::WriteLine( "This Socket is writable." );
}
else if ( s->Poll( -1, SelectMode::SelectRead ) )
{
Console::WriteLine( "This Socket is readable." );
}
else if ( s->Poll( -1, SelectMode::SelectError ) )
{
Console::WriteLine( "This Socket has an error." );
}
C#
//Creates the Socket for sending data over TCP.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );
// Connects to host using IPEndPoint.
s.Connect(EPhost);
if (!s.Connected)
{
strRetPage = "Unable to connect to host";
}
// Use the SelectWrite enumeration to obtain Socket status.
if(s.Poll(-1, SelectMode.SelectWrite)){
Console.WriteLine("This Socket is writable.");
}
else if (s.Poll(-1, SelectMode.SelectRead)){
Console.WriteLine("This Socket is readable." );
}
else if (s.Poll(-1, SelectMode.SelectError)){
Console.WriteLine("This Socket has an error.");
}
'Creates the Socket for sending data over TCP.
Dim s As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' Connects to host using IPEndPoint.
s.Connect(EPhost)
If Not s.Connected Then
strRetPage = "Unable to connect to host"
End If
' Use the SelectWrite enumeration to obtain Socket status.
If s.Poll(- 1, SelectMode.SelectWrite) Then
Console.WriteLine("This Socket is writable.")
Else
If s.Poll(- 1, SelectMode.SelectRead) Then
Console.WriteLine(("This Socket is readable. "))
Else
If s.Poll(- 1, SelectMode.SelectError) Then
Console.WriteLine("This Socket has an error.")
End If
End If
End If
SelectMode枚举定义可传递给 方法的Socket.Poll轮询模式。 使用 SelectRead 值确定侦 Socket 听是否有传入的连接请求。 使用 SelectWrite 值确定 是否 Socket 可写。 使用 SelectError 值确定 上 Socket是否存在错误条件。 有关可写性、可读性和是否存在错误条件的说明,请参阅 Socket.Poll 方法。
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.3, 1.4, 1.6, 2.0, 2.1 |