コード例 #1
0
ファイル: TransportAddress.cs プロジェクト: johnynek/brunet
 public static TransportAddress CreateInstance(TransportAddress.TAType t,
                         IPAddress host, int port) {
   Cache ta_cache = Interlocked.Exchange<Cache>(ref _ta_cache, null);
   if( ta_cache != null ) {
     TransportAddress ta = null;
     try {
       CacheKey key = new CacheKey(host, port, t);
       ta = (TransportAddress) ta_cache[key];
       if( ta == null ) {
         ta = new IPTransportAddress(t, host, port);
         ta_cache[key] = ta; 
        }
     }
     finally {
       Interlocked.Exchange<Cache>(ref _ta_cache, ta_cache);
     }
     return ta;
   }
   else {
     return new IPTransportAddress(t, host, port);
   }
 }
コード例 #2
0
ファイル: Cache.cs プロジェクト: pstjuste/brunet
 public void CacheKeyTest() {
   CacheKey test1 = new CacheKey("hello", "this", "is", "a", "test");
   CacheKey test2 = new CacheKey("hello", "this", "is", "a", "test");
   CacheKey test3 = new CacheKey("hello", "this", "is", "not", "a", "test");
   CacheKey test4 = new CacheKey("hello", "this", "is", "a different", "test");
   Assert.AreEqual(test1.GetHashCode(), test2.GetHashCode(), "CacheKey Hashcode equality");
   Assert.AreEqual(test1, test2, "CacheKey equality");
   Assert.IsFalse(test1.Equals(test3), "CacheKey non-equality");
   Assert.IsFalse(test2.Equals(test3), "CacheKey non-equality");
   Assert.IsFalse(test1.Equals(test4), "CacheKey non-equality");
   Assert.IsFalse(test2.Equals(test4), "CacheKey non-equality");
   Assert.IsFalse(test3.Equals(test4), "CacheKey non-equality");
 }