Author: alanmc
Date: 2007-06-22 09:16:03 -0400 (Fri, 22 Jun 2007)
New Revision: 80552

Modified:
   trunk/bitsharp/src/README
Log:
updated readme

Modified: trunk/bitsharp/src/README
===================================================================
--- trunk/bitsharp/src/README   2007-06-22 13:14:48 UTC (rev 80551)
+++ trunk/bitsharp/src/README   2007-06-22 13:16:03 UTC (rev 80552)
@@ -42,54 +42,7 @@
 there is no guarantee what thread the events will be fired on, so if you're 
doing GUI updates, you will need to
 make sure that you perform your actual GUI update in a threadsafe manner.
 
-Secondly, when dealing with the PeerId class which is passed to you when a 
peer connects or disconnects,
-there are two important things to note. 
 
-1) These are used directly by the engine. If you so wish, you can make the 
whole thing crash and burn by doing
-stupid things with those classes. On the other hand, it should be hard to 
break the engine while using them
-correctly.
-
-2) As the engine uses a lot of asynchronous code, thread safety is an issue 
that you have to deal with. In order
-to safely access the PeerId class which you have received, you must take a 
lock on that object. After taking the
-lock, you need to check if the id.Peer.Connection is null. If it is, the peer 
has been disposed and should be
-considered garbage so drop all references to it. If the Connection is not 
null, then the peer is still valid
-and you can safely do whatever you want with it. Do *not* hold the lock for 
longer than you need. If you hold the lock
-for 100ms while you perform a GUI update, you will stop the engine from 
downloading for up to 100ms! This is obviously
-not good.
-
-Example of safe and non-blocking usage:
-
-static void ConnectionManager_PeerConnected(object sender, 
PeerConnectionEventArgs e)
-{
-    bool amChoking = 0;
-    bool isChoking = 0;
-    double downSpeed = 0;
-    double upSpeed = 0;
-
-    lock (e.PeerID)
-    {
-        if (e.PeerID.Peer.Connection == null)
-        {
-            // The peer has been disposed internally, so you cannot use it.
-            return;
-        }
-        else
-        {
-            // The peer is still active and can now be safely accessed while 
the lock is held
-            PeerConnectionBase conn = e.PeerID.Peer.Connection;
-            amChoking = conn.AmChoking;
-            isChoking = conn.IsChoking;
-            downSpeed = conn.Monitor.DownloadSpeed;
-            upSpeed = conn.Monitor.UploadSpeed;
-        }
-    }
-
-    // We release the lock and perform our complex and time consuming GUI 
update
-    UpdateGuiWithNewPeerStatus(amChoking, isChoking, downSpeed, upSpeed);
-}
-
-
-
 [The Tracker]
 ============
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to