async Task HandleConnection() { try { await Handshake(); while (await callQueue.MoveNext(cancel)) { var call = callQueue.Current; await ProcessCall(call); } } catch (Exception e) { logger.LogDebug($"Service client for [{name}] dropped: {e.Message}"); // cancel current call if any if (callQueue.Current != null) { callQueue.Current.Tcs.TrySetException(e); } ClearCalls(e); throw; } finally { logger.LogDebug($"Removing service client for [{name}] from ServiceManagare."); ServiceManager.Instance.RemoveServiceServerLinkAsync(this); } }
async Task HandleConnection() { try { await Handshake().ConfigureAwait(false); while (await callQueue.MoveNext(cancel).ConfigureAwait(false)) { var call = callQueue.Current; await ProcessCall(call).ConfigureAwait(false); } connection.Socket.Shutdown(SocketShutdown.Send); connection.Close(50); } catch (Exception e) { if (!(e is OperationCanceledException)) { logger.LogDebug($"Service client for [{name}] dropped: {e.Message}"); } FlushCallQueue(e); callQueue = new AsyncQueue <CallInfo>(MAX_CALL_QUEUE_LENGTH, true); throw; } finally { logger.LogDebug($"Removing service client for [{name}] from ServiceManagare."); ServiceManager.Instance.RemoveServiceServerLinkAsync(this); } }
private async Task PublishLoopAsync() { using (var publisher = await ROS.GlobalNodeHandle.AdvertiseAsync <Log>("/rosout", 0).ConfigureAwait(false)) { while (await queue.MoveNext(default(CancellationToken)).ConfigureAwait(false)) { Log entry = queue.Current; publisher.Publish(entry); } } }
private async Task RunSendLoopAsync(Header header) { await Task.Yield(); try { // header handshake try { await HandleHeader(header).ConfigureAwait(false); } catch (Exception e) { if (ROS.shuttingDown) { await connection.SendHeaderError("ROS node shutting down", cancel).ConfigureAwait(false); } else { logger.LogWarning(e, e.Message); await connection.SendHeaderError(e.Message, cancel).ConfigureAwait(false); } connection.Close(50); throw; } // read messages from queue and send them while (await outbox.MoveNext(cancel).ConfigureAwait(false)) { cancel.ThrowIfCancellationRequested(); var current = outbox.Current; try { await WriteMessage(current).ConfigureAwait(false); } catch (Exception ex) { // Catch exceptions and log them instead of just ignoring them... ROS.Error()("Error while writing message, not sending. Error: {0}, Stacktrace: {1}", ex.ToString(), ex.StackTrace); throw; } } } finally { UnregisterSubscriberLink(); } }
private async Task RunPublishLoopAsync() { while (await publishQueue.MoveNext(cancel)) { cancel.ThrowIfCancellationRequested(); if (Dropped) { return; } EnqueueMessage(publishQueue.Current); } }
private async Task RunSendLoopAsync(Header header) { await Task.Yield(); try { // header handshake try { await HandleHeader(header); } catch (Exception e) { if (ROS.shuttingDown) { await connection.SendHeaderError("ROS node shutting down", cancel); } else { logger.LogWarning(e, e.Message); await connection.SendHeaderError(e.Message, cancel); } connection.Close(50); throw; } // read messages from queue and send them while (await outbox.MoveNext(cancel)) { cancel.ThrowIfCancellationRequested(); var current = outbox.Current; await WriteMessage(current); } } finally { UnregisterSubscriberLink(); } }
protected override Task <bool> MoveNextInternal(CancellationToken cancel) { return(queue.MoveNext(cancel)); }