using System;
using System.Threading.Tasks;
using JiShe.CollectBus.Exceptions;
using Microsoft.Extensions.Logging;
using TouchSocket.Core;
using TouchSocket.Sockets;

namespace JiShe.CollectBus.Plugins
{
    public partial class TcpCloseMonitor(ILogger<TcpCloseMonitor> logger) : PluginBase, ITcpReceivedPlugin
    {

        public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
        {
            try
            {
                await e.InvokeNext();
            }
            catch (CloseException ex)
            {
                logger.LogInformation("拦截到CloseException");
                await client.CloseAsync(ex.Message);
            }
            catch (Exception exx)
            {

            }
            finally
            {

            }
        }
    }

    public partial class UdpCloseMonitor(ILogger<TcpCloseMonitor> logger) : PluginBase, IUdpReceivedPlugin
    {
        public Task OnUdpReceived(IUdpSessionBase client, UdpReceivedDataEventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}
