/// <summary> /// Opens the connection. /// </summary> public async Task Open(CancellationToken cancellationToken) { if (State != RnetConnectionState.Closed) throw new RnetConnectionException("Connection is not closed."); // establish connection await Connect(cancellationToken); // obtain reader reader = GetReader(); if (reader == null) throw new RnetException("Unable to obtain RnetReader."); // obtain writer writer = GetWriter(); if (writer == null) throw new RnetException("Unable to obtain RnetWriter."); OnStateChanged(new RnetConnectionStateEventArgs(State)); }
/// <summary> /// Closes the connection. /// </summary> public async Task Close(CancellationToken cancellationToken) { Contract.Requires<RnetConnectionException>(State == RnetConnectionState.Open, "Connection is not open."); Contract.Ensures(reader == null); Contract.Ensures(writer == null); // disconnect await Disconnect(cancellationToken); reader = null; writer = null; OnStateChanged(new RnetConnectionStateEventArgs(State)); }