Compare commits

...

5 Commits
master ... v10

9 changed files with 42 additions and 20 deletions

View File

@ -2,11 +2,11 @@ name: publish-beta
on:
push:
branches: [ master, dev, v10 ]
branches: [ master, dev ]
paths:
- 'NewLife.Core/**'
pull_request:
branches: [ master, dev, v10 ]
branches: [ master, dev ]
paths:
- 'NewLife.Core/**'
workflow_dispatch:

View File

@ -265,7 +265,7 @@ public class Packet
{
//if (Offset == 0 && (Count < 0 || Offset + Count == Data.Length) && Next == null) return Data;
if (Next == null) Data.ReadBytes(Offset, Count);
if (Next == null) return Data.ReadBytes(Offset, Count);
// 链式包输出
var ms = Pool.MemoryStream.Get();

View File

@ -2,7 +2,6 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml.Linq;
using NewLife.Configuration;
using NewLife.Log;
@ -212,7 +211,7 @@ public static class ProcessHelper
{
if (process == null || process.GetHasExited()) return process;
XTrace.WriteLine("安全温柔一刀PID={0}/{1}", process.Id, process.ProcessName);
//XTrace.WriteLine("安全温柔一刀PID={0}/{1}", process.Id, process.ProcessName);
try
{
@ -250,7 +249,7 @@ public static class ProcessHelper
{
if (process == null || process.GetHasExited()) return process;
XTrace.WriteLine("强杀大力出奇迹PID={0}/{1}", process.Id, process.ProcessName);
//XTrace.WriteLine("强杀大力出奇迹PID={0}/{1}", process.Id, process.ProcessName);
// 终止指定的进程及启动的子进程,如nginx等
// 在Core 3.0, Core 3.1, 5, 6, 7, 8, 9 中支持此重载
@ -260,6 +259,7 @@ public static class ProcessHelper
#else
process.Kill();
#endif
if (process.GetHasExited()) return process;
try
{
@ -359,7 +359,14 @@ public static class ProcessHelper
if (msWait < 0)
p.WaitForExit();
else if (!p.WaitForExit(msWait))
{
#if NETCOREAPP
p.Kill(true);
#else
p.Kill();
#endif
return -1;
}
return p.ExitCode;
}
@ -428,7 +435,11 @@ public static class ProcessHelper
if (msWait > 0 && !process.WaitForExit(msWait))
{
#if NETCOREAPP
process.Kill(true);
#else
process.Kill();
#endif
return null;
}

View File

@ -134,7 +134,7 @@ public class WebSocket
{
var session = (Context?.Connection) ?? throw new ObjectDisposedException(nameof(Context));
var msg = new WebSocketMessage { Type = type, Payload = data };
session.Host.SendAllAsync(msg.ToPacket(), predicate);
session.Host.SendAllAsync(msg.ToPacket(), predicate).Wait();
}
/// <summary>想所有连接发送文本消息</summary>

View File

@ -213,6 +213,10 @@ public class NetUri
/// <summary>获取该域名下所有IP节点含端口</summary>
/// <returns></returns>
public IPEndPoint[] GetEndPoints() => GetAddresses().Select(e => new IPEndPoint(e, Port)).ToArray();
/// <summary>克隆</summary>
/// <returns></returns>
public NetUri Clone() => new() { Type = Type, Host = Host, Port = Port, Address = Address };
#endregion
#region

View File

@ -85,7 +85,9 @@ public class UdpServer : SessionBase, ISocketServer, ILogFeature
// 启用地址重用后,即使旧进程未退出,新进程也可以监听,但只有旧进程退出后,新进程才能接受对该端口的连接请求
if (ReuseAddress) sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true);
// 无需设置SocketOptionName.PacketInformation在ReceiveMessageFromAsync时会自动设置
//if (sock.AddressFamily == AddressFamily.InterNetwork)
// sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true);
}
catch (Exception ex)
{
@ -218,6 +220,9 @@ public class UdpServer : SessionBase, ISocketServer, ILogFeature
// 每次接收以后,这个会被设置为远程地址,这里重置一下,以防万一
se.RemoteEndPoint = new IPEndPoint(IPAddress.Any.GetRightAny(Local.EndPoint.AddressFamily), 0);
// 在StarAgent中此时可能收到广播包SocketFlags是Broadcast需要清空否则报错“参考的对象类型不支持尝试的操作”
se.SocketFlags = SocketFlags.None;
//return Client.ReceiveFromAsync(se);
return Client.ReceiveMessageFromAsync(se);
}

View File

@ -23,16 +23,8 @@ public class UdpSession : DisposeBase, ISocketSession, ITransport, ILogFeature
/// <summary>底层Socket</summary>
Socket? ISocket.Client => Server?.Client;
///// <summary>数据流</summary>
//public Stream Stream { get; set; }
private NetUri? _Local;
/// <summary>本地地址</summary>
public NetUri Local
{
get => _Local ??= Server.Local;
set => Server.Local = _Local = value;
}
public NetUri Local { get; set; }
/// <summary>端口</summary>
public Int32 Port { get => Local.Port; set => Local.Port = value; }
@ -83,6 +75,7 @@ public class UdpSession : DisposeBase, ISocketSession, ITransport, ILogFeature
Remote = new NetUri(NetType.Udp, remote);
Tracer = server.Tracer;
Local = server.Local.Clone();
if (local != null) Local.Address = local;
// 检查并开启广播

View File

@ -116,7 +116,7 @@ public class Cron
/// <returns></returns>
public Boolean Parse(String expression)
{
var ss = expression.Split(' ');
var ss = expression.Split([' '], StringSplitOptions.RemoveEmptyEntries);
if (ss.Length == 0) return false;
if (!TryParse(ss[0], 0, 60, out var vs)) return false;

View File

@ -24,8 +24,6 @@ public class CronTests
//Assert.False(cron.IsTime(DateTime.Parse("11:01:00 10/12/2008")));
}
[Theory]
[InlineData("*/2")]
[InlineData("* * * * *")]
@ -38,6 +36,17 @@ public class CronTests
[InlineData("1,10,20 * * * *")]
[InlineData("* 1,10,20 * * *")]
[InlineData("* 1-10,13,5/20 * * *")]
[InlineData("*/2 ")]
[InlineData("* * * * *")]
[InlineData("0 * * * *")]
[InlineData("0,1,2 * * * *")]
[InlineData("*/2 * * * * ")]
[InlineData("5/20 * * * *")]
[InlineData("1-4 * * * * ")]
[InlineData("1-55/3 * * * * ")]
[InlineData("1,10,20 * * * *")]
[InlineData(" * 1,10,20 * * *")]
[InlineData(" * 1-10,13,5/20 * * *")]
public void Valid(String expression)
{
var cron = new Cron();