Esempio n. 1
0
        public RpcTcpDuplexConnection(RpcTcpClientChannel channel, TcpUri serverUri)
            : base(RpcConnectionMode.Duplex, RpcConnectionDirection.Client)
        {
            _serverUri = serverUri;

            _socket = new RpcTcpSocketConnection(RpcConnectionDirection.Client);
            _socket.Disconnected += new Action <RpcTcpSocketConnection>(
                (socket) => {
                OnDisconnected();
            }
                );

            _socket.RequestReceived += new Action <RpcTcpSocketConnection, int, RpcRequest>(
                (socket, seq, request) => {
                var tx = new RpcTcpServerTransaction(_channel, this, socket, request, seq);
                OnTransactionCreated(tx);
            }
                );

            _socket.ResponseReceived += new Action <RpcTcpSocketConnection, int, RpcResponse>(
                (socket, seq, response) => {
                RpcTcpTransactionManager.EndTransaction(seq, response);
            }
                );

            _channel = new RpcDuplexCallbackChannel("tcp", serverUri.ToString(), this, channel);
        }
Esempio n. 2
0
        public RpcTcpServerConnection(RpcTcpServerChannel channel, RpcTcpSocketConnection sock)
            : base(RpcConnectionMode.Unknown, RpcConnectionDirection.Server)
        {
            _channel = channel;
            _sock    = sock;

            _sock.RequestReceived += new Action <RpcTcpSocketConnection, int, RpcRequest>(
                (socket, seq, request) => {
                RpcTcpServerTransaction tx = new RpcTcpServerTransaction(_channel, this, socket, request, seq);
                OnTransactionCreated(tx);
            }
                );

            _sock.ResponseReceived += new Action <RpcTcpSocketConnection, int, RpcResponse>(
                (socket, seq, response) => {
                RpcTcpTransactionManager.EndTransaction(seq, response);
            }
                );

            _sock.Disconnected += new Action <RpcTcpSocketConnection>(
                (socket) => {
                OnDisconnected();
            }
                );
        }
Esempio n. 3
0
 public override void SendRequest(Action callback, int timeout)
 {
     _callback = callback;
     if (_sock == null)
     {
         Callback(RpcResponse.Create(RpcErrorCode.ConnectionPending, null));
     }
     else
     {
         Timeout = timeout;
         RpcTcpTransactionManager.BeginTransaction(this);
         _sock.Send(this);
     }
 }
Esempio n. 4
0
        public override RpcClientTransaction CreateTransaction(RpcRequest request)
        {
            int n       = _lc.Next();
            var wrapper = _connections[n];
            var sock    = wrapper.GetSocket();

            if (sock == null)
            {
                throw new RpcException(RpcErrorCode.ConnectionPending, _serverUri.ToString(), "no SimplexConnection available", null);
            }
            var tx = RpcTcpTransactionManager.CreateClientTransaction(_serverUri, sock, request);

            return(tx);
        }
        private void CreateConnection()
        {
            var sock = new RpcTcpSocketConnection(RpcConnectionDirection.Client);

            sock.Disconnected += new Action <RpcTcpSocketConnection>(
                (s) => {
                _parent.OnSubDisconnected();
            }
                );

            sock.RequestReceived += new Action <RpcTcpSocketConnection, int, RpcRequest>(
                (s, seq, request) => {
                // TODO
                // Not support this response
            }
                );

            sock.ResponseReceived += new Action <RpcTcpSocketConnection, int, RpcResponse>(
                (s, seq, response) => {
                RpcTcpTransactionManager.EndTransaction(seq, response);
            }
                );

            //
            // Auto Connect
            sock.BeginConnect(
                (TcpUri)_parent.RemoteUri,
                delegate(Exception ex) {
                if (ex != null)
                {
                    _retryBegin = DateTime.Now.AddSeconds(1);
                }
                else
                {
                    _parent.OnSubConnected();
                }
            },
                false
                );

            _sock = sock;
        }
Esempio n. 6
0
        /// <summary>
        ///		构造函数, 不需要参数
        /// </summary>
        public RpcTcpClientChannel()
            : base("tcp")
        {
            RpcTcpBufferManager.Initialize();
            RpcTcpSimplexConnectionManager.Initialize();

            _simplexConnections = new Dictionary <ServerUri, RpcTcpSimplexConnection>();
            _duplexConnections  = new Dictionary <ServerUri, RpcTcpDuplexConnection>();

            p_channelSettings = new RpcChannelSettings()
            {
                MaxBodySize          = 512 * 1024 * 1024,
                SupportModes         = RpcChannelSupportModes.Connection | RpcChannelSupportModes.DuplexConnection,
                Version              = "4.3",
                Timeout              = RpcTcpBufferManager.Configuration.ChannelItem.Timeout,
                ConcurrentConnection = RpcTcpBufferManager.Configuration.ChannelItem.SimplexConnections,
            };

            RpcTcpTransactionManager.Initialize();
        }
Esempio n. 7
0
        public override RpcClientTransaction CreateTransaction(RpcRequest request)
        {
            RpcTcpClientTransaction trans = RpcTcpTransactionManager.CreateClientTransaction(_sock.RemoteUri, _sock, request);

            return(trans);
        }
Esempio n. 8
0
 public void SendFailed(RpcErrorCode code, Exception ex)
 {
     Response = RpcResponse.Create(code, ex);
     RpcTcpTransactionManager.EndTransaction(Sequence, Response);
 }