/// <summary>
        /// Initializes a new instance of the <see cref="NamedPipeCommunicationChannel" /> class.
        /// </summary>
        /// <param name="endPoint">The end point.</param>
        /// <param name="pipeStream">An existing pipe stream or <c>null</c> to create client.</param>
        public NamedPipeCommunicationChannel(NamedPipeEndPoint endPoint, PipeStream pipeStream = null)
        {
            _endPoint = endPoint;

            if (pipeStream != null) _pipeStream = pipeStream;
            else
            {
                var client = new NamedPipeClientStream(".", endPoint.Name, PipeDirection.InOut, PipeOptions.Asynchronous | PipeOptions.WriteThrough);

                // connect overload with timeout is extremely processor intensive
                int elapsed = 0, connectionTimeout = endPoint.ConnectionTimeout * 1000;

            CONNECT:
                try
                {
                    client.Connect(0);
                }
                catch (TimeoutException)
                {
                    Thread.Sleep(CONNECT_ATTEMPT_INTERVAL_MS);

                    if (endPoint.ConnectionTimeout != Timeout.Infinite && (elapsed += CONNECT_ATTEMPT_INTERVAL_MS) > connectionTimeout)
                        throw new TimeoutException("The host failed to connect. Timeout occurred.");

                    goto CONNECT;
                }

                _pipeStream = client;
            }

            _buffer = new byte[ReceiveBufferSize];
            _syncLock = new object();
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedPipeClient"/> class.
 /// </summary>
 /// <param name="endPoint">The end point.</param>
 public NamedPipeClient(NamedPipeEndPoint endPoint)
 {
     _endPoint = endPoint;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedPipeConnectionListener"/> class.
 /// </summary>
 /// <param name="endPoint">The end point.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public NamedPipeConnectionListener(NamedPipeEndPoint endPoint)
 {
     _syncObject = new object();
     _openChannels = new List<NamedPipeCommunicationChannel>();
     _endPoint = endPoint;
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedPipeServer"/> class.
 /// </summary>
 /// <param name="endPoint">The end point.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 public NamedPipeServer(NamedPipeEndPoint endPoint)
 {
     _endPoint = endPoint;
 }