protected override bool SendData(byte[] buffer, object state) { var message = new MqttApplicationMessageBuilder() .WithTopic(topic) .WithPayload(buffer) .WithExactlyOnceQoS() .Build(); if (!mqttClient.PublishAsync(message).Wait(TIMEOUT, cancellationToken.Token)) { var e = new TimeoutException(); Tracker.LogE(TAG, e); using (new MethodUtils.Unlocker(this)) { OnExceptionCallback?.Invoke(e); } return(false); } using (new MethodUtils.Unlocker(this)) { OnSendCompletedCallback?.Invoke(state); } return(true); }
/// <summary> /// 异步连接 /// </summary> private async Task ConnectAsync() { while (true) { try { // 连接 await mqttClient.ConnectAsync(options, cancellationToken.Token); using (new MethodUtils.Unlocker(this)) { OnConnectedCallback?.Invoke(); } return; } catch (Exception e) { Tracker.LogNW(TAG, "connect fail"); using (new MethodUtils.Unlocker(this)) { OnExceptionCallback?.Invoke(e); } await Task.Delay(TimeSpan.FromMilliseconds(RETRY_DURATION)); } } }
private static extern void SetOnExceptionCallback(IntPtr videoPlayerPtr, OnExceptionCallback callback, IntPtr callback_arg);
private static void SetOnExceptionCallback(IntPtr videoPlayerPtr, OnExceptionCallback callback, IntPtr callback_arg) { Debug.Log(NOT_IMPLEMENTED_MSG); }
private void OnException(Exception e) { using (new MethodUtils.Unlocker(this)) { OnExceptionCallback?.Invoke(e); } }