Example #1
0
        public Task SendResponseAsync(ILpReceiver handler, byte[] data)
        {
            if (data == null)
            {
                data = new byte[0];
            }

            return(Task.Run(() =>
            {
                if (!_pipe_recvs.Values.Contains(handler))
                {
                    return;
                }

                var pipe = _pipe_recvs.FirstOrDefault(h => h.Value == handler).Key;
                var sendBuffer = new byte[data.Length + 2];
                sendBuffer[0] = (byte)(pipe & 0xff);
                sendBuffer[1] = (byte)(pipe >> 8);
                Array.Copy(data, 0, sendBuffer, 2, data.Length);

                lock (_transport)
                {
                    _transport.SendMessageAsync(sendBuffer).Wait();
                }
            }));
        }
Example #2
0
        /// <summary>
        /// Создание нового пайпа с присвоением ему номера
        /// </summary>
        /// <param name="pipeHandler"></param>
        /// <returns></returns>
        public ushort CreatePipe(ILpReceiver pipeHandler)
        {
            lock (this)
            {
                ushort pipe = FindFreeNumber();
                if (pipe == 0)
                {
                    return(0);           // нет свободного номера
                }
                _pipe_recvs.Add(pipe, pipeHandler);

                return(pipe);
            }
        }