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


C# IO.DataFragment类代码示例

本文整理汇总了C#中Granados.IO.DataFragment的典型用法代码示例。如果您正苦于以下问题:C# DataFragment类的具体用法?C# DataFragment怎么用?C# DataFragment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Close

        public void Close(Cipher cipher, Random rnd, MAC mac, int sequence, DataFragment result) {
            if(!_is_open) throw new SSHException("internal state error");
            
            int blocksize = cipher==null? 8 : cipher.BlockSize;
            int payload_length = _writer.Length - (SEQUENCE_MARGIN + LENGTH_MARGIN + PADDING_MARGIN);
            int r = 11 - payload_length % blocksize;
            while(r < 4) r += blocksize;
            _paddingLength = r;
            _packetLength = PADDING_MARGIN + payload_length + _paddingLength;
            int image_length = _packetLength + LENGTH_MARGIN;

            //fill padding
            for(int i=0; i<_paddingLength; i+=4)
                _writer.Write(rnd.Next());

            //manipulate stream
            byte[] rawbuf = _writer.UnderlyingBuffer;
            SSHUtil.WriteIntToByteArray(rawbuf, 0, sequence);
            SSHUtil.WriteIntToByteArray(rawbuf, SEQUENCE_MARGIN, _packetLength);
            rawbuf[SEQUENCE_MARGIN + LENGTH_MARGIN] = (byte)_paddingLength;

            //mac
            if(mac!=null) {
                _mac = mac.ComputeHash(rawbuf, 0, _packetLength+LENGTH_MARGIN+SEQUENCE_MARGIN);
                Array.Copy(_mac, 0, rawbuf, _packetLength+LENGTH_MARGIN+SEQUENCE_MARGIN, _mac.Length);
                image_length += _mac.Length;
            }

            //encrypt
            if(cipher!=null)
                cipher.Encrypt(rawbuf, SEQUENCE_MARGIN, _packetLength+LENGTH_MARGIN, rawbuf, SEQUENCE_MARGIN);

            result.Init(rawbuf, SEQUENCE_MARGIN, image_length);
            _is_open = false;
        }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:35,代码来源:SSH2Packet.cs

示例2: SSH2Connection

        private int _requiredResponseCount; //for keyboard-interactive authentication

        internal SSH2Connection(SSHConnectionParameter param, AbstractGranadosSocket strm, ISSHConnectionEventReceiver r, string serverversion, string clientversion) : base(param, strm, r) {
            _cInfo = new SSH2ConnectionInfo();
            _cInfo._serverVersionString = serverversion;
            _cInfo._clientVersionString = clientversion;
            
            _packetReceiver = new SynchronizedPacketReceiver(this);
            _packetBuilder = new SSH2PacketBuilder(_packetReceiver);
            _transmissionPacket = new SSH2TransmissionPacket();
            _transmissionImage = new DataFragment(null, 0, 0);
        }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:12,代码来源:SSH2Connection.cs

示例3: Append

		public void Append(DataFragment data) {
			if(_length==0) {
    			AssureCapacity(RoundUp(data.Length));
    			Array.Copy(data.Data, data.Offset, _data, 0, data.Length);
                _offset = 0;
				_length = data.Length;
			}
			else {
				Append(data.Data, data.Offset, data.Length);
			}
		}
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:11,代码来源:DataFragment.cs

示例4: Init

 private void Init(DataFragment data)
 {
     _data = data.Data;
     _offset = data.Offset;
     _limit = _offset + data.Length;
 }
开发者ID:FNKGino,项目名称:poderosa,代码行数:6,代码来源:ReaderWriter.cs

示例5: OnData

 public void OnData(DataFragment data)
 {
     _connection.AsyncReceivePacket(data);
 }
开发者ID:FNKGino,项目名称:poderosa,代码行数:4,代码来源:SSH1Packet.cs

示例6: SneakPacketType

 private SSH1PacketType SneakPacketType(DataFragment data)
 {
     return (SSH1PacketType)data[0];
 }
开发者ID:yiyi99,项目名称:poderosa,代码行数:4,代码来源:SSH1Connection.cs

示例7: StartReceivingThread

        public void StartReceivingThread(Action<DataFragment> onDataCallback, Action onClosedCallback)
        {
            if (_socket == null || _receivingThread != null) {
                return;
            }

            _receivingThread = new Thread(() => {
                byte[] buffer = new byte[0x20000];
                DataFragment dataFrag = new DataFragment(buffer, 0, 0);

                try {
                    while (true) {
                        int received = _socket.Receive(buffer, 0, buffer.Length, SocketFlags.None);
                        if (received > 0) {
                            dataFrag.SetLength(0, received);
                            onDataCallback(dataFrag);
                        }
                    }
                }
                catch (Exception e) {
                    if (!_shutdown) {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                        System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    }

                    if (!_socket.Connected && !_shutdown) {
                        // closed by the peer
                        onClosedCallback();
                    }
                }
            });
            _receivingThread.Start();
        }
开发者ID:poderosaproject,项目名称:poderosa,代码行数:33,代码来源:X11Socket.cs

示例8: SSH2MsgNewKeys

 public SSH2MsgNewKeys(DataFragment data, Handler onDequeued)
     : base(data.Data, data.Offset, data.Length)
 {
     _onDequeued = onDequeued;
 }
开发者ID:FNKGino,项目名称:poderosa,代码行数:5,代码来源:SSH2Packet.cs

示例9: IsMsgNewKeys

 private bool IsMsgNewKeys(DataFragment packet)
 {
     return packet.Length >= 1 && packet.ByteAt(0) == (byte)PacketType.SSH_MSG_NEWKEYS;
 }
开发者ID:FNKGino,项目名称:poderosa,代码行数:4,代码来源:SSH2Packet.cs

示例10: FilterData

 /// <summary>
 /// Handle data instead of the core handler.
 /// </summary>
 /// <param name="data">data</param>
 protected abstract void FilterData(DataFragment data);
开发者ID:poderosaproject,项目名称:poderosa,代码行数:5,代码来源:Socket.cs

示例11: OnData

 /// <summary>
 /// Implements <see cref="IDataHandler"/>
 /// </summary>
 /// <param name="data"></param>
 public void OnData(DataFragment data)
 {
     FilterData(data);
 }
开发者ID:poderosaproject,项目名称:poderosa,代码行数:8,代码来源:Socket.cs

示例12: Write

 public void Write(DataFragment data)
 {
     Write(data.Data, data.Offset, data.Length);
 }
开发者ID:yiyi99,项目名称:poderosa,代码行数:4,代码来源:DataFragment.cs

示例13: MakeView

 /// <summary>
 /// Make another view of this instance.
 /// </summary>
 /// <param name="startIndex">start index for the new view.</param>
 public DataFragment MakeView(int startIndex)
 {
     if (startIndex < 0 || startIndex > _length) {
         throw new ArgumentOutOfRangeException();
     }
     DataFragment newInstance = new DataFragment(_data, _offset + startIndex, _length - startIndex);
     return newInstance;
 }
开发者ID:yiyi99,项目名称:poderosa,代码行数:12,代码来源:DataFragment.cs

示例14: Dump

 // for debug
 private void Dump(string caption, DataFragment data)
 {
     Dump(caption, data.Data, data.Offset, data.Length);
 }
开发者ID:poderosaproject,项目名称:poderosa,代码行数:5,代码来源:SCPChannelStream.cs

示例15: OnData

 public override void OnData(DataFragment data)
 {
     #if DUMP_PACKET
     Dump("SCP: OnData", data);
     #endif
     if (_dataHandler != null) {
         _dataHandler(data);
     }
 }
开发者ID:poderosaproject,项目名称:poderosa,代码行数:9,代码来源:SCPChannelStream.cs


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