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); }
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); }