Пример #1
0
            protected int onReceive(object cbArg, LBMMessage msg)
            {
                switch (msg.type())
                {
                case LBM.MSG_DATA:
                    IntPtr messagePtr = msg.dataPointerSafe();

                    if (bufferAcquiredSize != msg.length())
                    {
                        if (bufferAcquiredSize >= 0)
                        {
                            source.buffsCancel();
                        }

                        // assume that the payload size is correctly checked on the pinger size
                        bufferAcquiredSize =
                            (source.buffAcquire(out bufferAcquired, (uint)msg.length(), 0) == 0)
                                            ? (int)msg.length() : -1;
                    }
#if RunUnsafeMode
                    dqwordBlockCopy(bufferAcquired.ToPointer(), messagePtr.ToPointer(), (int)msg.length());
#else
                    memcpy(bufferAcquired, messagePtr, (int)msg.length());
#endif
                    source.buffsCompleteAndAcquire(out bufferAcquired, (uint)bufferAcquiredSize, 0);
                    break;

                case LBM.MSG_BOS:
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source()
                                                   + "], Beginning of Transport Session");
                    break;

                case LBM.MSG_EOS:
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source()
                                                   + "], End of Transport Session");
                    break;

                case LBM.MSG_UNRECOVERABLE_LOSS:
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source() + "]["
                                                   + msg.sequenceNumber() + "], LOST");
                    /* Any kind of loss makes this test invalid */
                    System.Console.WriteLine("Unrecoverable loss occurred.  Quitting...");
                    System.Environment.Exit(1);
                    break;

                case LBM.MSG_UNRECOVERABLE_LOSS_BURST:
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source() + "], LOST BURST");
                    /* Any kind of loss makes this test invalid */
                    System.Console.WriteLine("Unrecoverable loss occurred.  Quitting...");
                    System.Environment.Exit(1);
                    break;

                default:
                    System.Console.Out.WriteLine("Unhandled receiver event [" + msg.type() + "] from source [" + msg.source() + "] with topic [" + msg.topicName() + "]. Refer to https://ultramessaging.github.io/currdoc/doc/dotnet_example/index.html#unhandledcsevents for a detailed description.");
                    break;
                }

                msg.dispose();
                return(0);
            }
Пример #2
0
            protected int onReceive(object cbArg, LBMMessage msg)
            {
                switch (msg.type())
                {
                case LBM.MSG_DATA:
                    try
                    {
                        if (++bounce_count < NUM_ROUNDTRIPS_PER_MSG)
                        {
                            // Bounce the message -- no need to size check
                            IntPtr messagePtr = msg.dataPointerSafe();
#if RunUnsafeMode
                            dqwordBlockCopy(bufferAcquired.ToPointer(), messagePtr.ToPointer(), (int)msg.length());
#else
                            memcpy(bufferAcquired, messagePtr, (int)msg.length());
#endif
                            source.buffsCompleteAndAcquire(out bufferAcquired, (uint)buffer.Length, 0);
                        }
                        else
                        {
                            tsend[rcvd_msgs] = getTicks();

                            bounce_count = 0;
                            if (rcvd_msgs > lbmlatping.NUM_MSGS)
                            {       // still doing statistics report (throw away the extraneous message)
                                break;
                            }
                            if (latping.usBusyWaitPause > 0)
                            {
                                // Busy wait for at least requested microseconds.
                                long tstarget = tsend[rcvd_msgs] + nanosToTicks(latping.usBusyWaitPause * 1000);
                                while (tstarget > getTicks())
                                {
                                    ;
                                }
                            }

                            tsstart[rcvd_msgs + 1] = getTicks();
#if RunUnsafeMode
                            fixed(void *buff = buffer)
                            {
                                dqwordBlockCopy(bufferAcquired.ToPointer(), buff, buffer.Length);
                            }
#else
                            memcpy(bufferAcquired, bufferptr, (int)buffer.Length);
#endif
                            source.buffsCompleteAndAcquire(out bufferAcquired, (uint)buffer.Length, 0);

                            if (rcvd_msgs++ == lbmlatping.NUM_MSGS)
                            {
                                int      i;
                                double   min = Double.MaxValue, max = 0;
                                int      max_idx    = -1;
                                double[] elapsed_ts = new double[lbmlatping.NUM_MSGS - lbmlatping.NUM_MSGS_IGNORED];

                                System.Console.Out.WriteLine("Successfully sent & received " + lbmlatping.NUM_MSGS + " total "
                                                             + buffer.Length + "-byte messages, ignoring the first "
                                                             + lbmlatping.NUM_MSGS_IGNORED + " messages.");
                                System.Console.Out.WriteLine("Round-trip times in nanoseconds.");

                                for (i = lbmlatping.NUM_MSGS_IGNORED; i < lbmlatping.NUM_MSGS; i++)
                                {
                                    elapsed_ts[i - lbmlatping.NUM_MSGS_IGNORED] =
                                        ((double)ticksToNanos(tsend[i] - tsstart[i])) / NUM_ROUNDTRIPS_PER_MSG;
                                    if (elapsed_ts[i - lbmlatping.NUM_MSGS_IGNORED] < min)
                                    {
                                        min = elapsed_ts[i - lbmlatping.NUM_MSGS_IGNORED];
                                    }
                                    else if (elapsed_ts[i - lbmlatping.NUM_MSGS_IGNORED] > max)
                                    {
                                        max     = elapsed_ts[i - lbmlatping.NUM_MSGS_IGNORED];
                                        max_idx = i - lbmlatping.NUM_MSGS_IGNORED;
                                    }
                                }
                                /* Now calculate some summary statistics. */
                                lbmStatistics stats = new lbmStatistics();
                                Array.Sort(elapsed_ts);
                                stats.calcSummaryStats(elapsed_ts);

                                string output = String.Format("Min: {0:0.00}, Max {1:0.00}", min, max);
                                System.Console.Out.WriteLine(output);

                                output = String.Format("Mean: {0:0.00}, Median: {1:0.00}, Standard Dev: {2:0.00}",
                                                       stats.mean, stats.data[stats.data.Length / 2], stats.sample_sd);
                                System.Console.Out.WriteLine(output);

                                output = String.Format("99.9%: {0:#.00}, 99%: {1:0.00}, 95%: {2:0.00}, 90%: {3:0.00}, 80%: {4:0.00}",
                                                       stats.data[(stats.data.Length * 999) / 1000],
                                                       stats.data[(stats.data.Length * 99) / 100],
                                                       stats.data[(stats.data.Length * 95) / 100],
                                                       stats.data[(stats.data.Length * 9) / 10],
                                                       stats.data[(stats.data.Length * 8) / 10]);
                                System.Console.Out.WriteLine(output);

                                /* We're done. */
                                Environment.Exit(0);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Console.Out.WriteLine(e.ToString());
                    }
                    break;

                case LBM.MSG_BOS:
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source()
                                                   + "], Beginning of Transport Session");
                    break;

                case LBM.MSG_EOS:
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source()
                                                   + "], End of Transport Session");
                    break;

                case LBM.MSG_UNRECOVERABLE_LOSS:
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source() + "]["
                                                   + msg.sequenceNumber() + "], LOST");
                    /* Any kind of loss makes this test invalid */
                    System.Console.WriteLine("Unrecoverable loss occurred.  Quitting...");
                    System.Environment.Exit(1);
                    break;

                case LBM.MSG_UNRECOVERABLE_LOSS_BURST:
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source() + "], LOST BURST");
                    /* Any kind of loss makes this test invalid */
                    System.Console.WriteLine("Unrecoverable loss occurred.  Quitting...");
                    System.Environment.Exit(1);
                    break;

                default:
                    System.Console.Out.WriteLine("Unhandled receiver event [" + msg.type() + "] from source [" + msg.source() + "] with topic [" + msg.topicName() + "]. Refer to https://ultramessaging.github.io/currdoc/doc/dotnet_example/index.html#unhandledcsevents for a detailed description.");
                    break;
                }

                msg.dispose();
                return(0);
            }
Пример #3
0
        protected int onReceive(object cbArg, LBMMessage msg)
        {
            long t;

            if (_ping)
            {
                t = System.Diagnostics.Stopwatch.GetTimestamp() * lbmpong.pspertick / 1000;
            }
            else
            {
                t = 0;
            }
            switch (msg.type())
            {
            case LBM.MSG_DATA:
                if (rtt_ignore == 0)
                {
                    _msg_count++;
                }

                byte[] message    = null;
                IntPtr messagePtr = (IntPtr)0;
                long   s          = 0;
                if (use_smx)
                {
                    messagePtr = msg.dataPointerSafe();
                }
                else
                {
                    message = msg.data();
                }

                if (_ping)
                {
                    s = (use_smx) ? lbmpong.parse_s(messagePtr, 0) : lbmpong.parse_s(message, 0);
                    calc_latency(t, s);
                    if (rtt_ignore == 0 && _msg_count == _msgs)
                    {
                        rtt_avg_usec = ((double)total_nsec / 1000.0) / (double)_msg_count;

                        print_rtt_data();

                        print_latency(System.Console.Out);

                        try {
                            print_stats();
                        }
                        catch (LBMException ex) {
                            System.Console.Error.WriteLine("Error printing transport stats in ponglbmreceiver"
                                                           + ex.Message);
                        }

                        end();

                        msg.dispose();

                        return(0);
                    }
                    if (_msecpause > 0)
                    {
                        // This would not normally be a good
                        // thing in a callback on the context
                        // thread.
                        System.Threading.Thread.Sleep(_msecpause);
                    }
                    if (!use_smx)
                    {
                        lbmpong.format(message, 0,
                                       System.Diagnostics.Stopwatch.GetTimestamp() * lbmpong.pspertick / 1000);
                    }
                }
                if (use_mim)
                {
                    _ctx.send(_ping ? "lbmpong/ping" : "lbmpong/pong", message,
                              message.Length, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
                }
                else if (use_smx)
                {
                    try
                    {
                        IntPtr writeBuff;
                        if (_src.buffAcquire(out writeBuff, (uint)msg.length(), 0) == 0)
                        {
                            if (_ping)
                            {
                                lbmpong.format(writeBuff, 0,
                                               System.Diagnostics.Stopwatch.GetTimestamp() * lbmpong.pspertick / 1000);
                            }
                            else
                            {
                                memcpy(writeBuff, messagePtr, (int)msg.length());
                            }
                            _src.buffsComplete();
                        }
                    }
                    catch (LBMException ex)
                    {
                        System.Console.Error.WriteLine("Error (while doing SMX acquire/complete): " + ex.Message);
                        System.Environment.Exit(1);
                    }
                }
                else
                {
                    _src.send(message, message.Length, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
                }

                if (_ping && _verbose)
                {
                    System.Console.Out.WriteLine(_msg_count + " curr " + t + " sent " + s
                                                 + " latency " + (t - s) + " ns");
                }
                if (rtt_ignore > 0)
                {
                    rtt_ignore--;
                }
                break;

            case LBM.MSG_BOS:
                System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source()
                                               + "], Beginning of Transport Session");
                break;

            case LBM.MSG_EOS:
                System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source()
                                               + "], End of Transport Session");
                if (_end_on_eos)
                {
                    end();
                }
                break;

            case LBM.MSG_UNRECOVERABLE_LOSS:
                if (_verbose)
                {
                    System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source() + "]["
                                                   + msg.sequenceNumber() + "], LOST");
                }
                /* Any kind of loss makes this test invalid */
                System.Console.WriteLine("Unrecoverable loss occurred.  Quitting...");
                System.Environment.Exit(1);
                break;

            case LBM.MSG_UNRECOVERABLE_LOSS_BURST:
                System.Console.Error.WriteLine("[" + msg.topicName() + "][" + msg.source() + "], LOST BURST");
                /* Any kind of loss makes this test invalid */
                System.Console.WriteLine("Unrecoverable loss occurred.  Quitting...");
                System.Environment.Exit(1);
                break;

            default:
                System.Console.Out.WriteLine("Unhandled receiver event [" + msg.type() + "] from source [" + msg.source() + "] with topic [" + msg.topicName() + "]. Refer to https://ultramessaging.github.io/currdoc/doc/dotnet_example/index.html#unhandledcsevents for a detailed description.");
                break;
            }
            msg.dispose();
            System.Console.Out.Flush();
            return(0);
        }