Azure / DotNetty

DotNetty project – a port of netty, event-driven asynchronous network application framework
Other
4.09k stars 977 forks source link

TcpSocketChannel.DoConnect returning true stops channel active being fired #223

Open andreasdamm opened 7 years ago

andreasdamm commented 7 years ago

When using UnixEndPoint under Mono on Linux, TcpSocketChannel never becomes active after a call to connect. The reason appears to be that the connection succeeds immediately, on DoConnect returns false.

When creating a subclass (see attached code) which always returns false, then all is well. Also, when TcpSocketChannel tries to create a Socket, it always provides ProtocolType.IPv6. For unix domain sockets that needs to be ProtocolType.Unspecified otherwise an exception is thrown.

using System.Net;
using System.Net.Sockets;
using DotNetty.Transport.Channels.Sockets;

namespace agentx
{
    internal class UnixSocketChannel : TcpSocketChannel
    {
        public UnixSocketChannel()
            : base(new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
        {
        }

        protected override bool DoConnect(EndPoint remoteAddress, EndPoint localAddress)
        {
            base.DoConnect(remoteAddress, localAddress);

            // channel never fires active event if indicates that connected already
            return false;
        }
    }
}
Aaronontheweb commented 7 years ago

@andreasdamm is there any attached code for this still?

andreasdamm commented 7 years ago

Just what is in the issue description. To reproduce the error, use the UnixSocketChannel class and instead of "return false" in DoConnect, return the value of "base.DoConnect(...)".

Also, the original descriotion should have said that the connection succeeds immediately, and DoConnect returns true.