本文整理匯總了C#中BitField.SetAll方法的典型用法代碼示例。如果您正苦於以下問題:C# BitField.SetAll方法的具體用法?C# BitField.SetAll怎麽用?C# BitField.SetAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BitField
的用法示例。
在下文中一共展示了BitField.SetAll方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: From
public void From()
{
BitField b = new BitField(31);
b.SetAll(true);
Assert.AreEqual(31, b.TrueCount, "#1");
Assert.IsTrue(b.AllTrue, "#1b");
b = new BitField(32);
b.SetAll(true);
Assert.AreEqual(32, b.TrueCount, "#2");
Assert.IsTrue(b.AllTrue, "#2b");
b = new BitField(33);
b.SetAll(true);
Assert.AreEqual(33, b.TrueCount, "#3");
Assert.IsTrue(b.AllTrue, "#3b");
}
示例2: From
public void From()
{
var b = new BitField(31);
b.SetAll(true);
Assert.Equal(31, b.TrueCount);
Assert.True(b.AllTrue);
b = new BitField(32);
b.SetAll(true);
Assert.Equal(32, b.TrueCount);
Assert.True(b.AllTrue);
b = new BitField(33);
b.SetAll(true);
Assert.Equal(33, b.TrueCount);
Assert.True(b.AllTrue);
}
示例3: LargeBitfield
public void LargeBitfield()
{
BitField bf = new BitField(1000);
bf.SetAll(true);
Assert.AreEqual(1000, bf.TrueCount);
}
示例4: PeerHandshakeReceived
private void PeerHandshakeReceived(bool succeeded, int count, object state)
{
PeerId id = (PeerId)state;
string reason = null;
bool cleanUp = false;
PeerMessage msg;
try
{
// If the connection is closed, just return
if (!succeeded)
{
CleanupSocket(id, "Handshaking failed");
return;
}
// Decode the handshake and handle it
id.Decryptor.Decrypt(id.recieveBuffer.Array, id.recieveBuffer.Offset, count);
msg = new HandshakeMessage();
msg.Decode(id.recieveBuffer, 0, count);
msg.Handle(id);
Logger.Log(id.Connection, "ConnectionManager - Handshake recieved");
if (id.SupportsFastPeer && ClientEngine.SupportsFastPeer)
{
if (id.TorrentManager.Bitfield.AllFalse || id.TorrentManager.IsInitialSeeding)
msg = new HaveNoneMessage();
else if (id.TorrentManager.Bitfield.AllTrue)
msg = new HaveAllMessage();
else
msg = new BitfieldMessage(id.TorrentManager.Bitfield);
}
else if (id.TorrentManager.IsInitialSeeding)
{
BitField btfld = new BitField(id.TorrentManager.Bitfield.Length);
btfld.SetAll(false);
msg = new BitfieldMessage(btfld);
}
else
{
msg = new BitfieldMessage(id.TorrentManager.Bitfield);
}
if (id.SupportsLTMessages && ClientEngine.SupportsExtended)
{
MessageBundle bundle = new MessageBundle();
bundle.Messages.Add(new ExtendedHandshakeMessage());
bundle.Messages.Add(msg);
msg = bundle;
}
//ClientEngine.BufferManager.FreeBuffer(ref id.recieveBuffer);
SendMessage(id, msg, this.bitfieldSentCallback);
}
catch (TorrentException)
{
Logger.Log(id.Connection, "ConnectionManager - Couldn't decode the message");
reason = "Couldn't decode handshake";
cleanUp = true;
return;
}
finally
{
if (cleanUp)
CleanupSocket(id, reason);
}
}