Adrian
Adrian

Reputation: 29

mono, unix sockets

Does anyone know an example of c# (mono) application that creates unix domain socket and listens to it async way?

Upvotes: 2

Views: 2610

Answers (2)

Mikhail Tatarkov
Mikhail Tatarkov

Reputation: 7

May be it approach for this question.

       var listeningPort = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);
        var endPoint = new UnixDomainSocketEndPoint(path);

        listeningPort.Bind(endPoint);

        listeningPort.Listen(0);

        while (true)
        {

            var socket = await listeningPort.AcceptAsync();

            var result = await socket.ReceiveAsync(transferBuffer, CancellationToken.None);
            //...
        }

Upvotes: 0

Gonzalo
Gonzalo

Reputation: 21175

Take a look at the method GracefulShutdown() in ModMonoWebSource.cs. After the point where the socket is created, it does not matter any more whether it was a unix domain socket or an IPv4 socket. Accepting connection asynchronously is done in Mono.WebServer/ folder, but I'll let you find out where and how.

Upvotes: 2

Related Questions