2

SMTPメールサーバー( LumiSoft Mail Server )のコードで次のコードを見つけました。メソッドの名前に従って、プラットフォームがI/O完了ポートをサポートしているかどうかをテストします。

/// <summary>
/// Gets if IO completion ports supported by OS.
/// </summary>
/// <returns></returns>
public static bool IsIoCompletionPortsSupported()
{
    Socket s = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp);
    try{                            
        SocketAsyncEventArgs e = new SocketAsyncEventArgs();
        e.SetBuffer(new byte[0],0,0);
        e.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback,111);
        s.SendToAsync(e)

        return true;
    }

    catch(NotSupportedException nX){
        string dummy = nX.Message;
        return false;
    }
    finally{
        s.Close();
    }
}

正常に動作しているように見えますが、Mono/Linuxでは失敗します。このメソッドSendToAsyncは、その名前が示すように、非同期で実行されます。別のスレッドでも実行されます。ただし、実行を開始すると、このメソッドの最後の部分ですでにソケットが閉じObjectDisposedExceptionられ、他のスレッドでが発生します。

それで、IOCPサポートをテストするための間違ったテクニックはありますか?なぜWindowsで動作するのですか?IOCPサポートをテストする適切な方法は何ですか?

4

1 に答える 1

2

The test simply determines if an async operation results in a NotSupportedException or not. The test code doesn't care about the async operation completing it simply cares if it throws an exception when called.

The person who wrote the test probably assumes that async operations imply IOCP support and that this test should really be named "IsAsyncOperationSupported()".

I imagine that mono/linux doesn't support async operations everywhere due to the lack of IOCP support and the person who wrote the test knows this...

于 2010-11-22T09:44:52.763 に答える