void AirXRCameraRigManager.PredictionEventHandler.OnProfileDataReceived(AirXRCameraRig cameraRig, byte[] cbor)
    {
        if (bypassPrediction || _zmqReportEndpoint == null)
        {
            return;
        }

        _msg.InitPool(cbor.Length);
        Array.Copy(cbor, _msg.Data, _msg.Data.Length);

        _zmqReportEndpoint.TrySend(ref _msg, TimeSpan.Zero, false);
    }
示例#2
0
        private void SendingMain()
        {
            log.Info("Started the sending thread.");
            Volatile.Write(ref this.sendingState, RUNNING);
            var msg = new Msg();

            msg.InitPool(this.maxFrameSize);
            var spinWait = new SpinWait();

            using (var pushSocket = new PushSocket(this.outgoingConnection))
            {
                while (Volatile.Read(ref this.sendingState) == RUNNING)
                {
                    try
                    {
                        var body = msg.Data;
                        if (this.sendingQueue.TryPoll(out var envelope))
                        {
                            this.encoder.Encode(envelope, ref body);
                            if (!pushSocket.TrySend(ref msg, new TimeSpan(0, 0, 15), false))
                            {
                                log.Error("Unable to send a message.");
                            }

                            // Reset the buffer.
                            msg.InitPool(this.maxFrameSize);
                        }
                        else
                        {
                            spinWait.SpinOnce();
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex, ex.Message);
                    }
                }
            }

            Volatile.Write(ref this.sendingState, STOPPED);
            log.Info("Sending thread has stopped.");
        }
 public void Send(
     PushSocket pushSocket,
     IEnvelopFactory <TPayloadType, TBody> envelopFactory,
     IEncoder <TPayloadType, TBody> encoder,
     Msg msg,
     int maxFrameSize)
 {
     envelopFactory.CreateEnvelops(
         this.message,
         (envelope) =>
     {
         var array = msg.Data;
         encoder.Encode(envelope, ref array);
         if (!pushSocket.TrySend(ref msg, timeOut, false))
         {
             log.Error($"Failed to send a message.");
         }
         msg.InitPool(maxFrameSize);
     });
 }