Esempio n. 1
0
        // Asynchronous callback for BeginConnect
        private void OnConnect(IAsyncResult asyncResult)
        {
            var noti = new LinkSessionConnected { LinkName = Name };

            try
            {
                socket.EndConnect(asyncResult);

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

                Log.Info("{0} {1} connected to {2}", Name, socket.Handle, socket.RemoteEndPoint);

                noti.Result = true;

                ConnectInternal();

                session = new TcpLinkSession(this, socket);
                session.Polarity = true;

                if (BufferTransform != null)
                {
                    session.BufferTransform = BufferTransform;
                }

                noti.Context = session;
                Flow.Publish(noti);

                session.BeginReceive(true);
            }
            catch (Exception e)
            {
                Log.Warn("{0} connect error: {1}", Name, e.Message);

                var endpoint = (EndPoint)asyncResult.AsyncState;

                noti.Context = endpoint;
                Flow.Publish(noti);

                RetryInternal(endpoint);
            }
        }
Esempio n. 2
0
        // Completion callback for ConnectAsync
        private void OnConnect(SocketAsyncEventArgs e)
        {
            var noti = new LinkSessionConnected { LinkName = Name };

            if (e.SocketError == SocketError.Success)
            {
                // Adjust socket options.
                socket.NoDelay = NoDelay;

                Log.Info("{0} {1} connected to {2}", Name, socket.Handle, socket.RemoteEndPoint);

                noti.Result = true;

                ConnectInternal();

                connectEventArgs = null;

                session = new AsyncTcpLinkSession(this, socket);
                session.Polarity = true;

                if (BufferTransform != null)
                {
                    session.BufferTransform = BufferTransform;
                }

                noti.Context = session;
                Flow.Publish(noti);

                session.BeginReceive(true);
            }
            else
            {
                Log.Warn("{0} connect error {1}", Name, e.SocketError);

                noti.Context = e.RemoteEndPoint;
                Flow.Publish(noti);

                RetryInternal(e.RemoteEndPoint);
            }
        }
Esempio n. 3
0
        private void OnLinkSessionConnected(LinkSessionConnected e)
        {
            OnSessionConnected(e);

            SocketLinkSession linkSession = (SocketLinkSession)e.Context;
            linkSession.HeartbeatTimeoutToken = Timer.Reserve(linkSession, 15);
        }
Esempio n. 4
0
 protected virtual void OnSessionConnected(LinkSessionConnected e)
 {
 }
Esempio n. 5
0
        private void OnLinkSessionConnected(LinkSessionConnected e)
        {
            OnSessionConnected(e);

            link.Session.HeartbeatTimeoutToken = Timer.Reserve(new Object(), 15);
            Timer.ReserveRepetition(null, new TimeSpan(0, 0, 5));
        }