コード例 #1
0
ファイル: Packet.cs プロジェクト: iridinite/wirefox
        public Packet(PacketCommand cmd, [CanBeNull] byte[] payload)
        {
            // to pass the buffer to unmanaged code, we need to memcpy it to an unmanaged buffer
            var length = payload?.Length ?? 0;
            var buffer = IntPtr.Zero;

            try {
                // payload may be null, in which case we pass nullptr to C++
                if (payload != null)
                {
                    buffer = Marshal.AllocHGlobal(length);
                    Marshal.Copy(payload, 0, buffer, length);
                }

                m_handle  = NativeMethods.wirefox_packet_create((byte)cmd, buffer, new UIntPtr((uint)length));
                m_cmd     = cmd;
                m_sender  = PeerID.Invalid;
                m_payload = payload;
            } finally {
                if (buffer != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(buffer);
                }
            }
        }
コード例 #2
0
ファイル: Packet.cs プロジェクト: iridinite/wirefox
        internal Packet(IntPtr handle)
        {
            m_handle = handle;
            m_cmd    = (PacketCommand)NativeMethods.wirefox_packet_get_cmd(handle);
            m_sender = new PeerID(NativeMethods.wirefox_packet_get_sender(handle));

            var dataptr = NativeMethods.wirefox_packet_get_data(handle);

            if (dataptr == IntPtr.Zero)
            {
                // nullptr payload is allowed
                m_payload = new byte[0];
            }
            else
            {
                // copy payload of correct length over to managed land
                m_payload = new byte[NativeMethods.wirefox_packet_get_length(handle).ToUInt32()];
                Marshal.Copy(NativeMethods.wirefox_packet_get_data(handle), m_payload, 0, m_payload.Length);
            }
        }
コード例 #3
0
ファイル: Peer.cs プロジェクト: iridinite/wirefox
 public void DisconnectImmediate(PeerID who)
 {
     NativeMethods.wirefox_peer_disconnect_immediate(m_handle, who);
 }
コード例 #4
0
ファイル: Peer.cs プロジェクト: iridinite/wirefox
 public uint Send(Packet packet, PeerID recipient, PacketOptions options, PacketPriority priority = PacketPriority.MEDIUM)
 {
     return(NativeMethods.wirefox_peer_send(m_handle, packet.GetHandle(), recipient, options, priority, 0));
 }
コード例 #5
0
ファイル: Peer.cs プロジェクト: iridinite/wirefox
 public void Disconnect(PeerID who, TimeSpan linger)
 {
     NativeMethods.wirefox_peer_disconnect(m_handle, who, (uint)linger.TotalMilliseconds);
 }
コード例 #6
0
ファイル: Peer.cs プロジェクト: iridinite/wirefox
 public void Disconnect(PeerID who)
 {
     Disconnect(who, TimeSpan.FromMilliseconds(200));
 }
コード例 #7
0
ファイル: Peer.cs プロジェクト: iridinite/wirefox
 public ulong GetStat(PeerID who, PeerStatID stat)
 {
     return((ulong)NativeMethods.wirefox_peer_get_stat(m_handle, who, stat));
 }
コード例 #8
0
ファイル: Peer.cs プロジェクト: iridinite/wirefox
 public bool GetPingAvailable(PeerID who)
 {
     return(NativeMethods.wirefox_peer_get_ping_available(m_handle, who));
 }
コード例 #9
0
ファイル: Peer.cs プロジェクト: iridinite/wirefox
 public int GetPing(PeerID who)
 {
     return((int)NativeMethods.wirefox_peer_get_ping(m_handle, who));
 }