Skip to content

Commit 18c4e21

Browse files
committed
update to 1.0.3.4
1 parent 7155cd8 commit 18c4e21

16 files changed

+1100
-95
lines changed

.gitignore

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Samples/Base/BaseSample/.vs/
2+
Samples/Base/BaseSample/ClientApp/bin/
3+
Samples/Base/BaseSample/ClientApp/obj/
4+
Samples/Base/BaseSample/ServerApp/bin/
5+
Samples/Base/BaseSample/ServerApp/obj/
6+
Samples/Performance/.vs/
7+
Samples/Performance/ClientApp/Properties/
8+
Samples/Performance/ClientApp/bin/
9+
Samples/Performance/ClientApp/obj/
10+
Samples/Performance/ServerApp/Properties/
11+
Samples/Performance/ServerApp/bin/
12+
Samples/Performance/ServerApp/obj/
13+
Samples/Actors/.vs/
14+
Samples/Actors/Actors/bin/
15+
Samples/Actors/Actors/obj/
16+
Samples/Actors/Client/Properties/
17+
Samples/Actors/Client/bin/
18+
Samples/Actors/Client/obj/
19+
Samples/Actors/Actors/Properties/
20+
Samples/HelloWorld/.vs/
21+
Samples/HelloWorld/HelloWorld.Client/bin/
22+
Samples/HelloWorld/HelloWorld.Client/obj/
23+
Samples/HelloWorld/HelloWorld/bin/
24+
Samples/HelloWorld/HelloWorld/obj/
25+
Samples/SSL/.vs/
26+
Samples/SSL/SSLClient/bin/
27+
Samples/SSL/SSLClient/obj/
28+
Samples/SSL/SSLServer/bin/
29+
Samples/SSL/SSLServer/obj/
30+
Samples/Filters/.vs/
31+
Samples/Filters/FiltersClient/bin/
32+
Samples/Filters/FiltersClient/obj/
33+
Samples/Filters/FiltersServer/bin/
34+
Samples/Filters/FiltersServer/obj/
35+
Samples/Headers/.vs/
36+
Samples/Headers/HeadersClient/bin/
37+
Samples/Headers/HeadersClient/obj/
38+
Samples/Headers/HeadersServer/bin/
39+
Samples/Headers/HeadersServer/obj/
40+
src/.vs/
41+
src/bin/
42+
src/obj/
43+
src/Properties/
44+
samples/XRPC.Actor/.vs/
45+
samples/XRPC.Actor/Client/bin/
46+
samples/XRPC.Actor/Client/obj/
47+
samples/XRPC.Actor/Server/bin/
48+
samples/XRPC.Actor/Server/obj/
49+
samples/XRPC.DI/.vs/
50+
samples/XRPC.DI/Client/obj/
51+
samples/XRPC.DI/Server/bin/
52+
samples/XRPC.DI/Server/obj/
53+
samples/XRPC.Hello/.vs/
54+
samples/XRPC.Hello/Client/bin/
55+
samples/XRPC.Hello/Client/obj/
56+
samples/XRPC.Hello/Server/bin/
57+
samples/XRPC.Hello/Server/obj/
58+
samples/XRPC.InterfaceTwoWay/.vs/
59+
samples/XRPC.InterfaceTwoWay/Client/bin/
60+
samples/XRPC.InterfaceTwoWay/Client/obj/
61+
samples/XRPC.InterfaceTwoWay/Server/bin/
62+
samples/XRPC.InterfaceTwoWay/Server/obj/
63+
samples/XRPC.JWT/.vs/
64+
samples/XRPC.JWT/Client/bin/
65+
samples/XRPC.JWT/Client/obj/
66+
samples/XRPC.JWT/Server/bin/
67+
samples/XRPC.JWT/Server/obj/
68+
samples/XRPC.WFPChat/.vs/
69+
samples/XRPC.WFPChat/Client/bin/
70+
samples/XRPC.WFPChat/Client/obj/
71+
samples/XRPC.WFPChat/packages/
72+
samples/XRPC.WFPChat/Server/bin/
73+
samples/XRPC.WFPChat/Server/obj/
74+
samples/XRPC.WPF/.vs/
75+
samples/XRPC.WPF/Client/bin/
76+
samples/XRPC.WPF/Client/obj/
77+
samples/XRPC.WPF/packages/
78+
samples/XRPC.WPF/Server/bin/
79+
samples/XRPC.WPF/Server/obj/
80+
samples/XRPC.WPF_SSL/.vs/
81+
samples/XRPC.WPF_SSL/Client/bin/
82+
samples/XRPC.WPF_SSL/Client/obj/
83+
samples/XRPC.WPF_SSL/packages/
84+
samples/XRPC.WPF_SSL/Server/bin/
85+
samples/XRPC.WPF_SSL/Server/obj/
86+
samples/XRPC_SSL/.vs/
87+
samples/XRPC_SSL/Client/bin/
88+
samples/XRPC_SSL/Client/obj/
89+
samples/XRPC_SSL/Server/bin/
90+
samples/XRPC_SSL/Server/obj/
91+
samples/XRPC.DelegateInvoke/.vs/
92+
samples/XRPC.DelegateInvoke/Client/bin/
93+
samples/XRPC.DelegateInvoke/Client/obj/
94+
samples/XRPC.DelegateInvoke/packages/
95+
samples/XRPC.DelegateInvoke/Server/bin/
96+
samples/XRPC.DelegateInvoke/Server/obj/

src/BeetleX.XRPC.csproj

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp2.1</TargetFramework>
5-
<Version>0.8.2.3</Version>
5+
<Version>1.0.3.4</Version>
66
<Authors>henryfan</Authors>
77
<Company>ikende.com</Company>
8-
<Copyright>Copyright © beetlex.io 2019-2020 email:[email protected]</Copyright>
9-
<Description>high performance remote interface invoke(RPC) communication components for netcore</Description>
8+
<Copyright>Copyright © 2019-2020 beetlex.io</Copyright>
9+
<Description>high performance remote interface and delegate invoke(RPC) communication components for netcore</Description>
1010
<PackageReleaseNotes>dotnet high performance remote interface invoke(RPC) communication components</PackageReleaseNotes>
1111
<PackageProjectUrl>https://github.com/IKende/XRPC</PackageProjectUrl>
1212
<PackageLicenseUrl></PackageLicenseUrl>
13-
<SignAssembly>true</SignAssembly>
13+
<SignAssembly>false</SignAssembly>
1414
<AssemblyOriginatorKeyFile>XRPC.pfx</AssemblyOriginatorKeyFile>
15+
<LangVersion>7.3</LangVersion>
16+
<AssemblyVersion>1.0.3.4</AssemblyVersion>
17+
<PackageIconUrl>https://raw.githubusercontent.com/IKende/BeetleX/master/beetlexlogo.png</PackageIconUrl>
18+
<FileVersion>1.0.3.4</FileVersion>
1519
</PropertyGroup>
1620

1721
<ItemGroup>
@@ -21,8 +25,8 @@
2125
</ItemGroup>
2226

2327
<ItemGroup>
24-
<PackageReference Include="BeetleX" Version="1.4.8.3" />
25-
<PackageReference Include="EventNext" Version="0.9.7.8" />
28+
<PackageReference Include="BeetleX" Version="1.5.4" />
29+
<PackageReference Include="EventNext" Version="0.9.8" />
2630
<PackageReference Include="MessagePack" Version="2.0.323" />
2731
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
2832
</ItemGroup>

src/Clients/AnyCompletionSource.cs

+17-11
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,29 @@ public void Error(Exception error)
3232

3333
public async void WaitResponse(Task<RPCPacket> task)
3434
{
35-
var response = await task;
36-
if (response.Status != (short)StatusCode.SUCCESS)
35+
try
3736
{
38-
XRPCException error = new XRPCException((string)response.Data[0]);
39-
Error(error);
40-
}
41-
else
42-
{
43-
if (response.Paramters > 0)
37+
var response = await task;
38+
if (response.Status != (short)StatusCode.SUCCESS)
4439
{
45-
object result = response.Data[0];
46-
Success(result);
40+
XRPCException error = new XRPCException((string)response.Data[0]);
41+
Error(error);
4742
}
4843
else
4944
{
50-
Success(new object());
45+
if (response.Paramters > 0)
46+
{
47+
object result = response.Data[0];
48+
Success(result);
49+
}
50+
else
51+
{
52+
Success(new object());
53+
}
5154
}
55+
}catch(Exception e_)
56+
{
57+
Error(e_);
5258
}
5359
}
5460

src/Clients/TcpClientItem.cs

+13-32
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,31 @@ public TcpClientItem(AsyncTcpClient client, XRPCClient xrpc)
1919

2020
public bool Connected => TcpClient.IsConnected;
2121

22-
public long PingTime { get; set; }
23-
24-
25-
public bool TimeOut(long time)
26-
{
27-
return (TimeWatch.GetElapsedMilliseconds() - PingTime) > time;
28-
}
29-
3022
private int mPingStatus = 0;
3123

24+
private int mPingError = 0;
25+
3226
public async void Ping()
3327
{
3428
if (System.Threading.Interlocked.CompareExchange(ref mPingStatus, 1, 0) == 0)
3529
{
36-
if (TcpClient.IsConnected)
30+
try
3731
{
38-
try
39-
{
40-
RPCPacket request = new RPCPacket();
41-
request.Url = "/__System/Ping";
42-
var response = await XRPCClient.SendWait(request, TcpClient, null);
43-
PingTime = TimeWatch.GetElapsedMilliseconds();
44-
}
45-
catch (Exception e_)
46-
{
47-
48-
}
49-
finally
50-
{
51-
if (TimeOut(XRPCClient.PingTimeout * 1000))
52-
{
53-
TcpClient.DisConnect();
54-
bool isnew;
55-
TcpClient.Connect(out isnew);
56-
}
57-
}
32+
RPCPacket request = new RPCPacket();
33+
request.Url = "/__System/Ping";
34+
var response = await XRPCClient.SendWait(request, TcpClient, null);
5835
}
59-
else
36+
catch (Exception e_)
6037
{
61-
PingTime = TimeWatch.GetElapsedMilliseconds();
38+
mPingError++;
39+
if (mPingError > 3)
40+
{
41+
mPingError = 0;
42+
TcpClient.DisConnect();
43+
}
6244
}
6345
System.Threading.Interlocked.Exchange(ref mPingStatus, 0);
6446
}
6547
}
66-
6748
}
6849
}

src/Clients/XRPCClient.cs

+31-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace BeetleX.XRPC.Clients
1414
{
15-
public class XRPCClient
15+
public partial class XRPCClient
1616
{
1717
public EventClientError NetError
1818
{
@@ -123,13 +123,17 @@ protected virtual void OnProcess(RPCPacket response)
123123
response.Status = (short)StatusCode.INNER_ERROR;
124124
response.Data = new object[] { $"{e_.Message}@{e_.StackTrace}" };
125125
}
126-
127126
mAwaiterFactory.Completed(awaitItem, response);
128127
}
129128
else
130129
{
131130
try
132131
{
132+
if (response.Url.IndexOf(DELEGATE_TAG, StringComparison.OrdinalIgnoreCase) == 0)
133+
{
134+
InvokeDelegate(response);
135+
return;
136+
}
133137
//notfound;
134138
var item = Controllers.GetHandler(response.Url);
135139
if (item != null)
@@ -187,19 +191,15 @@ private void InitConnect()
187191
if (mSslServerName == null)
188192
{
189193
client = BeetleX.SocketFactory.CreateClient<BeetleX.Clients.AsyncTcpClient>(
190-
191194
packet, Host, Port);
192195
}
193196
else
194197
{
195198
client = BeetleX.SocketFactory.CreateSslClient<BeetleX.Clients.AsyncTcpClient>(
196-
197199
packet, Host, Port, mSslServerName);
198200
}
199201
client.PacketReceive = OnPacketCompleted;
200202
client.ClientError = OnError;
201-
bool isnew;
202-
client.Connect(out isnew);
203203
mClients.Add(new TcpClientItem(client, this));
204204
}
205205
}
@@ -236,12 +236,16 @@ public void Register<Service>(Service serviceImpl)
236236
Controllers.Register<Service>(serviceImpl);
237237
}
238238

239-
public void Send(RPCPacket request, AsyncTcpClient client = null)
239+
public async Task Send(RPCPacket request, AsyncTcpClient client = null)
240240
{
241241
client = client ?? GetClient();
242242
bool isnew;
243243
if (client.Connect(out isnew))
244244
{
245+
if (isnew)
246+
{
247+
await OnLogin(client);
248+
}
245249
client.Send(request);
246250
System.Threading.Interlocked.Increment(ref mRequests);
247251
}
@@ -251,45 +255,55 @@ public void Send(RPCPacket request, AsyncTcpClient client = null)
251255
}
252256
}
253257

254-
public Task<RPCPacket> SendWait(RPCPacket request, AsyncTcpClient client, Type[] resultType = null)
258+
public async Task<RPCPacket> SendWait(RPCPacket request, AsyncTcpClient client, Type[] resultType = null)
255259
{
256260
client = client ?? GetClient();
257261
bool isnew;
258262
if (client.Connect(out isnew))
259263
{
264+
if (isnew)
265+
{
266+
await OnLogin(client);
267+
}
260268
var result = mAwaiterFactory.Create(request, resultType, TimeOut);
261269
request.ID = result.Item1;
262270
client.Send(request);
263271
System.Threading.Interlocked.Increment(ref mRequests);
264-
return result.Item2.Task;
272+
return await result.Item2.Task;
265273
}
266274
else
267275
{
268276
throw client.LastError;
269277
}
270278
}
279+
271280
#region ping
272281

273282
private System.Threading.Timer mPingTimer;
274283

275-
private int mPingTimeout = 0;
284+
private int mPingTime = 0;
276285

277-
public int PingTimeout
286+
public int PingTime
278287
{
279288
get
280289
{
281-
return mPingTimeout;
290+
return mPingTime;
282291
}
283292
set
284293
{
285-
mPingTimeout = value;
286-
if (mPingTimeout > 0)
287-
mPingTimer.Change(1000, 1000);
294+
mPingTime = value;
295+
if (mPingTime < 1000)
296+
mPingTime = 1000;
297+
if (mPingTime > 0)
298+
mPingTimer.Change(mPingTime, mPingTime);
288299
else
289-
mPingTimer.Change(100000, 100000);
300+
mPingTimer.Change(1000 * 30, 1000 * 30);
290301
}
291302
}
292-
303+
public void Ping()
304+
{
305+
OnPing(null);
306+
}
293307
private void OnPing(object state)
294308
{
295309
foreach (var item in Clients)

0 commit comments

Comments
 (0)