/// <summary> /// Initializes a new instance of the <see cref="Stream"/> class. /// </summary> /// <param name="client">The client for which the stream belongs.</param> /// <param name="id">The unique identifier of the stream within the tor session.</param> /// <param name="target">The target of the stream.</param> internal Stream(Client client, int id, Host target) { this.circuitID = 0; this.client = client; this.id = id; this.purpose = StreamPurpose.None; this.reason = StreamReason.None; this.status = StreamStatus.None; this.target = target; }
/// <summary> /// Closes an existing stream within the tor service. /// </summary> /// <param name="stream">The stream which should be closed.</param> /// <param name="reason">The reason for the stream being closed.</param> /// <returns><c>true</c> if the stream was closed successfully; otherwise, <c>false</c>.</returns> public bool CloseStream(Stream stream, StreamReason reason) { if (stream == null) { throw new ArgumentNullException("stream"); } if (stream.ID == 0) { throw new ArgumentException("The stream has an invalid ID", "stream"); } if (reason == StreamReason.None || reason == StreamReason.End || reason == StreamReason.PrivateAddr) { throw new ArgumentOutOfRangeException("reason", "The reason for closure cannot be None, End or PrivateAddr"); } CloseStreamCommand command = new CloseStreamCommand(stream, reason); Response response = command.Dispatch(client); return(response.Success); }
/// <summary> /// Initializes a new instance of the <see cref="CloseStreamCommand"/> class. /// </summary> /// <param name="stream">The stream which should be closed.</param> /// <param name="reason">The reason for the stream being closed.</param> public CloseStreamCommand(Stream stream, StreamReason reason) { this.reason = reason; this.stream = stream; }