コード例 #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);
            }
        }
コード例 #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);
     }
 }
コード例 #3
0
ファイル: ClientLink.cs プロジェクト: awesomedotnetcore/x2net
 protected override void OnSessionDisconnectedInternal(int handle, object context)
 {
     using (new WriteLock(rwlock))
     {
         if (!ReferenceEquals(session, null))
         {
             session = null;
         }
     }
 }
コード例 #4
0
ファイル: ClientLink.cs プロジェクト: awesomedotnetcore/x2net
 protected override void OnSessionConnectedInternal(bool result, object context)
 {
     if (result)
     {
         var session = (LinkSession)context;
         using (new WriteLock(rwlock))
         {
             this.session = session;
         }
     }
 }
コード例 #5
0
ファイル: ClientLink.cs プロジェクト: awesomedotnetcore/x2net
        /// <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);
        }
コード例 #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));
        }
コード例 #7
0
        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()
            });
        }
コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #10
0
ファイル: ClientLink.cs プロジェクト: awesomedotnetcore/x2net
        /// <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);
        }
コード例 #11
0
 public override void BeforeSessionSetup(LinkSession linkSession)
 {
     linkSession.HeartbeatStrategy = new KeepaliveSessionStrategy {
         Session = linkSession
     };
 }
コード例 #12
0
 public override void BeforeSessionSetup(LinkSession linkSession)
 {
     linkSession.ChannelStrategy = new BufferTransformSessionStrategy {
         Session = linkSession
     };
 }
コード例 #13
0
 /// <summary>
 /// Called immediately once a new link session object is created.
 /// </summary>
 public virtual void BeforeSessionSetup(LinkSession linkSession)
 {
 }
コード例 #14
0
ファイル: ClientLink.cs プロジェクト: awesomedotnetcore/x2net
 /// <summary>
 /// Called by a derived link class on a successful connect.
 /// </summary>
 protected virtual void OnConnectInternal(LinkSession session)
 {
     session.Polarity = true;
     InitiateSession(session);
 }
コード例 #15
0
 public virtual void InitiateHandshake(LinkSession session)
 {
 }
コード例 #16
0
 /// <summary>
 /// Called once an existing link session object is shut down.
 /// </summary>
 public virtual void AfterSessionTeardown(LinkSession linkSession)
 {
 }
コード例 #17
0
ファイル: ServerLink.cs プロジェクト: awesomedotnetcore/x2net
 /// <summary>
 /// Called by a derived link class on a successful accept.
 /// </summary>
 protected virtual bool OnAcceptInternal(LinkSession session)
 {
     InitiateSession(session);
     return(true);
 }
コード例 #18
0
 public Diagnostics(LinkSession owner)
 {
     this.owner = owner;
 }