using System.Threading.Tasks;

namespace Plane.Communication
{
    /// <summary>
    /// <see cref="IConnection"/> 的空白实现。
    /// </summary>
    public class EmptyConnection : ExceptionThrownEventSource, IConnection
    {
        private EmptyConnection()
        {
        }

        public static EmptyConnection Instance { get; } = new EmptyConnection();

        public bool IsOpen { get; private set; }

        public void Close()
        {
            IsOpen = false;
        }

        public Task OpenAsync()
        {
            IsOpen = true;
            return TaskUtils.CompletedTask;
        }

        public Task<int> ReadAsync(byte[] buffer, int offset, int count)
        {
            return Task.FromResult(count);
        }

        public Task WriteAsync(byte[] buffer, int offset, int count)
        {
            return TaskUtils.CompletedTask;
        }
    }
}
