[Mono-dev] Win32 sockets regression on trunk.

Lucas Meijer lucas at lucasmeijer.com
Mon Feb 16 07:44:37 EST 2009


Hey.

While upgrading our mono to get all the latest bugfixes, I'm running into the following, which looks like a win32 socket regression.
When the program below is executed on mono trunk (r126917)
it outputs:

error on socket s
error on socket s2
available data on socket s
available data on socket s2

When run on a previous mono. (Mono2.0ish don't have the exact svn for this one, but around november 29, 2008), this program outputs:

available data on socket s2

Which seems to me like the correct output.

Reported as: https://bugzilla.novell.com/show_bug.cgi?id=476138

Here's the program. you need to make sure to actually have something listening on port 1234.


using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Net;

class Program
{
    static void Main(string[] args)
    {
        var s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        var ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5655);
        s.Blocking = false;
        s.Bind(ep);
        s.Listen(5);

        var s2 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        s2.Bind(new IPEndPoint(IPAddress.Any, 0));
        s2.Blocking = false;

        try
        {
            //You actally need to be running something on port 1234. 
            s2.Connect(IPAddress.Parse("127.0.0.1"), 1234); 
        }
        catch (SocketException se)
        {
            // ignore blocking connect exception. shouldn't there be some other way to do this...
            if (se.ErrorCode != 10035)
                throw se;
        }

        var errorList = new List<Socket>();
        var readList = new List<Socket>();
        var writeList = new List<Socket>();

        readList.Add(s);
        readList.Add(s2);
        errorList.Add(s);
        errorList.Add(s2);
        Socket.Select(readList, null, errorList, 100);

        if (errorList.Contains(s))
            Console.WriteLine("error on socket s");
        if (errorList.Contains(s2))
            Console.WriteLine("error on socket s2");
        if (readList.Contains(s))
            Console.WriteLine("available data on socket s");
        if (readList.Contains(s2))
            Console.WriteLine("available data on socket s2");
    }
}





-- Lucas Meijer | GameDev & Unity3D Consulting 
-- Blog: http://lucasmeijer.com/blog
-- twitter: lucasmeijer



More information about the Mono-devel-list mailing list