Exemple #1
0
        public static int Main(string[] args)
        {
            lbmlatpong latpong = null;

            LBMContext           ctx      = null;
            LBMContextAttributes ctx_attr = null;

            LBMTopic            pong_src_topic      = null;
            LBMSourceAttributes pong_src_topic_attr = null;
            LBMSource           pong_src            = null;

            LBMTopic ping_rcv_topic = null;
            LBMReceiverAttributes ping_rcv_topic_attr = null;
            lbmlatpongreceiver    ping_rcv            = null;

            latpong = new lbmlatpong(args);
            if (latpong.cpu >= 0)
            {
                Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(latpong.cpu);
            }

            /* Create the context. */
            ctx_attr = new LBMContextAttributes();
            ctx_attr.setValue("resolver_cache", "0");
            ctx_attr.setValue("operational_mode", "sequential");
            ctx_attr.setValue("request_tcp_port_high", "50000");
            ctx_attr.setValue("transport_lbtipc_receiver_thread_behavior", "busy_wait");
            ctx = new LBMContext(ctx_attr);
            ctx_attr.dispose();

            /* Create the pong source. */
            pong_src_topic_attr = new LBMSourceAttributes();
            pong_src_topic_attr.setValue("resolver_advertisement_sustain_interval", "0");
            pong_src_topic_attr.setValue("transport", "lbtsmx");
            pong_src_topic = new LBMTopic(ctx, "lbmlat-pong", pong_src_topic_attr);
            pong_src_topic_attr.dispose();
            pong_src         = new LBMSource(ctx, pong_src_topic);
            latpong.pong_src = pong_src;

            /* Create the ping receiver. */
            ping_rcv_topic_attr = new LBMReceiverAttributes();
            ping_rcv_topic_attr.enableSingleReceiverCallback(true);
            ping_rcv_topic_attr.setSourceNotificationCallbacks(
                new LBMSourceCreationCallback(latpong.onNewSource),
                new LBMSourceDeletionCallback(latpong.onSourceDelete),
                null);
            ping_rcv_topic = new LBMTopic(ctx, "lbmlat-ping", ping_rcv_topic_attr);
            ping_rcv_topic_attr.dispose();
            ping_rcv = new lbmlatpongreceiver(ctx, ping_rcv_topic, latpong, pong_src);

            /* Wait a bit for things to get set up. */
            System.Threading.Thread.Sleep(1000);

            /* Run the context until we've discovered the pinger's source. */
            while (!latpong.found_pinger)
            {
                ctx.processEvents(1000);
            }

            /* Wait a bit for things to get set up. */
            System.Threading.Thread.Sleep(1000);

            /* Send in a dummy pong message to kick things off. */
            IntPtr writeBuff;

            if (pong_src.buffAcquire(out writeBuff, (uint)16, 0) == 0)
            {
                Marshal.WriteInt64(writeBuff, 0, 1234567890);
                pong_src.buffsComplete();
            }

            /* Wait forever. */
            while (true)
            {
                System.Threading.Thread.Sleep(1000000);
                // ctx.processEvents(1000000);
            }
        }
Exemple #2
0
        public static int Main(string[] args)
        {
            lbmlatping latping = null;

            LBMContext           ctx      = null;
            LBMContextAttributes ctx_attr = null;

            LBMTopic            ping_src_topic      = null;
            LBMSourceAttributes ping_src_topic_attr = null;
            LBMSource           ping_src            = null;

            LBMTopic pong_rcv_topic = null;
            LBMReceiverAttributes pong_rcv_topic_attr = null;
            lbmlatpingreceiver    pong_rcv            = null;

            latping = new lbmlatping(args);
            if (latping.cpu >= 0)
            {
                Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(latping.cpu);
            }
            try
            {
                /* Create the context. */
                ctx_attr = new LBMContextAttributes();
                ctx_attr.setValue("resolver_cache", "0");
                ctx_attr.setValue("operational_mode", "sequential");
                ctx_attr.setValue("request_tcp_port_high", "50000");
                ctx = new LBMContext(ctx_attr);
                ctx_attr.dispose();

                /* Create the ping source. */
                ping_src_topic_attr = new LBMSourceAttributes();
                ping_src_topic_attr.setValue("resolver_advertisement_sustain_interval", "0");
                ping_src_topic_attr.setValue("transport", "lbtsmx");
                ping_src_topic = new LBMTopic(ctx, "lbmlat-ping", ping_src_topic_attr);
                ping_src_topic_attr.dispose();
                ping_src         = new LBMSource(ctx, ping_src_topic);
                latping.ping_src = ping_src;

                /* Perform some configuration validation */
                const int smx_header_size  = 16;
                int       max_payload_size =
                    Convert.ToInt32(ping_src.getAttributeValue("transport_lbtsmx_datagram_max_size")) + smx_header_size;
                if (latping.msgbuf.Length > max_payload_size)
                {
                    /* The SMX transport doesn't fragment, so payload must be within maximum size limits */
                    System.Console.WriteLine("Error: Message size requested is larger than configured SMX datagram size.");
                    System.Environment.Exit(1);
                }

                /* Create the pong receiver. */
                pong_rcv_topic_attr = new LBMReceiverAttributes();
                pong_rcv_topic_attr.enableSingleReceiverCallback(true);
                pong_rcv_topic = new LBMTopic(ctx, "lbmlat-pong", pong_rcv_topic_attr);
                pong_rcv_topic_attr.dispose();
                pong_rcv = new lbmlatpingreceiver(ctx, pong_rcv_topic, latping);

                /* Run the context just long enough to advertise. */
                ctx.processEvents(1000);

                /* The ponger kicks things off as soon as he's discovered our ping source. */
                while (true)
                {
                    System.Threading.Thread.Sleep(1000000);
                    //ctx.processEvents(1000000);
                }
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine(e.ToString());
            }
            return(0);
        }