Skip to content

Commit

Permalink
update to v1.5.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
beetlex-io committed Sep 9, 2020
1 parent ce62901 commit b684032
Show file tree
Hide file tree
Showing 15 changed files with 246 additions and 112 deletions.
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,60 @@ samples/Protobuf.Server/obj/
samples/Http.Server/Properties/
samples/Http.Server/bin/
samples/Http.Server/obj/
samples/TCP.FixedString/.vs/
samples/TCP.FixedString/Client/bin/
samples/TCP.FixedString/Client/obj/
samples/TCP.FixedString/Server/bin/
samples/TCP.FixedString/Server/obj/
samples/TCP.Hello/.vs/
samples/TCP.Hello/Client/bin/
samples/TCP.Hello/Client/obj/
samples/TCP.Hello/Server/bin/
samples/TCP.Hello/Server/obj/
samples/TCP.JsonFormater/.vs/
samples/TCP.JsonFormater/Client/bin/
samples/TCP.JsonFormater/Client/obj/
samples/TCP.JsonFormater/Messages/bin/
samples/TCP.JsonFormater/Messages/obj/
samples/TCP.JsonFormater/Server/bin/
samples/TCP.JsonFormater/Server/obj/
samples/TCP.MessagePackFormater/.vs/
samples/TCP.MessagePackFormater/Client/bin/
samples/TCP.MessagePackFormater/Client/obj/
samples/TCP.MessagePackFormater/Messages/bin/
samples/TCP.MessagePackFormater/Messages/obj/
samples/TCP.MessagePackFormater/Server/bin/
samples/TCP.MessagePackFormater/Server/obj/
samples/TCP.ProtobufFormater/.vs/
samples/TCP.ProtobufFormater/Client/bin/
samples/TCP.ProtobufFormater/Client/obj/
samples/TCP.ProtobufFormater/Messages/bin/
samples/TCP.ProtobufFormater/Messages/obj/
samples/TCP.ProtobufFormater/Server/bin/
samples/TCP.ProtobufFormater/Server/obj/
samples/TCP.SSL/.vs/
samples/TCP.SSL/Client/bin/
samples/TCP.SSL/Client/obj/
samples/TCP.SSL/Messages/bin/
samples/TCP.SSL/Messages/obj/
samples/TCP.SSL/Server/bin/
samples/TCP.SSL/Server/obj/
samples/TCP.BaseHttp/.vs/
samples/TCP.BaseHttp/TCP.BaseHttp/bin/
samples/TCP.BaseHttp/TCP.BaseHttp/obj/
samples/TCP.BaseHttp/TCP.BaseHttp/Properties/
samples/TCP.AsynClient/.vs/
samples/TCP.AsynClient/Client/bin/
samples/TCP.AsynClient/Client/obj/
samples/TCP.AsynClient/Server/bin/
samples/TCP.AsynClient/Server/obj/
samples/TCP.Awaiter/.vs/
samples/TCP.Awaiter/Client/bin/
samples/TCP.Awaiter/Client/obj/
samples/TCP.Awaiter/Server/bin/
samples/TCP.Awaiter/Server/obj/
samples/TCP.BaseHttp/TCP.BaseHttp/TCP.BaseHttp.csproj.user
samples/TCP.FixedString/Server/Properties/
samples/TCP.FixedString/Server/Server.csproj.user
.vs/BeetleX/v16/
.vs/BeetleX/DesignTimeBuild/.dtbcache.v2
Binary file modified .vs/BeetleX/v15/.suo
Binary file not shown.
6 changes: 3 additions & 3 deletions src/BeetleX/BeetleX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<Authors>henryfan</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<AssemblyVersion>1.5.1.6</AssemblyVersion>
<FileVersion>1.5.1.6</FileVersion>
<Version>1.5.1.6</Version>
<AssemblyVersion>1.5.3.2</AssemblyVersion>
<FileVersion>1.5.3.2</FileVersion>
<Version>1.5.3.2</Version>
<Description>high performance dotnet core socket tcp communication components, support tcp, ssl, http, websocket, rpc, redis ... protocols and 1M connections problem solution</Description>
<Copyright>Copyright © 2019-2020 beetlex.io</Copyright>
<PackageProjectUrl>https://github.com/IKende/BeetleX</PackageProjectUrl>
Expand Down
24 changes: 22 additions & 2 deletions src/BeetleX/Buffers/PipeStreamExtens.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,29 @@ public void Write(StringBuilder data, Encoding encoding = null)
}
}

}

public int Buffers
{
get
{
if (FirstBuffer == null)
{
return 0;
}
else
{
int count = 1;
var buffer = FirstBuffer.Next;
while (buffer != null)
{
count++;
buffer = buffer.Next;
}
return count;
}
}
}

}

}
namespace BeetleX
Expand Down
3 changes: 2 additions & 1 deletion src/BeetleX/Buffers/Pool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,15 @@ public IBuffer Pop()
item = CreateBuffer();
}
item.Reset();
item.Pool = this;
Interlocked.Decrement(ref mCount);
return item;

}

public void Push(IBuffer item)
{
Interlocked.Increment(ref mCount);
item.Pool = null;
mPool.Push(item);
}

Expand Down
2 changes: 1 addition & 1 deletion src/BeetleX/Clients/AwaiterClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AwaiterClient(string host, int port, IClientPacket packet, string sslServ

private static void OnProcess((AwaiterClient client, object result) item)
{
item.client.Success(item.result);
item.client.Success(item.result);
}

private void OnError(IClient c, ClientErrorArgs e)
Expand Down
138 changes: 74 additions & 64 deletions src/BeetleX/Clients/Clients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,17 @@ private void OnConnect()
this.Connected?.Invoke(this);
}

public SslProtocols? SslProtocols { get; set; } = System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls12;

public X509CertificateCollection CertificateCollection { get; private set; } = new X509CertificateCollection();

protected virtual void OnSslAuthenticate(SslStream sslStream)
{
var task = sslStream.AuthenticateAsClientAsync(SslServiceName);
Task task;
if (SslProtocols == null)
SslProtocols = System.Security.Authentication.SslProtocols.Tls | System.Security.Authentication.SslProtocols.Tls11 |
System.Security.Authentication.SslProtocols.Tls12;
task = sslStream.AuthenticateAsClientAsync(SslServiceName, CertificateCollection.Count > 0 ? CertificateCollection : null, SslProtocols.Value, false);
task.Wait();
}

Expand Down Expand Up @@ -621,9 +629,9 @@ public void Init(string host, int port, IClientPacket packet)

private SslStreamX mSslStream = null;

private AwaitObject awaitPipeStream = new AwaitObject();
//private AwaitObject awaitPipeStream = new AwaitObject();

private AwaitObject mReadMessageAwait = new AwaitObject();
//private AwaitObject mReadMessageAwait = new AwaitObject();

private int mPort;

Expand All @@ -635,10 +643,10 @@ public void ProcessError(Exception e_, string message = null)
e.Message = message;
try
{
if (awaitPipeStream.Pending)
awaitPipeStream.Error(e_);
if (mReadMessageAwait.Pending)
mReadMessageAwait.Error(e_);
//if (awaitPipeStream.Pending)
// awaitPipeStream.Error(e_);
//if (mReadMessageAwait.Pending)
// mReadMessageAwait.Error(e_);
ClientError?.Invoke(this, e);
}
catch
Expand All @@ -661,7 +669,7 @@ public void DisConnect()
mSocket = null;
}
mReceiveEventArgs?.Clear();
mReceiveEventArgs?.Dispose();
mReceiveEventArgs?.Dispose();
mReceiveEventArgs = null;
mSendEventArgs?.Clear();
mSendEventArgs?.Dispose();
Expand Down Expand Up @@ -692,14 +700,14 @@ public void DisConnect()
{
}
}
if (awaitPipeStream.Pending)
{
awaitPipeStream.Error(new SocketException((int)SocketError.ConnectionAborted));
}
if (mReadMessageAwait.Pending)
{
mReadMessageAwait.Error(new SocketException((int)SocketError.ConnectionAborted));
}
//if (awaitPipeStream.Pending)
//{
// awaitPipeStream.Error(new SocketException((int)SocketError.ConnectionAborted));
//}
//if (mReadMessageAwait.Pending)
//{
// mReadMessageAwait.Error(new SocketException((int)SocketError.ConnectionAborted));
//}
}

private static void IO_Completed(object sender, SocketAsyncEventArgs e)
Expand Down Expand Up @@ -740,9 +748,9 @@ private void OnReceive()
try
{
mReceiveArgs.Stream = this.Stream;
if (awaitPipeStream.Pending)
awaitPipeStream.Success(this.Stream.ToPipeStream());
else
//if (awaitPipeStream.Pending)
// awaitPipeStream.Success(this.Stream.ToPipeStream());
//else
DataReceive?.Invoke(this, mReceiveArgs);

}
Expand Down Expand Up @@ -918,45 +926,45 @@ protected virtual bool ValidateServerCertificate(object sender, X509Certificate
return false;
}

public AwaitObject ReceiveMessage()
{
mReadMessageAwait.Reset();
bool isconnect;
Connect(out isconnect);
if (Packet == null)
ProcessError(new BXException("packet is empty be cannot receive messages!"), "packet is empty be cannot receive messages");
if (!AutoReceive)
BeginReceive();
return mReadMessageAwait;
}

public AwaitStruct<PipeStream> ReceiveFrom(Action<PipeStream> writeHandler)
{
var result = Receive();
if (writeHandler != null)
{
PipeStream stream = this.Stream.ToPipeStream();
writeHandler(stream);
if (stream.CacheLength > 0)
this.Stream.Flush();
}
return result;
}

public AwaitStruct<T> ReceiveMessage<T>()
{
return new AwaitStruct<T>(ReceiveMessage());
}

public AwaitStruct<PipeStream> Receive()
{
awaitPipeStream.Reset();
bool isconnect;
Connect(out isconnect);
if (!AutoReceive)
BeginReceive();
return new AwaitStruct<PipeStream>(awaitPipeStream);
}
//public AwaitObject ReceiveMessage()
//{
// mReadMessageAwait.Reset();
// bool isconnect;
// Connect(out isconnect);
// if (Packet == null)
// ProcessError(new BXException("packet is empty be cannot receive messages!"), "packet is empty be cannot receive messages");
// if (!AutoReceive)
// BeginReceive();
// return mReadMessageAwait;
//}

//public AwaitStruct<PipeStream> ReceiveFrom(Action<PipeStream> writeHandler)
//{
// var result = Receive();
// if (writeHandler != null)
// {
// PipeStream stream = this.Stream.ToPipeStream();
// writeHandler(stream);
// if (stream.CacheLength > 0)
// this.Stream.Flush();
// }
// return result;
//}

//public AwaitStruct<T> ReceiveMessage<T>()
//{
// return new AwaitStruct<T>(ReceiveMessage());
//}

//public AwaitStruct<PipeStream> Receive()
//{
// awaitPipeStream.Reset();
// bool isconnect;
// Connect(out isconnect);
// if (!AutoReceive)
// BeginReceive();
// return new AwaitStruct<PipeStream>(awaitPipeStream);
//}

public bool Connect(out bool newConnection)
{
Expand Down Expand Up @@ -1029,13 +1037,15 @@ public bool Connect(out bool newConnection)
}
public SslProtocols? SslProtocols { get; set; } = System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls12;

public X509CertificateCollection CertificateCollection { get; private set; } = new X509CertificateCollection();

protected virtual void OnSslAuthenticate(SslStream sslStream)
{
Task task;
if (SslProtocols == null)
task = sslStream.AuthenticateAsClientAsync(SslServiceName);
else
task = sslStream.AuthenticateAsClientAsync(SslServiceName, null, SslProtocols.Value, false);
SslProtocols = System.Security.Authentication.SslProtocols.Tls | System.Security.Authentication.SslProtocols.Tls11 |
System.Security.Authentication.SslProtocols.Tls12;
task = sslStream.AuthenticateAsClientAsync(SslServiceName, CertificateCollection.Count > 0 ? CertificateCollection : null, SslProtocols.Value, false);
task.Wait();
}

Expand Down Expand Up @@ -1234,9 +1244,9 @@ private void OnPacketCompleted(IClient client, object message)
{
try
{
if (mReadMessageAwait.Pending)
mReadMessageAwait.Success(message);
else
//if (mReadMessageAwait.Pending)
// mReadMessageAwait.Success(message);
//else
PacketReceive?.Invoke(this, message);
}
catch (Exception e_)
Expand Down
1 change: 1 addition & 0 deletions src/BeetleX/EventArgs/ServerLogEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public ServerLogEventArgs(string message, LogType type, ISession session = null)

public LogType Type { get; set; }


public string Message
{
get;
Expand Down
4 changes: 4 additions & 0 deletions src/BeetleX/IServerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace BeetleX
public interface IServerHandler
{

IServer Server { get; set; }

void Connecting(IServer server, EventArgs.ConnectingEventArgs e);

void Connected(IServer server, EventArgs.ConnectedEventArgs e);
Expand All @@ -25,5 +27,7 @@ public interface IServerHandler

void SessionDetection(IServer server, SessionDetectionEventArgs e);

void Opened(IServer server);

}
}
2 changes: 2 additions & 0 deletions src/BeetleX/ISession.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Threading.Tasks;

namespace BeetleX
Expand Down Expand Up @@ -37,6 +38,7 @@ bool LittleEndian
get; set;
}

SocketError LastSocketError { get; set; }

Buffers.SocketAsyncEventArgsX SendEventArgs { get; set; }

Expand Down
Loading

0 comments on commit b684032

Please sign in to comment.