Exemple #1
0
        public void Close()
        {
            try
            {
                if (_keepAliveTracker != null)
                {
                    _keepAliveTracker.StopTimer();
                }
                if (_keepAliveTimeoutTimer != null)
                {
                    _keepAliveTimeoutTimer.Change(Timeout.Infinite, Timeout.Infinite);
                }

                var copySession = _innerSession;
                _innerSession = null;
                if (copySession != null && copySession.Active)
                {
                    copySession.Close();
                }

                this.SessionHandshaked   -= OnSessionHandshaked;
                this.SessionDataReceived -= OnSessionDataReceived;

                if (ChannelDisconnected != null)
                {
                    ChannelDisconnected(this, new ActorChannelDisconnectedEventArgs(this.Identifier, _remoteActor));
                }
            }
            finally
            {
                _remoteActor = null;
                IsHandshaked = false;
            }
        }
Exemple #2
0
 public ActorTransportSessionConnectedEventArgs(ActorTransportSession session)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     this.Session = session;
 }
Exemple #3
0
        private void OnClientDataReceived(object sender, TcpClientDataReceivedEventArgs e)
        {
            ActorTransportSession session = null;

            if (_sessions.TryGetValue(e.Session.SessionKey, out session))
            {
                if (DataReceived != null)
                {
                    DataReceived(this, new ActorTransportSessionDataReceivedEventArgs(session, e.Data, e.DataOffset, e.DataLength));
                }
            }
        }
Exemple #4
0
        private void OnClientConnected(object sender, TcpClientConnectedEventArgs e)
        {
            _log.DebugFormat("TCP client [{0}] has connected.", e.Session.RemoteEndPoint);
            var session = new ActorTransportSession(e.Session);

            _sessions.Add(e.Session.SessionKey, session);

            if (Connected != null)
            {
                Connected(this, new ActorTransportSessionConnectedEventArgs(session));
            }
        }
        public ActorChannelSession(
            ActorIdentity localActor,
            ActorChannelConfiguration channelConfiguration,
            ActorTransportSession session)
        {
            _localActor           = localActor;
            _channelConfiguration = channelConfiguration;
            _innerSession         = session;

            _keepAliveTracker      = KeepAliveTracker.Create(KeepAliveInterval, new TimerCallback((s) => OnKeepAlive()));
            _keepAliveTimeoutTimer = new Timer(new TimerCallback((s) => OnKeepAliveTimeout()), null, Timeout.Infinite, Timeout.Infinite);
        }
Exemple #6
0
        public ActorTransportSessionDataReceivedEventArgs(ActorTransportSession session, byte[] data, int dataOffset, int dataLength)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            Session = session;

            Data       = data;
            DataOffset = dataOffset;
            DataLength = dataLength;
        }
Exemple #7
0
        public void EndSendTo(string sessionKey, IAsyncResult asyncResult)
        {
            ActorTransportSession session = null;

            if (_sessions.TryGetValue(sessionKey, out session))
            {
                session.EndSend(asyncResult);
            }
            else
            {
                _log.WarnFormat("EndSendTo, cannot find target session [{0}].", sessionKey);
            }
        }
Exemple #8
0
        private void OnClientDisconnected(object sender, TcpClientDisconnectedEventArgs e)
        {
            _log.DebugFormat("TCP client [{0}] has disconnected.", e.Session.RemoteEndPoint);
            ActorTransportSession session = null;

            if (_sessions.TryRemove(e.Session.SessionKey, out session))
            {
                if (Disconnected != null)
                {
                    Disconnected(this, new ActorTransportSessionDisconnectedEventArgs(session));
                }
            }
        }
Exemple #9
0
        public void BeginSendTo(string sessionKey, byte[] data, int offset, int count)
        {
            if (!IsListening)
            {
                throw new InvalidOperationException("The server has stopped to listen.");
            }

            ActorTransportSession session = null;

            if (_sessions.TryGetValue(sessionKey, out session))
            {
                session.BeginSend(data, offset, count);
            }
            else
            {
                _log.WarnFormat("BeginSendTo, cannot find target session [{0}].", sessionKey);
            }
        }
Exemple #10
0
        public IAsyncResult BeginSendTo(string sessionKey, byte[] data, int offset, int count, AsyncCallback callback, object state)
        {
            if (!IsListening)
            {
                throw new InvalidOperationException("The server has stopped to listen.");
            }

            ActorTransportSession session = null;

            if (_sessions.TryGetValue(sessionKey, out session))
            {
                return(session.BeginSend(data, offset, count, callback, state));
            }
            else
            {
                _log.WarnFormat("BeginSendTo, cannot find target session [{0}].", sessionKey);
            }

            return(null);
        }
Exemple #11
0
 public ActorTransportSessionDataReceivedEventArgs(ActorTransportSession session, byte[] data)
     : this(session, data, 0, data.Length)
 {
 }