public TcpClientTransport( EndPoint remoteEndPoint, RpcTransportProtocol protocol, ClientEventLoop eventLoop, RpcClientOptions options )
            : base(remoteEndPoint, protocol, eventLoop, options)
        {
            if ( protocol.ProtocolType != ProtocolType.Tcp )
            {
                throw new ArgumentException( "socket must be connected TCP socket.", "protocol" );
            }

            Contract.EndContractBlock();
        }
Esempio n. 2
0
        protected ClientTransport( RpcTransportProtocol protocol, ClientEventLoop eventLoop, RpcClientOptions options )
        {
            if ( eventLoop == null )
            {
                throw new ArgumentNullException( "eventLoop" );
            }

            Contract.EndContractBlock();

            this._eventLoop = eventLoop;
            this._requestSerializer = ClientServices.RequestSerializerFactory.Create( protocol, options );
            this._responseSerializer = ClientServices.ResponseDeserializerFactory.Create( protocol, options );
            this._drainTimeout = options == null ? TimeSpan.FromSeconds( 3 ) : options.DrainTimeout ?? TimeSpan.FromSeconds( 3 );
            this._options = options ?? new RpcClientOptions();
            this._options.Freeze();
        }
Esempio n. 3
0
        public static RpcClient CreateTcp( EndPoint remoteEndPoint, ClientEventLoop eventLoop, RpcClientOptions options )
        {
            RpcTransportException failure = null;
            var transport =
                new TcpClientTransport(
                    remoteEndPoint,
                    options.ForceIPv4.GetValueOrDefault() ? RpcTransportProtocol.TcpIpV4 : RpcTransportProtocol.TcpIp,
                    eventLoop,
                    options
                );
            if ( failure != null )
            {
                throw failure;
            }

            return new RpcClient( transport );
        }
        protected ConnectionOrientedClientTransport( EndPoint remoteEndPoint, RpcTransportProtocol protocol, ClientEventLoop eventLoop, RpcClientOptions options )
            : base(protocol, eventLoop, options)
        {
            if ( remoteEndPoint == null )
            {
                throw new ArgumentNullException( "remoteEndPoint" );
            }

            this._connectionPool =
                new ConnectionPool(
                    remoteEndPoint,
                    protocol,
                    eventLoop,
                    options == null ? _defaultMinimumConnectionCount : ( options.MinimumConnectionCount ?? _defaultMinimumConnectionCount ),
                    options == null ? _defaultMaximumConnectionCount : ( options.MaximumConnectionCount ?? _defaultMaximumConnectionCount )
                );
            this._connectTimeout =
                options == null
                ? _defaultConnectTimeout
                : ( options.ConnectTimeout ?? _defaultConnectTimeout );
        }
Esempio n. 5
0
		public ConnectionPool( EndPoint destination, RpcTransportProtocol protocol, ClientEventLoop eventLoop, int minimumCount, int maximumCount )
		{
			if ( destination == null )
			{
				throw new ArgumentNullException( "destination" );
			}

			if ( eventLoop == null )
			{
				throw new ArgumentNullException( "eventLoop" );
			}

			if ( minimumCount < 0 )
			{
				throw new ArgumentOutOfRangeException( "minimumCount", "'minumumCount' cannot be negative." );
			}

			if ( maximumCount < 1 )
			{
				throw new ArgumentOutOfRangeException( "maximumCount", "'maximumCount' must be positive." );
			}

			if ( maximumCount < minimumCount )
			{
				throw new ArgumentException( "'maximumCount' cannot be lessor than 'minimumCount'.", "maximumCount" );
			}

			Contract.EndContractBlock();

			this._allocationLock = new object();
			this._cancellationTokenSource = new CancellationTokenSource();
			this._destination = destination;
			this._protocol = protocol;
			this._eventLoop = eventLoop;
			this._minimum = minimumCount;
			this._maximum = maximumCount;
			this._availableSockets = new BlockingCollection<RpcSocketAsyncEventArgs>( new ConcurrentQueue<RpcSocketAsyncEventArgs>(), maximumCount );
			this.AllocateMore();
		}
        public UdpClientTransport( RpcSocket socket, EndPoint remoteEndPoint, ClientEventLoop eventLoop, RpcClientOptions options )
            : base(socket == null ? RpcTransportProtocol.UdpIp : socket.Protocol, eventLoop, options)
        {
            if ( socket == null )
            {
                throw new ArgumentNullException( "socket" );
            }

            if ( socket.Protocol.ProtocolType != ProtocolType.Udp )
            {
                throw new ArgumentException( "socket must be connected TCP socket.", "socket" );
            }

            if ( remoteEndPoint == null )
            {
                throw new ArgumentNullException( "remoteEndPoint" );
            }

            Contract.EndContractBlock();

            this._socket = socket;
            this._remoteEndPoint = remoteEndPoint;
        }
Esempio n. 7
0
 public static RpcClient CreateUdp( EndPoint remoteEndPoint, ClientEventLoop eventLoop, RpcClientOptions options )
 {
     var transport =
         new UdpClientTransport(
             ClientServices.SocketFactory(
                 ( options.ForceIPv4.GetValueOrDefault() ? RpcTransportProtocol.UdpIpV4 : RpcTransportProtocol.UdpIp ).CreateSocket()
             ),
             remoteEndPoint,
             eventLoop,
             options
         );
     return new RpcClient( transport );
 }