本文整理汇总了C#中MemBlock类的典型用法代码示例。如果您正苦于以下问题:C# MemBlock类的具体用法?C# MemBlock怎么用?C# MemBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemBlock类属于命名空间,在下文中一共展示了MemBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UdpPacket
/**
<summary>Takes in a MemBlock and parses it as a Udp Packet.</summary>
<param name="packet">The MemBlock containing the Udp Packet</param>
*/
public UdpPacket(MemBlock packet)
{
_icpacket = _packet = packet;
SourcePort = (packet[0] << 8) | packet[1];
DestinationPort = (packet[2] << 8) | packet[3];
_icpayload = _payload = packet.Slice(8);
}
示例2: HandleData
public void HandleData(MemBlock packet, ISender from, object node)
{
_message_count++;
long stop_time, rt_ticks = -10000;
if ( !from.Equals(node)) {
if (packet[0] == 0) {
//log.Debug("Echo Response:");
stop_time = System.DateTime.Now.Ticks;
int received_uid = NumberSerializer.ReadInt(packet, 1);
if(uid_starttime.ContainsKey(received_uid)){
rt_ticks = stop_time - (long)EchoTester.uid_starttime[received_uid];
}
double rt_ms = (double) rt_ticks/10000.0;
uid_brunetpingtime.Add(received_uid, rt_ms);
Console.WriteLine("Packet ID = {0}, Round-trip = {1}", received_uid, rt_ms);
}
else {
//log.Debug("Echo Request:");
}
//log.Debug(packet.ToString());
//System.Console.WriteLine("{0}", packet.ToString());
if (packet[0] > 0) {
//Send a reply back, this is a request
byte[] new_payload = new byte[ packet.Length ];
packet.CopyTo(new_payload, 0);
new_payload[0] = (byte) 0;
from.Send(new CopyList(PType.Protocol.Echo, MemBlock.Reference(new_payload)));
}
}
}
示例3: EthernetPacket
/// <summary>This parses a MemBlock into the Ethernet fields</summary>
/// <param name="Packet">The Ethernet packet</param>
public EthernetPacket(MemBlock Packet) {
_icpacket = _packet = Packet;
DestinationAddress = Packet.Slice(0, 6);
SourceAddress = Packet.Slice(6, 6);
Type = (Types) ((Packet[12] << 8) | Packet[13]);
_icpayload = _payload = Packet.Slice(14);
}
示例4: IgmpPacket
public IgmpPacket(MemBlock packet)
{
_icpacket = _packet = packet;
Type = packet[0];
GroupAddress = packet.Slice(4, 4);
_icpayload = _payload = packet.Slice(8);
}
示例5: HandleData
public void HandleData(MemBlock payload, ISender return_path, object state) {
if(_sub != null) {
MemBlock rest = null;
PType.Parse(payload, out rest);
_sub.Handle(rest, return_path);
}
}
示例6: SecurityControlMessage
static SecurityControlMessage()
{
byte[] empty_cookie = new byte[CookieLength];
for(int i = 0; i < CookieLength; i++) {
empty_cookie[i] = 0;
}
EmptyCookie = MemBlock.Reference(empty_cookie);
}
示例7: DhtDns
/**
<summary>Create a DhtDns using the specified Dht object</summary>
<param name="dht">A Dht object used to acquire name translations</param>
*/
public DhtDns(MemBlock ip, MemBlock netmask, string name_server,
bool forward_queries, IDht dht, String ipop_namespace) :
base(ip, netmask, name_server, forward_queries)
{
_ipop_namespace = ipop_namespace;
_dht = dht;
_sync = new object();
}
示例8: HandleData
public void HandleData(MemBlock payload, ISender return_path, object state) {
_last_received = payload;
_ht[payload] = return_path;
_order.Add(payload);
if(HandleDataCallback != null) {
HandleDataCallback(payload, null);
}
}
示例9: HandleData
public void HandleData(MemBlock b, ISender return_path, object state) {
byte b0 = b[0];
if( b0 == 0 ) {
//This is a request:
MemBlock data = b.Slice(1);
//Make sure node to reply with a zero
return_path.Send( new CopyList( PType.Protocol.Echo, REPLY_HEADER, data) );
}
}
示例10: UdpPacket
/**
<summary>Takes in a MemBlock and parses it as a Udp Packet.</summary>
<param name="packet">The MemBlock containing the Udp Packet</param>
*/
public UdpPacket(MemBlock packet) {
if(packet.Length < 8) {
throw new Exception("Invalid UDP Packet");
}
_icpacket = _packet = packet;
SourcePort = (packet[0] << 8) | packet[1];
DestinationPort = (packet[2] << 8) | packet[3];
_icpayload = _payload = packet.Slice(8);
}
示例11: AHHeader
/** Parse the first LENGTH bytes to get the AHHeader
*/
public AHHeader(MemBlock mb) {
Hops = NumberSerializer.ReadShort(mb, 0);
Ttl = NumberSerializer.ReadShort(mb, 2);
//We parse the Address objects lazily
Opts = (ushort)NumberSerializer.ReadShort(mb, 2 * Address.MemSize + 4);
if( mb.Length != LENGTH ) {
mb = mb.Slice(0,LENGTH);
}
_data = mb;
}
示例12: Resolve
/// <summary>Translates an IP Address to a Brunet Address. If it is in the
/// cache it returns a result, otherwise it returns null and begins a Miss
/// lookup.</summary>
/// <param name="ip">The IP Address to translate.</param>
/// <returns>Null if none exists or there is a miss or the Brunet Address if
/// one exists in the cache</returns>
public Address Resolve(MemBlock ip)
{
Address addr;
bool update;
bool success = _cache.TryGetValue(ip, out addr, out update);
if(update || !success) {
Miss(ip);
}
return addr;
}
示例13: HandleData
public void HandleData(MemBlock data, ISender return_path, object state)
{
/*
* Write the messages:
*/
Console.WriteLine("Msg from: {0}", return_path);
data.ToMemoryStream().WriteTo( System.Console.OpenStandardOutput() );
Console.WriteLine();
return_path.Send( new CopyList(PType.Protocol.Chat, MemBlock.Null) );
}
示例14: DataPacket
public DataPacket(ICopyable packet) {
_update_icpacket = false;
_update_packet = false;
_icpacket = packet;
_packet = packet as MemBlock;
if(_packet == null) {
_update_packet = true;
}
}
示例15: Free
/// <summary>
/// 释放
/// </summary>
/// <param name="block"></param>
public void Free(MemBlock block)
{
if (block.GetBytes() == null)
return;
int nIndex = GetIndex(block.GetMaxLength());
if (nIndex >= mMaxList)
return;
mAllMemList[nIndex].Enqueue(block);
}