mono | Blog | Limilabs https://www.limilabs.com/blog Using Limilabs .net components Thu, 08 Sep 2016 21:01:03 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 A non-blocking socket operation could not be completed https://www.limilabs.com/blog/a-non-blocking-socket-operation https://www.limilabs.com/blog/a-non-blocking-socket-operation#comments Mon, 12 Apr 2010 16:03:29 +0000 http://www.limilabs.com/blog/?p=809 There is a bug in .NET 2.0 regarding timeout handling by Socket class. Here’s the code that reproduces this behavior. The above code runs as expected on Mono and on .NET 4.0. The problem is in UpdateStatusAfterSocketError internal Socket method that executes SetToDisconnected method when any exception is thrown, including timeout exception.

The post A non-blocking socket operation could not be completed first appeared on Blog | Limilabs.

]]>
There is a bug in .NET 2.0 regarding timeout handling by Socket class.
Here’s the code that reproduces this behavior.

using(TcpClient client = new TcpClient())
{
    // Set timeout
    client.ReceiveTimeout =
        (int)TimeSpan.FromSeconds(1).TotalMilliseconds;

    // Connect to perfectly working imap server
    client.Connect("mail.limilabs.com", 143);

    // Create reader and writer
    NetworkStream stream = client.GetStream();
    StreamReader reader = new StreamReader(stream);
    StreamWriter writer = new StreamWriter(stream);

    // Read hello line
    Console.WriteLine(reader.ReadLine());

    // this works with no problems
    writer.WriteLine("a NOOP");             // No operation command
    writer.Flush();
    Console.WriteLine(reader.ReadLine());   // No operation response

    try
    {
        reader.ReadLine();                  // Nothing to read
    }
    catch (Exception ex)                    // Timeout
    {
        Console.WriteLine("timeout");       // This is expected
    }

    writer.WriteLine("b NOOP");             // No operation command
    writer.Flush();

    // SocketException: A non-blocking socket operation
    // could not be completed immediately
    Console.WriteLine(reader.ReadLine());

    client.Close();
}

The above code runs as expected on Mono and on .NET 4.0.

The problem is in UpdateStatusAfterSocketError internal Socket method that executes SetToDisconnected method when any exception is thrown, including timeout exception.

The post A non-blocking socket operation could not be completed first appeared on Blog | Limilabs.

]]>
https://www.limilabs.com/blog/a-non-blocking-socket-operation/feed 2
Regex bug on Mono https://www.limilabs.com/blog/regex-bug-on-mono Sun, 06 Dec 2009 12:36:19 +0000 http://www.limilabs.com/blog/?p=345 This is a good advice for all creating applications using .NET that need to work on both Microsoft .NET and Mono. It seems that Mono ignores group indexes specified explicitly. Here’s the code to reproduce this problem. The results on Mono are incorrect. Regex parser = new Regex("(?<2>.*?),(?<1>.*?),"); Match match = parser.Match("first,second,"); Console.WriteLine("Groups[1].Value={0}", match.Groups[1].Value); Console.WriteLine("Groups[2].Value={0}", […]

The post Regex bug on Mono first appeared on Blog | Limilabs.

]]>
monoThis is a good advice for all creating applications using .NET that need to work on both Microsoft .NET and Mono.

It seems that Mono ignores group indexes specified explicitly.
Here’s the code to reproduce this problem.

The results on Mono are incorrect.

Regex parser = new Regex("(?<2>.*?),(?<1>.*?),");
Match match = parser.Match("first,second,");
Console.WriteLine("Groups[1].Value={0}", match.Groups[1].Value);
Console.WriteLine("Groups[2].Value={0}", match.Groups[2].Value);

MS implementation:

C:\1\ConsoleApplication\1\bin\Debug>ConsoleApplication1.exe
Groups[1].Value=second
Groups[2].Value=first

Mono 2.4.2.3 implementation:

C:\1\ConsoleApplication\1\bin\Debug>mono.exe ConsoleApplication1.exe
Groups[1].Value=first
Groups[2].Value=second

The workaround is simple use names instead of numbers:

Regex parser = new Regex("(?<first>.*?),(?<second>.*?),");
Match match = parser.Match("first,second,");
Console.WriteLine("Groups[first].Value={0}", match.Groups["first"].Value);
Console.WriteLine("Groups[second].Value={0}", match.Groups["second"].Value);

The post Regex bug on Mono first appeared on Blog | Limilabs.

]]>