Skip to content

Socket.Select() method doesn't work as expected on macOS #920

@earlbread

Description

@earlbread

On macOS, Socket.Select method doesn't work as expected. In .NET Framework, it works as expected.

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

namespace SelectTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Socket receiver = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Unspecified);
            Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Unspecified);

            receiver.Bind(new IPEndPoint(IPAddress.Loopback, 0));
            receiver.Listen(1);
            sender.Connect(receiver.LocalEndPoint);
            receiver = receiver.Accept();

            sender.Send(new byte[] { 1 });

            var readList = new List<Socket> { receiver };
            var errorList = new List<Socket> { receiver };

            Socket.Select(readList, null, errorList, -1);
            Console.WriteLine($"readList Count: {readList.Count}");
            Console.WriteLine($"errorList Count: {errorList.Count}");
        }
    }
}

Expected result:

The following output is written to stdout:

readList Count: 1
errorList Count: 0

Actual result:

The following output is written to stdout:

readList Count: 0
errorList Count: 0

Dotnet Info

.NET Core SDK (reflecting any global.json):
 Version:   2.2.105
 Commit:    7cecb35b92

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.2.105/

Host (useful for support):
  Version: 2.2.3
  Commit:  6b8ad509b6

.NET Core SDKs installed:
  2.2.105 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Metadata

Metadata

Assignees

Labels

area-System.Net.Socketsbugin-prThere is an active PR which will close this issue when it is mergedos-mac-os-xmacOS aka OSXtenet-compatibilityIncompatibility with previous versions or .NET Framework

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions