using Best.HTTP.Shared.Streams;
using System;
namespace Best.HTTP.Shared.PlatformSupport.Network.Tcp
{
///
/// The IPeekableContentProvider interface defines an abstraction for providing content to an with the ability to peek at the content without consuming it.
/// It is an essential part of content streaming over a TCP connection.
///
///
///
/// Key Functions of IPeekableContentProvider:
///
///
/// -
/// Content ProvisionIt provides content to an associated without immediately consuming the content. This allows the consumer to examine the data before processing.
///
/// -
/// Two-Way BindingSupports establishing a two-way binding between the and an , enabling bidirectional communication between the provider and consumer.
///
/// -
/// UnbindingProvides methods for unbinding a content consumer, terminating the association between the provider and consumer.
///
///
///
public interface IPeekableContentProvider
{
///
/// Gets the associated with this content provider, which allows peeking at the content without consuming it.
///
PeekableContentProviderStream Peekable { get; }
///
/// Gets the implementor that will be notified through calls when new data is available in the TCPStreamer.
///
IContentConsumer Consumer { get; }
///
/// Sets up a two-way binding between this content provider and an . This enables bidirectional communication between the provider and consumer.
///
/// The to bind to.
void SetTwoWayBinding(IContentConsumer consumer);
///
/// Unbinds the content provider from its associated content consumer. This terminates the association between the provider and consumer.
///
void Unbind();
///
/// Unbinds the content provider from a specific content consumer if it is currently bound to that consumer.
///
/// The to unbind from.
void UnbindIf(IContentConsumer consumer);
///
/// Unbinds the content provider from a specific content consumer if it is currently bound to that consumer, and changes to the new consumer.
///
/// The to unbind from.
/// The to bin to.
void SwitchIf(IContentConsumer from, IContentConsumer to);
}
///
/// The IContentConsumer interface represents a consumer of content provided by an . It defines methods for handling received content and connection-related events.
///
///
///
/// Key Functions of IContentConsumer:
///
///
/// -
/// Content HandlingDefines methods for handling incoming content, allowing consumers to process data as it becomes available.
///
/// -
/// Connection ManagementProvides event methods to notify consumers of connection closure and error conditions, facilitating graceful handling of connection-related issues.
///
///
///
public interface IContentConsumer
{
///
/// Gets the associated with this content consumer, which allows access to incoming content.
///
PeekableContentProviderStream ContentProvider { get; }
///
/// This method should not be called directly. It is used internally to set the binding between the content consumer and its associated content provider.
///
/// The to bind to.
void SetBinding(PeekableContentProviderStream contentProvider);
///
/// This method should not be called directly. It is used internally to unset the binding between the content consumer and its associated content provider.
///
void UnsetBinding();
///
/// Called when new content is available from the associated content provider.
///
void OnContent();
///
/// Called when the connection is closed by the remote peer. It notifies the content consumer about the connection closure.
///
void OnConnectionClosed();
///
/// Called when an error occurs during content processing or connection handling. It provides the exception that caused the error.
///
/// The that represents the error condition.
void OnError(Exception ex);
}
}