コード例 #1
0
        /// <summary>
        /// Handles the CommunicationErrorOccurred event of the Peer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        private void Peer_CommunicationErrorOccurred(object sender, PeerCommunicationErrorEventArgs e)
        {
            Peer peer;

            peer = sender as Peer;

            if (e.IsFatal)
            {
                Debug.WriteLine($"fatal communication error occurred for peer {peer.Endpoint} on torrent {this.TorrentInfo.InfoHash}: {e.ErrorMessage}");

                lock (((IDictionary)this.peers).SyncRoot)
                {
                    // update transfer parameters
                    this.downloaded += peer.Downloaded;
                    this.uploaded   += peer.Uploaded;

                    // something is wrong with the peer -> remove it from the list and close the connection
                    if (this.peers.ContainsKey(peer.Endpoint))
                    {
                        this.peers.Remove(peer.Endpoint);
                    }

                    // dispose of the peer
                    peer.Dispose();
                }
            }
            else
            {
                Debug.WriteLine($"communication error occurred for peer {peer.Endpoint} on torrent {this.TorrentInfo.InfoHash}: {e.ErrorMessage}");
            }
        }
コード例 #2
0
        /// <summary>
        /// Called when peer communication error has occurred.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments.</param>
        private void OnCommunicationErrorOccurred(object sender, PeerCommunicationErrorEventArgs e)
        {
            sender.CannotBeNull();
            e.CannotBeNull();

            if (this.CommunicationErrorOccurred != null)
            {
                this.CommunicationErrorOccurred(sender, e);
            }
        }