コード例 #1
0
ファイル: Peer.cs プロジェクト: Whinarn/TorrentSwifter
        private void OnConnectionDisconnected(object sender, EventArgs e)
        {
            Log.LogInfo("[Peer] Disconnected from {0}", endPoint);

            if (connection != null)
            {
                UninitializeConnection(connection);
                connection.Dispose();
                connection = null;
            }

            if (torrent != null)
            {
                torrent.OnPeerDisconnected(this);
            }

            Disconnected.SafeInvoke(this, e);
        }
コード例 #2
0
ファイル: Peer.cs プロジェクト: Whinarn/TorrentSwifter
        /// <summary>
        /// Attempts to connect to this peer synchronously.
        /// </summary>
        /// <returns>If the connection was successfully established.</returns>
        public bool Connect()
        {
            if (connection != null)
            {
                return(false);
            }

            try
            {
                connection = new PeerConnectionTCP(torrent, this, endPoint);
                InitializeConnection(connection);
                connection.Connect();
                return(connection.IsConnected);
            }
            catch
            {
                return(false);
            }
        }
コード例 #3
0
ファイル: Peer.cs プロジェクト: Whinarn/TorrentSwifter
        /// <summary>
        /// Attempts to connect to this peer asynchronously.
        /// </summary>
        /// <returns>If the connection was successfully established.</returns>
        public async Task <bool> ConnectAsync()
        {
            if (connection != null)
            {
                return(false);
            }

            try
            {
                connection = new PeerConnectionTCP(torrent, this, endPoint);
                InitializeConnection(connection);
                await connection.ConnectAsync();

                return(connection.IsConnected);
            }
            catch
            {
                return(false);
            }
        }
コード例 #4
0
 private static void UnregisterConnectionEvents(PeerConnection connection)
 {
     connection.Disconnected -= OnConnectionDisconnected;
     connection.Handshaked   -= OnConnectionHandshaked;
 }