SelectMode 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 Poll(Int32, SelectMode) 方法定义轮询模式。
public enum class SelectMode
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." );
}
//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 该方法。