[fix]修正UdpServer在接收广播时连续启动接收的错误,在StarAgent中,此时可能收到广播包,SocketFlags是Broadcast,需要清空,否则报错“参考的对象类型不支持尝试的操作”; 无需设置SocketOptionName.PacketInformation,在ReceiveMessageFromAsync时会自动设置,并且支持ipv6;
石头 编写于 2024-10-10 00:36:00 石头 提交于 2024-10-10 00:45:43
X
using System.Runtime.InteropServices;

namespace NewLife;

/// <summary>泛型事件参数</summary>
/// <typeparam name="TArg"></typeparam>
[Serializable]
[ComVisible(true)]
public class EventArgs<TArg> : EventArgs
{
    /// <summary>参数</summary>
    public TArg Arg { get; set; }

    /// <summary>使用参数初始化</summary>
    /// <param name="arg"></param>
    public EventArgs(TArg arg) => Arg = arg;

    /// <summary>弹出</summary>
    /// <param name="arg"></param>
    public void Pop(ref TArg arg) => arg = Arg;
}

/// <summary>泛型事件参数</summary>
/// <typeparam name="TArg1"></typeparam>
/// <typeparam name="TArg2"></typeparam>
public class EventArgs<TArg1, TArg2> : EventArgs
{
    /// <summary>参数</summary>
    public TArg1 Arg1 { get; set; }

    /// <summary>参数2</summary>
    public TArg2 Arg2 { get; set; }

    /// <summary>使用参数初始化</summary>
    /// <param name="arg1"></param>
    /// <param name="arg2"></param>
    public EventArgs(TArg1 arg1, TArg2 arg2)
    {
        Arg1 = arg1;
        Arg2 = arg2;
    }

    /// <summary>弹出</summary>
    /// <param name="arg1"></param>
    /// <param name="arg2"></param>
    public void Pop(ref TArg1 arg1, ref TArg2 arg2)
    {
        arg1 = Arg1;
        arg2 = Arg2;
    }
}

/// <summary>泛型事件参数</summary>
/// <typeparam name="TArg1"></typeparam>
/// <typeparam name="TArg2"></typeparam>
/// <typeparam name="TArg3"></typeparam>
public class EventArgs<TArg1, TArg2, TArg3> : EventArgs
{
    /// <summary>参数</summary>
    public TArg1 Arg1 { get; set; }

    /// <summary>参数2</summary>
    public TArg2 Arg2 { get; set; }

    /// <summary>参数3</summary>
    public TArg3 Arg3 { get; set; }

    /// <summary>使用参数初始化</summary>
    /// <param name="arg1"></param>
    /// <param name="arg2"></param>
    /// <param name="arg3"></param>
    public EventArgs(TArg1 arg1, TArg2 arg2, TArg3 arg3)
    {
        Arg1 = arg1;
        Arg2 = arg2;
        Arg3 = arg3;
    }

    /// <summary>弹出</summary>
    /// <param name="arg1"></param>
    /// <param name="arg2"></param>
    /// <param name="arg3"></param>
    public void Pop(ref TArg1 arg1, ref TArg2 arg2, ref TArg3 arg3)
    {
        arg1 = Arg1;
        arg2 = Arg2;
        arg3 = Arg3;
    }
}

/// <summary>泛型事件参数</summary>
/// <typeparam name="TArg1"></typeparam>
/// <typeparam name="TArg2"></typeparam>
/// <typeparam name="TArg3"></typeparam>
/// <typeparam name="TArg4"></typeparam>
public class EventArgs<TArg1, TArg2, TArg3, TArg4> : EventArgs
{
    /// <summary>参数</summary>
    public TArg1 Arg1 { get; set; }

    /// <summary>参数2</summary>
    public TArg2 Arg2 { get; set; }

    /// <summary>参数3</summary>
    public TArg3 Arg3 { get; set; }

    /// <summary>参数4</summary>
    public TArg4 Arg4 { get; set; }

    /// <summary>使用参数初始化</summary>
    /// <param name="arg1"></param>
    /// <param name="arg2"></param>
    /// <param name="arg3"></param>
    /// <param name="arg4"></param>
    public EventArgs(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
    {
        Arg1 = arg1;
        Arg2 = arg2;
        Arg3 = arg3;
        Arg4 = arg4;
    }

    /// <summary>弹出</summary>
    /// <param name="arg1"></param>
    /// <param name="arg2"></param>
    /// <param name="arg3"></param>
    /// <param name="arg4"></param>
    public void Pop(ref TArg1 arg1, ref TArg2 arg2, ref TArg3 arg3, ref TArg4 arg4)
    {
        arg1 = Arg1;
        arg2 = Arg2;
        arg3 = Arg3;
        arg4 = Arg4;
    }
}