Beispiel #1
0
        /// <summary>
        /// Fires whenever a Helios <see cref="IConnection"/> gets closed.
        /// 
        /// Two possible causes for this event handler to fire:
        ///  * The other end of the connection has closed. We don't make any distinctions between graceful / unplanned shutdown.
        ///  * This end of the connection experienced an error.
        /// </summary>
        /// <param name="cause">An exception describing why the socket was closed.</param>
        /// <param name="closedChannel">The handle to the socket channel that closed.</param>
        protected override void OnDisconnect(HeliosConnectionException cause, IConnection closedChannel)
        {
            //if (cause != null)
            //    ChannelLocalActor.Notify(closedChannel, new UnderlyingTransportError(cause, "Underlying transport closed."));

            ChannelLocalActor.Notify(closedChannel, new Disassociated(DisassociateInfo.Unknown));
            ChannelLocalActor.Remove(closedChannel);
        }
Beispiel #2
0
 private void ConnectionTerminatedCallback(HeliosConnectionException reason, IConnection closedChannel)
 {
     Invoke((Action)(() =>
     {
         AppendStatusText(string.Format("Disconnected from {0}", closedChannel.RemoteHost));
         AppendStatusText(string.Format("Reason: {0}", reason.Message));
         tsStatusLabel.Text = string.Format("Disconnected from {0}", closedChannel.RemoteHost);
         btnSend.Enabled = false;
         tbSend.Enabled = false;
     }));
 }
 protected override void OnDisconnect(HeliosConnectionException cause, IConnection closedChannel)
 {
     if(cause != null)
         ChannelLocalActor.Notify(closedChannel, new UnderlyingTransportError(cause, "Underlying transport closed."));
     if (cause != null && cause.Type == ExceptionType.Closed)
         ChannelLocalActor.Notify(closedChannel, new Disassociated(DisassociateInfo.Shutdown));
     else
     {
         ChannelLocalActor.Notify(closedChannel, new Disassociated(DisassociateInfo.Unknown));
     }
         
     ChannelLocalActor.Remove(closedChannel);
 }
Beispiel #4
0
        public override void Open()
        {
            CheckWasDisposed();

            if (IsOpen()) return;

            if (RemoteHost == null || RemoteHost.Host == null)
            {
                throw new HeliosConnectionException(ExceptionType.NotOpen, "Cannot open a connection to a null Node or null Node.Host");
            }

            if (RemoteHost.Port <= 0)
            {
                throw new HeliosConnectionException(ExceptionType.NotOpen, "Cannot open a connection to an invalid port");
            }

            if (_client == null)
                InitClient();

            var ar = _client.BeginConnect(RemoteHost.Host, RemoteHost.Port, null, null);
            if (ar.AsyncWaitHandle.WaitOne(Timeout))
            {
                try
                {
                    _client.EndConnect(ar);
                    HeliosTrace.Instance.TcpClientConnectSuccess();
                }
                catch (SocketException ex)
                {
                    HeliosTrace.Instance.TcpClientConnectFailure(ex.Message);
					// JKH = because I want to know if my BeginConnect has failed and because when I use BeginConnect I cannot catch this throw and it litters my Debug window
					HeliosConnectionException rethrow = new HeliosConnectionException(ExceptionType.NotOpen, ex);
					InvokeDisconnectIfNotNull(RemoteHost, rethrow);
					return;
                    //throw rethrow;	using BeginConnect, I cannot catch this throw...
                }
            }
            else
            {
                _client.Close();
                HeliosTrace.Instance.TcpClientConnectFailure("Timed out on connect");
				// JKH = because I want to know if my BeginConnect has failed
				HeliosConnectionException rethrow = new HeliosConnectionException(ExceptionType.TimedOut, "Timed out on connect");
				InvokeDisconnectIfNotNull(RemoteHost, rethrow);
                throw rethrow;
            }
            SetLocal(_client);
            InvokeConnectIfNotNull(RemoteHost);
        }
 protected void InvokeDisconnectIfNotNull(INode remoteHost, HeliosConnectionException ex)
 {
     if (NetworkEventLoop.Disconnection != null)
     {
         NetworkEventLoop.Disconnection(ex, this);
     }
 }
Beispiel #6
0
 /// <summary>
 /// Invoked when a node's connection to this server has been disconnected
 /// </summary>
 /// <param name="closedChannel">The <see cref="IConnection"/> instance that just closed</param>
 /// <param name="reason">The reason why this node disconnected</param>
 protected void NodeDisconnected(HeliosConnectionException reason, IConnection closedChannel)
 {
     if (EventLoop.Disconnection != null)
     {
         EventLoop.Disconnection(reason, closedChannel);
     }
 }
Beispiel #7
0
 protected abstract void OnDisconnect(HeliosConnectionException cause, IConnection closedChannel);
Beispiel #8
0
 protected void InvokeDisconnectIfNotNull(INode remoteHost, HeliosConnectionException ex)
 {
     if (OnDisconnection != null)
     {
         OnDisconnection(ex, this);
     }
 }
Beispiel #9
0
 private static void ConnectionTerminatedCallback(HeliosConnectionException reason, IConnection closedChannel)
 {
     Console.WriteLine("Connection Terminated");
 }
Beispiel #10
0
 protected override void OnDisconnect(HeliosConnectionException cause, IConnection closedChannel)
 {
     ChannelLocalActor.Notify(closedChannel, new Disassociated(DisassociateInfo.Unknown));
 }
 protected override void OnDisconnect(HeliosConnectionException cause, IConnection closedChannel)
 {
     _handler.OnDisconnect(cause, closedChannel);
 }