Ejemplo n.º 1
0
        /// <summary>
        /// <see cref="ServerLink.OnAcceptInternal"/>
        /// </summary>
        protected override bool OnAcceptInternal(LinkSession session)
        {
            var tcpSession = (AbstractTcpSession)session;

            try
            {
                if (!base.OnAcceptInternal(session))
                {
                    return(false);
                }

                var clientSocket = tcpSession.Socket;

                // Adjust client socket options.
                clientSocket.NoDelay = NoDelay;

                tcpSession.BeginReceive(true);

                Trace.Info("{0} {1} accepted from {2}",
                           Name, tcpSession.InternalHandle, clientSocket.RemoteEndPoint);

                return(true);
            }
            catch (Exception ex)
            {
                Trace.Warn("{0} {1} accept error: {2}",
                           Name, tcpSession.InternalHandle, ex);
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Called internally when an event is ready for preprocessing.
 /// </summary>
 internal void OnPreprocess(LinkSession session, Event e)
 {
     if (Preprocess != null)
     {
         Preprocess(session, e);
     }
 }
Ejemplo n.º 3
0
 protected override void OnSessionDisconnectedInternal(int handle, object context)
 {
     using (new WriteLock(rwlock))
     {
         if (!ReferenceEquals(session, null))
         {
             session = null;
         }
     }
 }
Ejemplo n.º 4
0
 protected override void OnSessionConnectedInternal(bool result, object context)
 {
     if (result)
     {
         var session = (LinkSession)context;
         using (new WriteLock(rwlock))
         {
             this.session = session;
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Sends out the specified event through this link channel.
        /// </summary>
        public override void Send(Event e)
        {
            LinkSession currentSession = Session;

            if (ReferenceEquals(currentSession, null))
            {
                Trace.Warn("{0} dropped event {1}", Name, e);
                return;
            }
            currentSession.Send(e);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Connects to the specified IP address and port.
        /// </summary>
        public void Connect(IPAddress ip, int port)
        {
            connecting = true;

            LinkSession session = Session;

            if (session != null &&
                ((AbstractTcpSession)session).SocketConnected)
            {
                Disconnect();
                Trace.Info("{0} disconnected to initiate a new connection", Name);
            }

            Connect(null, new IPEndPoint(ip, port));
        }
        public override void InitiateHandshake(LinkSession session)
        {
            if (ReferenceEquals(BufferTransform, null))
            {
                return;
            }

            var sessionStrategy =
                (BufferTransformSessionStrategy)session.ChannelStrategy;

            var bufferTransform = (IBufferTransform)BufferTransform.Clone();
            sessionStrategy.BufferTransform = bufferTransform;
            SignalPool.Acquire(session.InternalHandle).Set();

            session.Send(new HandshakeReq {
                _Transform = false,
                Data = bufferTransform.InitializeHandshake()
            });
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Called when a new link session is ready for open.
        /// </summary>
        public void InitiateSession(LinkSession session)
        {
            if (HasChannelStrategy)
            {
                ChannelStrategy.BeforeSessionSetup(session);
            }
            if (HasHeartbeatStrategy)
            {
                HeartbeatStrategy.BeforeSessionSetup(session);
            }

            if (HasChannelStrategy)
            {
                ChannelStrategy.InitiateHandshake(session);
            }
            else
            {
                OnLinkSessionConnectedInternal(true, session);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// <see cref="ClientLink.OnConnectInternal"/>
        /// </summary>
        protected override void OnConnectInternal(LinkSession session)
        {
            base.OnConnectInternal(session);

            // Reset the retry counter.
            retryCount = 0;

            var    tcpSession = (AbstractTcpSession)session;
            Socket socket     = tcpSession.Socket;

            // Adjust socket options.
            socket.NoDelay = NoDelay;

            // Save the remote endpoint to reconnect.
            remoteEndPoint = socket.RemoteEndPoint;

            tcpSession.BeginReceive(true);

            Trace.Info("{0} {1} connected to {2}",
                       Name, tcpSession.InternalHandle, socket.RemoteEndPoint);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Frees managed or unmanaged resources.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            LinkSession session = null;

            using (new WriteLock(rwlock))
            {
                if (this.session != null)
                {
                    session      = this.session;
                    this.session = null;
                }
            }
            if (session != null)
            {
                session.Close();
            }

            base.Dispose(disposing);
        }
Ejemplo n.º 11
0
 public override void BeforeSessionSetup(LinkSession linkSession)
 {
     linkSession.HeartbeatStrategy = new KeepaliveSessionStrategy {
         Session = linkSession
     };
 }
 public override void BeforeSessionSetup(LinkSession linkSession)
 {
     linkSession.ChannelStrategy = new BufferTransformSessionStrategy {
         Session = linkSession
     };
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Called immediately once a new link session object is created.
 /// </summary>
 public virtual void BeforeSessionSetup(LinkSession linkSession)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Called by a derived link class on a successful connect.
 /// </summary>
 protected virtual void OnConnectInternal(LinkSession session)
 {
     session.Polarity = true;
     InitiateSession(session);
 }
Ejemplo n.º 15
0
 public virtual void InitiateHandshake(LinkSession session)
 {
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Called once an existing link session object is shut down.
 /// </summary>
 public virtual void AfterSessionTeardown(LinkSession linkSession)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Called by a derived link class on a successful accept.
 /// </summary>
 protected virtual bool OnAcceptInternal(LinkSession session)
 {
     InitiateSession(session);
     return(true);
 }
Ejemplo n.º 18
0
 public Diagnostics(LinkSession owner)
 {
     this.owner = owner;
 }