Esempio n. 1
0
        private void BeginRead(PipeHeaderData hd)
        {
            bool isConnected = hd.pipe.IsConnected;

            if (isConnected)
            {
                try
                {
                    hd.pipe.BeginRead(hd.data, 0, hd.data.Length, OnAsyncMessage, hd);
                }
                catch (Exception)
                {
                    isConnected = false;
                }
            }

            if (!isConnected)
            {
                hd.pipe.Close();
                m_handler.OnAsyncDisconnect(hd.pipe, hd.state);
                lock (m_pipes)
                {
                    bool removed = m_pipes.Remove(hd.pipe);
                }
            }
        }
Esempio n. 2
0
        private void OnAsyncMessage(IAsyncResult result)
        {
            PipeHeaderData hd        = (PipeHeaderData)result.AsyncState;
            Int32          bytesRead = hd.pipe.EndRead(result);

            if (bytesRead != 0)
            {
                m_handler.OnAsyncMessage(hd.pipe, hd.data, bytesRead, hd.state);
            }
            BeginRead(hd);
        }
Esempio n. 3
0
        private void OnClientConnected(IAsyncResult result)
        {
            NamedPipeServerStream pipe = (NamedPipeServerStream)result.AsyncState;

            pipe.EndWaitForConnection(result);

            PipeHeaderData hd = new PipeHeaderData();

            hd.state = null;
            hd.pipe  = pipe;
            hd.data  = new Byte[BUFFER_SIZE];

            bool running;

            lock (m_pipes)
            {
                running = m_running;
                if (running)
                {
                    m_pipes.Add(hd.pipe, hd);
                }
            }

            if (running)
            {
                PipeServerCreate();

                m_handler.OnAsyncConnect(pipe, out hd.state);

                BeginRead(hd);
            }
            else
            {
                pipe.Close();
            }
        }