当前位置: 首页>>代码示例>>C#>>正文


C# ICopyable.CopyTo方法代码示例

本文整理汇总了C#中ICopyable.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# ICopyable.CopyTo方法的具体用法?C# ICopyable.CopyTo怎么用?C# ICopyable.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICopyable的用法示例。


在下文中一共展示了ICopyable.CopyTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Send

 public void Send(ICopyable Data) {
   byte[] data = new byte[Data.Length];
   Data.CopyTo(data, 0);
   MemBlock mdata = MemBlock.Reference(data);
   for(int i = 0; i < _remove_n_ptypes; i++) {
     MemBlock payload = mdata;
     PType.Parse(mdata, out payload);
     mdata = payload;
   }
   Receiver.HandleData(mdata, ReturnPath, State);
 }
开发者ID:xujyan,项目名称:brunet,代码行数:11,代码来源:MockSender.cs

示例2: Send

    ///<summary>All outgoing data filters through here.</summary>
    public void Send(ICopyable data) {
      if(!_active) {
        if(_closed == 1) {
          throw new SendException(false, "SA closed, unable to send!");
        }
        UpdateSH(null, null);
        return;
      }

      // prepare the packet
      SecurityDataMessage sdm = new SecurityDataMessage();
      sdm.SPI = _spi;
      sdm.Data = data as MemBlock;
      if(sdm.Data == null) {
        byte[] b = new byte[data.Length];
        data.CopyTo(b, 0);
        sdm.Data = MemBlock.Reference(b);
      }

      // Encrypt it!
      lock(_sync) {
        _current_sh.SignAndEncrypt(sdm);
      }

      // Prepare for sending and send over the underlying ISender!
      data = new CopyList(SecurityOverlord.Security, SecurityOverlord.SecureData, sdm.ICPacket);
      try {
        _sender.Send(data);
        _running = true;
      } catch (Exception e) {
        Close("Failed on sending");
        throw new SendException(false, "Failed on sending closing...", e);
      }
    }
开发者ID:johnynek,项目名称:brunet,代码行数:35,代码来源:SecurityAssociation.cs

示例3: Send

  public void Send(ICopyable data) {
    /*
     * Assemble an AHPacket:
     */
    if( _header == null ) {
      AHHeader ahh = new AHHeader(_hops, _ttl, _source, _dest, _options);
      _header = MemBlock.Copy(new CopyList( PType.Protocol.AH, ahh));
      _header_length = _header.Length;
    }
    byte[] ah_packet;
    int packet_length;
    int packet_offset;

    //Try to get the shared BufferAllocator, useful when
    //we don't know how big the data is, which in general
    //is just as expensive as doing a CopyTo...
    BufferAllocator ba = Interlocked.Exchange<BufferAllocator>(ref _buf_alloc, null);
    if( ba != null ) {
      try {
        ah_packet = ba.Buffer;
        packet_offset = ba.Offset;
        int tmp_off = packet_offset;
        tmp_off += _header.CopyTo(ah_packet, packet_offset);
        tmp_off += data.CopyTo(ah_packet, tmp_off);
        packet_length = tmp_off - packet_offset;
        ba.AdvanceBuffer(packet_length);
      }
      catch(System.Exception x) {
        throw new SendException(false, "could not write the packet, is it too big?", x);
      }
      finally {
        //Put the BA back
        Interlocked.Exchange<BufferAllocator>(ref _buf_alloc, ba);
      }
    }
    else {
      //Oh well, someone else is using the buffer, just go ahead
      //and allocate new memory:
      packet_offset = 0;
      packet_length = _header_length + data.Length;
      ah_packet = new byte[ packet_length ];
      int off_to_data = _header.CopyTo(ah_packet, 0);
      data.CopyTo(ah_packet, off_to_data);
    }
    MemBlock mb_packet = MemBlock.Reference(ah_packet, packet_offset, packet_length);
    /*
     * Now we announce this packet, the AHHandler will
     * handle routing it for us
     */
    _n.HandleData(mb_packet, _from, this);
  }
开发者ID:johnynek,项目名称:brunet,代码行数:51,代码来源:AHSender.cs

示例4: Copy

 /**
  * Copy an ICopyable object into a MemBlock.  You might do this
  * if you wanted to access the i^th byte, something you can't do with
  * ICopyable
  */
 public static MemBlock Copy(ICopyable c) {
   int l = c.Length;
   if( l != 0 ) {
     byte[] buffer = new byte[l];
     c.CopyTo(buffer, 0);
     return new MemBlock(buffer, 0, buffer.Length);
   }
   else {
     return _null;
   }
 }
开发者ID:xujyan,项目名称:brunet,代码行数:16,代码来源:MemBlock.cs

示例5: Send

        /// <summary>Writes the data to the Ethernet device.</summary>
        /// <remarks>The same max MTU byte array is always used to write the data to
        /// the device.  Since the incoming data is an ICopyable, it needs to be copied
        /// to a single byte array before being sent to the unmanaged language.
        /// </remarks>
        /// <param name="data">ICopyable of the data to be written.</param>
        public void Send(ICopyable data)
        {
            int length = 0, n = 0;
              lock(_send_buffer) {
            length = data.CopyTo(_send_buffer, 0);
            n = _tap.Write(_send_buffer, length);
              }

              if(n != length) {
            if(_running) {
              ProtocolLog.WriteIf(IpopLog.TapLog, String.Format(
            "TAP: Didn't write all data ... only {0} / {1}", n, length));
            }
              }
        }
开发者ID:arjunprakash84,项目名称:ipop,代码行数:21,代码来源:Ethernet.cs

示例6: HandleEdgeSend

    public void HandleEdgeSend(Edge from, ICopyable p) {
      if(_ploss_prob > 0) {
        if(_rand.NextDouble() < _ploss_prob) {
          return;
        }
      }

      MemBlock mb = p as MemBlock;
      if(mb == null) {
        int offset = p.CopyTo(_ba.Buffer, _ba.Offset);
        mb = MemBlock.Reference(_ba.Buffer, _ba.Offset, offset);
        _ba.AdvanceBuffer(offset);
        _bytes += offset;
      }

      SimulationEdge se_from = (SimulationEdge)from;
      SimulationEdge se_to = se_from.Partner;
      if(se_to != null) {
        se_to.Push(mb);
      }
    }
开发者ID:bakriy,项目名称:brunet,代码行数:21,代码来源:SimulationEdgeListener.cs

示例7: HandleOutgoing

    override protected bool HandleOutgoing(ICopyable app_data, out ICopyable data)
    {
      MemBlock buffer = null;
      data = null;
      int written = 1;
      lock(_buffer_sync) {
        if(app_data != null) {
          int count = app_data.CopyTo(_buffer, 0);
          written = _ssl.Write(_buffer, count);
        }

        if(written > 0) {
          int count = _write.Read(_buffer, _buffer.Length);
          if(count <= 0) {
            // This really shouldn't ever happen
            ProtocolLog.WriteIf(ProtocolLog.SecurityExceptions, this + " error");
            data = null;
            return false;
          }

          buffer = MemBlock.Copy(_buffer, 0, count);
        }
      }

      if(written > 0) {
        // Timer becomes -1 when there are no more control messages
        long to = _ssl.GetTimeout();
        if(to >= 0) {
          HandleWouldBlock();
        }

        if(buffer != null) {
          data = new CopyList(PType, Header, buffer);
          return true;
        }
      }

      // If the write failed, then Dtls is either waiting for a control message
      // or has a control message to send
      var error = _ssl.GetError(written);
      if(error == SslError.SSL_ERROR_WANT_READ) {
        HandleWouldBlock();
      } else if(error == SslError.SSL_ERROR_SSL) {
        var ose = new OpenSslException();
        Close("Received unrecoverable error: " + ose.ToString());
        throw ose;
      } else {
        ProtocolLog.WriteIf(ProtocolLog.SecurityExceptions, "Send other");
      }
      data = null;
      return false;
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:52,代码来源:DtlsAssociation.cs

示例8: HandleEdgeSend

    public void HandleEdgeSend(Edge from, ICopyable p) {
      SimulationEdge se_from = (SimulationEdge)from;
      if(!Nat.Outgoing(se_from.RemoteTA)) {
        return;
      }

      if(_ploss_prob > 0) {
        if(_rand.NextDouble() < _ploss_prob) {
          return;
        }
      }

      MemBlock mb = p as MemBlock;
      if(mb == null) {
        int offset = p.CopyTo(_ba.Buffer, _ba.Offset);
        mb = MemBlock.Reference(_ba.Buffer, _ba.Offset, offset);
        _ba.AdvanceBuffer(offset);
        _bytes += offset;
      }

      SimulationEdge se_to = se_from.Partner;
      if(se_to == null) {
        return;
      }

      if(!se_to.SimEL.Nat.Incoming(se_from.LocalTA)) {
        return;
      }

      se_to.Push(mb);
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:31,代码来源:SimulationEdgeListener.cs

示例9: HandleData

 public void HandleData(AHHeader header, ICopyable payload, ISender ret_path, object st) {
   AHState state = _state; //Read the state, it can't change after the read
   Connection next_con;
   //Check to see if we can use a Leaf connection:
   int dest_idx = state.Leafs.IndexOf(header.Destination);
   if( dest_idx >= 0 ) {
     next_con = state.Leafs[dest_idx];
   } else {
     var alg = state.GetRoutingAlgo(header);
     Pair<Connection, bool> result = alg.NextConnection(ret_path as Edge, header);
     if( result.Second ) {
       //Send a response exactly back to the node that sent to us
       var resp_send = new AHSender(_n, ret_path, header.Source, 
                                      AHSender.DefaultTTLFor(_n.NetworkSize),
                                      AHHeader.Options.Exact, header.Hops);
       MemBlock data = payload as MemBlock;
       if(data == null) {
         // Try to get the shared BufferAllocator, useful when we don't know
         // how big the data is, which in general is just as expensive as
         // doing a CopyTo...
         BufferAllocator ba = Interlocked.Exchange<BufferAllocator>(ref _ba, null);
         if( ba != null ) {
           try {
             int length = payload.CopyTo(ba.Buffer, ba.Offset);
             data = MemBlock.Reference(ba.Buffer, ba.Offset, length);
             ba.AdvanceBuffer(length);
           } catch(System.Exception x) {
             throw new SendException(false, "could not write the packet, is it too big?", x);
           } finally {
             Interlocked.Exchange<BufferAllocator>(ref _ba, ba);
           }
         } else {
           data = MemBlock.Copy(payload);
         }
       }
       _n.HandleData( data, resp_send, this); 
     }
     next_con = result.First;
   }
   //Send it on:
   if( next_con != null ) {
     //Now we do the sending:
     var new_packet = new CopyList(PType.Protocol.AH,
                                   header.IncrementHops(),
                                   payload);
     try {
       next_con.State.Edge.Send(new_packet);
     }
     catch(SendException) {
       //Just drop the packet...
     }
   }
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:53,代码来源:AHSender.cs

示例10: HandleEdgeSend

 /**
  * When UdpEdge objects call Send, it calls this packet
  * callback:
  * @todo The previous interface did not throw an exception to a user
  * since the send was called in another thread.  All code that calls this
  * could be updated to handle exceptions that the socket might throw.
  */
 public void HandleEdgeSend(Edge from, ICopyable p) {
   UdpEdge sender = (UdpEdge) from;
   lock(_send_sync) {
     //Write the IDs of the edge:
     //[local id 4 bytes][remote id 4 bytes][packet]
     NumberSerializer.WriteInt(sender.ID, _send_buffer, 0);
     NumberSerializer.WriteInt(sender.RemoteID, _send_buffer, 4);
     int plength = p.CopyTo(_send_buffer, 8);
     try {
       _s.SendTo(_send_buffer, 8 + plength, SocketFlags.None, sender.End);
     }
     catch(Exception x) {
       bool transient = (1 == _running);
       throw new SendException(transient, String.Format("Problem sending on: {0}",sender), x);
     }
   }
 }
开发者ID:johnynek,项目名称:brunet,代码行数:24,代码来源:UdpEdgeListener.cs

示例11: Send

 /**
 <summary>Writes the data to the Ethernet device.</summary>
 <remarks>The same max MTU byte array is always used to write the data to
 the device.  Since the incoming data is an ICopyable, it needs to be copied
 to a single byte array before being sent to the unmanaged language.
 </remarks>
 <param name="data">ICopyable of the data to be written.</param>
  */
 public void Send(ICopyable data)
 {
     int length = data.CopyTo(_send_buffer, 0);
       int n = send_tap(fd, _send_buffer, length);
       if(n != length) {
     if(_running) {
       ProtocolLog.WriteIf(ProtocolLog.Exceptions, String.Format(
     "TAP: Didn't write all data ... only {0} / {1}", n, length));
     }
       }
 }
开发者ID:kyungyonglee,项目名称:ipop,代码行数:19,代码来源:Ethernet.cs

示例12: HandleOutgoing

    ///<summary>All outgoing data filters through here.</summary>
    override protected bool HandleOutgoing(ICopyable app_data, out ICopyable data)
    {
      if(!_active) {
        if(_closed == 1) {
          throw new SendException(false, "SA closed, unable to send!");
        }
        UpdateSH(null, null);
        data = null;
        return false;
      }

      // prepare the packet
      SecurityDataMessage sdm = new SecurityDataMessage();
      sdm.SPI = _spi;
      sdm.Data = app_data as MemBlock;
      if(sdm.Data == null) {
        byte[] b = new byte[app_data.Length];
        app_data.CopyTo(b, 0);
        sdm.Data = MemBlock.Reference(b);
      }

      // Encrypt it!
      lock(_sync) {
        _current_sh.SignAndEncrypt(sdm);
      }

      data = new CopyList(PeerSecOverlord.Security, PeerSecOverlord.SecureData, sdm.ICPacket);
      return true;
    }
开发者ID:hseom,项目名称:brunet,代码行数:30,代码来源:PeerSecAssociation.cs

示例13: WriteToBuffer

 /**
  * The caller must make sure that this is synchronized, it is not
  * a thread-safe method
  * This method either writes the whole packet into the buffer space,
  * or it throws an exception.  There is no other case.
  */
 public void WriteToBuffer(ICopyable p) {
   int plength = p.CopyTo(_buffer, _written + 2);
   if( plength > Int16.MaxValue ) {
     throw new EdgeException(true,
                 String.Format("Packet too long: {0}",plength));
   }
   // 
   //The length at the beginning:
   NumberSerializer.WriteShort((short)plength, _buffer, _written);
   //Also write the length at the end so we can detect a bad packet
   //as we have seen on planetlab:
   NumberSerializer.WriteShort((short)plength, _buffer, _written + 2 + plength);
   //If the buffer did not fill up, we have not yet thrown an exception:
   _written += (plength + 4);
 }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:21,代码来源:TcpEdge.cs

示例14: HandleEdgeSend

 /// <summary>Used to send data over Xmpp using the specified XmppEdge.</summary>
 public void HandleEdgeSend(Edge from, ICopyable data)
 {
   XmppEdge xe = from as XmppEdge;
   byte[] msg = new byte[xe.Header.Length + data.Length];
   xe.Header.CopyTo(msg, 0);
   data.CopyTo(msg, xe.Header.Length);
   _xmpp.SendTo(new XmppRelay(new XmlDocument(), msg), xe.To);
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:9,代码来源:XmppEdgeListener.cs

示例15: WriteToBuffer

 /**
  * The caller must make sure that this is synchronized, it is not
  * a thread-safe method
  * This method either writes the whole packet into the buffer space,
  * or it throws an exception.  There is no other case.
  */
 public void WriteToBuffer(ICopyable p) {
   int plength = p.CopyTo(_buffer, _written + 2);
   if( plength > Int16.MaxValue ) {
     throw new EdgeException(true,
                 String.Format("Packet too long: {0}",plength));
   }
   //Now we're safe, nothing can go wrong:
   NumberSerializer.WriteShort((short)plength, _buffer, _written);
   _written += (plength + 2);
 }
开发者ID:xujyan,项目名称:brunet,代码行数:16,代码来源:TcpEdge.cs


注:本文中的ICopyable.CopyTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。