/// <summary> /// Connect this instance to the other end. /// </summary> public async Task ConnectAsync() { LOG.DebugFormat("{0} is connecting", SelfID); if (!m_socket.Connected) { throw new InvalidOperationException("Cannot use socket if not connected"); } try { m_stream = m_socket.GetStream(); await NegotiateConnection(); } catch { try { m_stream.Dispose(); } catch { } finally { m_stream = null; } try { m_socket.Close(); } catch { } try { m_readRequests.Retire(); } catch { } try { m_writeRequests.Retire(); } catch { } throw; } ReaderProcess(m_socket, m_stream, m_readRequests.AsWriteOnly(), SelfID).FireAndForget(); WriterProcess(m_socket, m_stream, m_writeRequests.AsReadOnly(), SelfID).FireAndForget(); }
public static Task RunReader <T>(IChannel <T> channel, IEnumerable <T> values, CounterShim counter) { return(AutomationExtensions.RunTask( new { chan = channel.AsReadOnly() }, async self => { foreach (var v in values) { var r = await self.chan.ReadAsync(); counter.Increment(); if (Comparer <T> .Default.Compare(v, r) != 0) { throw new Exception(string.Format("Got {0} but expected {1}", r, v)); } } } )); }