Ejemplo n.º 1
0
 public static unsafe void SendGossip(string topic, ReadOnlySpan <byte> data)
 {
     byte[] topicUtf8 = Encoding.UTF8.GetBytes(topic);
     fixed(byte *topicUtf8Ptr = topicUtf8)
     fixed(byte *dataPtr = data)
     {
         Mothra.SendGossip(topicUtf8Ptr, topicUtf8.Length, dataPtr, data.Length);
     }
 }
Ejemplo n.º 2
0
        public static unsafe void Start(string[] clientConstants, string[] args)
        {
            s_handlers = new Handlers();

            // MothraInterop.DiscoveredPeer discoveredPeer = new MothraInterop.DiscoveredPeer(OnDiscoveredPeer);
            // MothraInterop.ReceiveGossip receiveGossip = new MothraInterop.ReceiveGossip(OnReceiveGossip);
            // MothraInterop.ReceiveRpc receiveRpc = new MothraInterop.ReceiveRpc(OnReceiveRpc);
            s_discoveredPeer = new Mothra.DiscoveredPeer(s_handlers.OnDiscoveredPeer);
            s_receiveGossip  = new Mothra.ReceiveGossip(s_handlers.OnReceiveGossip);
            s_receiveRpc     = new Mothra.ReceiveRpc(s_handlers.OnReceiveRpc);

            // as delegates
            // s_discoveredPeerHandle = GCHandle.Alloc(discoveredPeer);
            // s_receiveGossipHandle = GCHandle.Alloc(receiveGossip);
            // s_receiveRpcHandle = GCHandle.Alloc(receiveRpc);
            s_discoveredPeerHandle = GCHandle.Alloc(s_discoveredPeer);
            s_receiveGossipHandle  = GCHandle.Alloc(s_receiveGossip);
            s_receiveRpcHandle     = GCHandle.Alloc(s_receiveRpc);

            // as pointers
            // IntPtr discoveredPeerPtr = Marshal.GetFunctionPointerForDelegate(discoveredPeer);
            // IntPtr receiveGossipPtr = Marshal.GetFunctionPointerForDelegate(receiveGossip);
            // IntPtr receiveRpcPtr = Marshal.GetFunctionPointerForDelegate(receiveRpc);
            // s_discoveredPeerHandle = GCHandle.Alloc(discoveredPeerPtr, GCHandleType.Pinned);
            // s_receiveGossipHandle = GCHandle.Alloc(receiveGossipPtr, GCHandleType.Pinned);
            // s_receiveRpcHandle = GCHandle.Alloc(receiveRpcPtr, GCHandleType.Pinned);

            // as static field pointers
            // s_discoveredPeerPtr = Marshal.GetFunctionPointerForDelegate(discoveredPeer);
            // s_receiveGossipPtr = Marshal.GetFunctionPointerForDelegate(receiveGossip);
            // s_receiveRpcPtr = Marshal.GetFunctionPointerForDelegate(receiveRpc);
            // s_discoveredPeerHandle = GCHandle.Alloc(s_discoveredPeerPtr, GCHandleType.Pinned);
            // s_receiveGossipHandle = GCHandle.Alloc(s_receiveGossipPtr, GCHandleType.Pinned);
            // s_receiveRpcHandle = GCHandle.Alloc(s_receiveRpcPtr, GCHandleType.Pinned);

            //MothraInterop.RegisterHandlers(discoveredPeer, receiveGossip, receiveRpc);
            Mothra.RegisterHandlers(s_discoveredPeer, s_receiveGossip, s_receiveRpc);
            Thread.Sleep(1000);
            //MothraInterop.RegisterHandlers(discoveredPeerPtr, receiveGossipPtr, receiveRpcPtr);
            // MothraInterop.RegisterHandlers(s_discoveredPeerPtr, s_receiveGossipPtr, s_receiveRpcPtr);

            s_args = GCHandle.Alloc(args);
            Mothra.Start(clientConstants, clientConstants.Length, args, args.Length);
        }