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

namespace NewLife.Model;

/// <summary>处理器上下文</summary>
public interface IHandlerContext //: IExtend
{
    /// <summary>管道</summary>
    IPipeline? Pipeline { get; set; }

    /// <summary>上下文拥有者</summary>
    Object? Owner { get; set; }

    /// <summary>读取管道过滤后最终处理消息</summary>
    /// <param name="message"></param>
    void FireRead(Object message);

    /// <summary>写入管道过滤后最终处理消息</summary>
    /// <param name="message"></param>
    Int32 FireWrite(Object message);
}

/// <summary>处理器上下文</summary>
public class HandlerContext : IHandlerContext, IExtend
{
    #region 属性
    /// <summary>管道</summary>
    public IPipeline? Pipeline { get; set; }

    /// <summary>上下文拥有者</summary>
    public Object? Owner { get; set; }

    /// <summary>数据项</summary>
    public IDictionary<String, Object?> Items { get; } = new NullableDictionary<String, Object?>();

    /// <summary>设置 或 获取 数据项</summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public Object? this[String key] { get => Items.TryGetValue(key, out var obj) ? obj : null; set => Items[key] = value; }
    #endregion

    #region 方法
    /// <summary>读取管道过滤后最终处理消息</summary>
    /// <param name="message"></param>
    public virtual void FireRead(Object message) { }

    /// <summary>写入管道过滤后最终处理消息</summary>
    /// <param name="message"></param>
    public virtual Int32 FireWrite(Object message) => 0;
    #endregion
}