/// <summary>
        /// Handle requests.
        /// </summary>
        public void HandleRequests()
        {
            File.Delete(socketName);

            serverSocket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);

            // Start listening on the Unix socket.
            //
            serverSocket.Bind(new UnixDomainSocketEndPoint(socketName));
            serverSocket.Listen(backlog: 1);

            // Signal the target process, the Agent is ready.
            //
            using NamedEvent namedEvent = NamedEvent.CreateOrOpen(semaphoreName);
            namedEvent.Signal();
            {
                // Accept the connection and obtain the list of the shared memory regions.
                //
                using Socket acceptedSocket = serverSocket.Accept();
                HandleAcceptedRequest(acceptedSocket);
            }

            Thread handlerThread = new Thread(
                start: () =>
            {
                while (!isDisposed)
                {
                    Socket socket = serverSocket;
                    if (socket == null)
                    {
                        // Stop processing the request after we disposed the socket.
                        //
                        break;
                    }

                    try
                    {
                        using Socket acceptedSocket = socket.Accept();
                        HandleAcceptedRequest(acceptedSocket);
                    }
                    catch (SocketException)
                    {
                        // Ignore the exception.
                        //
                    }
                    catch (ObjectDisposedException)
                    {
                        // Ignore the exception.
                        //
                    }
                }
            });

            handlerThread.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Uninitialize shared channel.
        /// </summary>
        public static void UninitializeSharedChannel()
        {
            // Signal named event to close any waiter threads.
            //
            controlChannelNamedEvent.Signal();
            feedbackChannelNamedEvent.Signal();

            // Close shared memory.
            //
            controlChannelMemoryMapView.Dispose();
            feedbackChannelMemoryMapView.Dispose();
            sharedConfigMemoryMapView.Dispose();

            KeepRunning = false;
        }