Skip to content

Commit

Permalink
refactoring the awaiter with sync context
Browse files Browse the repository at this point in the history
  • Loading branch information
gaochundong committed Sep 7, 2017
1 parent d30ae65 commit 55787c5
Show file tree
Hide file tree
Showing 50 changed files with 154 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<Link>SolutionVersion.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tcp\Server\RIO\InternalTcpSocketRioServerMessageDispatcherImplementation.cs" />
<Compile Include="Tcp\Server\RIO\ITcpSocketRioServerMessageDispatcher.cs" />
<Compile Include="Tcp\Server\RIO\DefaultTcpSocketRioServerEventDispatcher.cs" />
<Compile Include="Tcp\Server\RIO\ITcpSocketRioServerEventDispatcher.cs" />
<Compile Include="Tcp\Server\RIO\RioSharp\Kernel32.cs" />
<Compile Include="Tcp\Server\RIO\RioSharp\RioBufferSegment.cs" />
<Compile Include="Tcp\Server\RIO\RioSharp\RioConnectionlessSocket.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

namespace Cowboy.Sockets.Experimental
{
internal class InternalTcpSocketRioServerMessageDispatcherImplementation : ITcpSocketRioServerMessageDispatcher
internal class DefaultTcpSocketRioServerEventDispatcher : ITcpSocketRioServerEventDispatcher
{
private Func<TcpSocketRioSession, byte[], int, int, Task> _onSessionDataReceived;
private Func<TcpSocketRioSession, Task> _onSessionStarted;
private Func<TcpSocketRioSession, Task> _onSessionClosed;

public InternalTcpSocketRioServerMessageDispatcherImplementation()
public DefaultTcpSocketRioServerEventDispatcher()
{
}

public InternalTcpSocketRioServerMessageDispatcherImplementation(
public DefaultTcpSocketRioServerEventDispatcher(
Func<TcpSocketRioSession, byte[], int, int, Task> onSessionDataReceived,
Func<TcpSocketRioSession, Task> onSessionStarted,
Func<TcpSocketRioSession, Task> onSessionClosed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Cowboy.Sockets.Experimental
{
public interface ITcpSocketRioServerMessageDispatcher
public interface ITcpSocketRioServerEventDispatcher
{
Task OnSessionStarted(TcpSocketRioSession session);
Task OnSessionDataReceived(TcpSocketRioSession session, byte[] data, int offset, int count);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace RioSharp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace RioSharp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RioSharp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RioSharp
namespace RioSharp
{
public class RioConnectionlessSocketPool : RioSocketPool
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security;
using System.Threading;
using System.Threading.Tasks;

namespace RioSharp
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Cowboy.Buffer;
using Logrila.Logging;
using RioSharp;

Expand All @@ -20,7 +19,7 @@ public class TcpSocketRioServer : IDisposable
private static readonly byte[] EmptyArray = new byte[0];
private readonly ConcurrentDictionary<string, TcpSocketRioSession> _sessions = new ConcurrentDictionary<string, TcpSocketRioSession>();
private readonly TcpSocketRioServerConfiguration _configuration;
private readonly ITcpSocketRioServerMessageDispatcher _dispatcher;
private readonly ITcpSocketRioServerEventDispatcher _dispatcher;

private int _state;
private const int _none = 0;
Expand All @@ -35,17 +34,17 @@ public class TcpSocketRioServer : IDisposable

#region Constructors

public TcpSocketRioServer(int listenedPort, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null)
public TcpSocketRioServer(int listenedPort, ITcpSocketRioServerEventDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null)
: this(IPAddress.Any, listenedPort, dispatcher, configuration)
{
}

public TcpSocketRioServer(IPAddress listenedAddress, int listenedPort, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null)
public TcpSocketRioServer(IPAddress listenedAddress, int listenedPort, ITcpSocketRioServerEventDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null)
: this(new IPEndPoint(listenedAddress, listenedPort), dispatcher, configuration)
{
}

public TcpSocketRioServer(IPEndPoint listenedEndPoint, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null)
public TcpSocketRioServer(IPEndPoint listenedEndPoint, ITcpSocketRioServerEventDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null)
{
if (listenedEndPoint == null)
throw new ArgumentNullException("listenedEndPoint");
Expand Down Expand Up @@ -91,7 +90,7 @@ public TcpSocketRioServer(
Func<TcpSocketRioSession, Task> onSessionClosed = null,
TcpSocketRioServerConfiguration configuration = null)
: this(listenedEndPoint,
new InternalTcpSocketRioServerMessageDispatcherImplementation(onSessionDataReceived, onSessionStarted, onSessionClosed),
new DefaultTcpSocketRioServerEventDispatcher(onSessionDataReceived, onSessionStarted, onSessionClosed),
configuration)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class TcpSocketRioSession : IDisposable
private readonly object _opsLock = new object();
private readonly TcpSocketRioServerConfiguration _configuration;
private readonly ISegmentBufferManager _bufferManager;
private readonly ITcpSocketRioServerMessageDispatcher _dispatcher;
private readonly ITcpSocketRioServerEventDispatcher _dispatcher;
private readonly TcpSocketRioServer _server;
private RioSocket _socket;
private Stream _stream;
Expand All @@ -40,7 +40,7 @@ public TcpSocketRioSession(
TcpSocketRioServerConfiguration configuration,
ISegmentBufferManager bufferManager,
RioSocket socket,
ITcpSocketRioServerMessageDispatcher dispatcher,
ITcpSocketRioServerEventDispatcher dispatcher,
TcpSocketRioServer server)
{
if (configuration == null)
Expand Down
16 changes: 8 additions & 8 deletions Cowboy/Cowboy.Sockets/Cowboy.Sockets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Tcp\Client\EAP\TcpSocketSaeaClient.cs" />
<Compile Include="Tcp\Client\EAP\TcpSocketSaeaClientConfiguration.cs" />
<Compile Include="Tcp\Client\EAP\ITcpSocketSaeaClientMessageDispatcher.cs" />
<Compile Include="Tcp\Client\EAP\InternalTcpSocketSaeaClientMessageDispatcherImplementation.cs" />
<Compile Include="Tcp\Client\EAP\ITcpSocketSaeaClientEventDispatcher.cs" />
<Compile Include="Tcp\Client\EAP\DefaultTcpSocketSaeaClientEventDispatcher.cs" />
<Compile Include="Tcp\Framing\LengthFieldBasedFrameBuilder.cs" />
<Compile Include="Tcp\Framing\RawBufferFrameBuilder.cs" />
<Compile Include="Tcp\Framing\FixedLengthFrameBuilder.cs" />
Expand All @@ -66,8 +66,8 @@
<Compile Include="Tcp\Framing\Base\IFrameEncoder.cs" />
<Compile Include="Tcp\Server\EAP\Awaitable\SaeaAwaiter.cs" />
<Compile Include="Tcp\Server\EAP\Awaitable\SaeaExtensions.cs" />
<Compile Include="Tcp\Server\EAP\ITcpSocketSaeaServerMessageDispatcher.cs" />
<Compile Include="Tcp\Server\EAP\InternalTcpSocketSaeaServerMessageDispatcherImplementation.cs" />
<Compile Include="Tcp\Server\EAP\ITcpSocketSaeaServerEventDispatcher.cs" />
<Compile Include="Tcp\Server\EAP\DefaultTcpSocketSaeaServerEventDispatcher.cs" />
<Compile Include="Tcp\Server\EAP\Pooling\QueuedObjectPool.cs" />
<Compile Include="Tcp\Server\EAP\Pooling\SessionPool.cs" />
<Compile Include="Tcp\Server\EAP\Pooling\SaeaPool.cs" />
Expand All @@ -88,13 +88,13 @@
<Compile Include="Tcp\Server\APM\EventArgs\TcpClientDataReceivedEventArgs.cs" />
<Compile Include="Tcp\Client\APM\EventArgs\TcpServerConnectedEventArgs.cs" />
<Compile Include="Tcp\Client\APM\EventArgs\TcpServerDisconnectedEventArgs.cs" />
<Compile Include="Tcp\Client\TAP\IAsyncTcpSocketClientMessageDispatcher.cs" />
<Compile Include="Tcp\Server\TAP\IAsyncTcpSocketServerMessageDispatcher.cs" />
<Compile Include="Tcp\Client\TAP\IAsyncTcpSocketClientEventDispatcher.cs" />
<Compile Include="Tcp\Server\TAP\IAsyncTcpSocketServerEventDispatcher.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tcp\Server\TAP\AsyncTcpSocketSession.cs" />
<Compile Include="Tcp\Client\TAP\AsyncTcpSocketClient.cs" />
<Compile Include="Tcp\Server\TAP\InternalAsyncTcpSocketServerMessageDispatcherImplementation.cs" />
<Compile Include="Tcp\Client\TAP\InternalAsyncTcpSocketClientMessageDispatcherImplementation.cs" />
<Compile Include="Tcp\Server\TAP\DefaultAsyncTcpSocketServerEventDispatcher.cs" />
<Compile Include="Tcp\Client\TAP\DefaultAsyncTcpSocketClientEventDispatcher.cs" />
<Compile Include="Tcp\Server\APM\TcpSocketSession.cs" />
<Compile Include="Tcp\Client\APM\TcpSocketClient.cs" />
<Compile Include="Tcp\Server\TAP\AsyncTcpSocketServer.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Cowboy/Cowboy.Sockets/Cowboy.Sockets.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<licenseUrl>https://github.com/gaochundong/Cowboy/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/gaochundong/Cowboy</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Cowboy is a C# library for building sockets based services.</description>
<description>Cowboy.Sockets is a C# library for building sockets based services.</description>
<copyright>Copyright © 2015-2017 Dennis Gao.</copyright>
<dependencies>
<dependency id="Logrila.Logging" version="1.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

namespace Cowboy.Sockets
{
internal class InternalTcpSocketSaeaClientMessageDispatcherImplementation : ITcpSocketSaeaClientMessageDispatcher
internal class DefaultTcpSocketSaeaClientEventDispatcher : ITcpSocketSaeaClientEventDispatcher
{
private Func<TcpSocketSaeaClient, byte[], int, int, Task> _onServerDataReceived;
private Func<TcpSocketSaeaClient, Task> _onServerConnected;
private Func<TcpSocketSaeaClient, Task> _onServerDisconnected;

public InternalTcpSocketSaeaClientMessageDispatcherImplementation()
public DefaultTcpSocketSaeaClientEventDispatcher()
{
}

public InternalTcpSocketSaeaClientMessageDispatcherImplementation(
public DefaultTcpSocketSaeaClientEventDispatcher(
Func<TcpSocketSaeaClient, byte[], int, int, Task> onServerDataReceived,
Func<TcpSocketSaeaClient, Task> onServerConnected,
Func<TcpSocketSaeaClient, Task> onServerDisconnected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Cowboy.Sockets
{
public interface ITcpSocketSaeaClientMessageDispatcher
public interface ITcpSocketSaeaClientEventDispatcher
{
Task OnServerConnected(TcpSocketSaeaClient client);
Task OnServerDataReceived(TcpSocketSaeaClient client, byte[] data, int offset, int count);
Expand Down
14 changes: 7 additions & 7 deletions Cowboy/Cowboy.Sockets/Tcp/Client/EAP/TcpSocketSaeaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TcpSocketSaeaClient

private static readonly ILog _log = Logger.Get<TcpSocketSaeaClient>();
private static readonly byte[] EmptyArray = new byte[0];
private readonly ITcpSocketSaeaClientMessageDispatcher _dispatcher;
private readonly ITcpSocketSaeaClientEventDispatcher _dispatcher;
private readonly TcpSocketSaeaClientConfiguration _configuration;
private readonly IPEndPoint _remoteEndPoint;
private readonly IPEndPoint _localEndPoint;
Expand All @@ -34,27 +34,27 @@ public class TcpSocketSaeaClient

#region Constructors

public TcpSocketSaeaClient(IPAddress remoteAddress, int remotePort, IPAddress localAddress, int localPort, ITcpSocketSaeaClientMessageDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
public TcpSocketSaeaClient(IPAddress remoteAddress, int remotePort, IPAddress localAddress, int localPort, ITcpSocketSaeaClientEventDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
: this(new IPEndPoint(remoteAddress, remotePort), new IPEndPoint(localAddress, localPort), dispatcher, configuration)
{
}

public TcpSocketSaeaClient(IPAddress remoteAddress, int remotePort, IPEndPoint localEP, ITcpSocketSaeaClientMessageDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
public TcpSocketSaeaClient(IPAddress remoteAddress, int remotePort, IPEndPoint localEP, ITcpSocketSaeaClientEventDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
: this(new IPEndPoint(remoteAddress, remotePort), localEP, dispatcher, configuration)
{
}

public TcpSocketSaeaClient(IPAddress remoteAddress, int remotePort, ITcpSocketSaeaClientMessageDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
public TcpSocketSaeaClient(IPAddress remoteAddress, int remotePort, ITcpSocketSaeaClientEventDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
: this(new IPEndPoint(remoteAddress, remotePort), dispatcher, configuration)
{
}

public TcpSocketSaeaClient(IPEndPoint remoteEP, ITcpSocketSaeaClientMessageDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
public TcpSocketSaeaClient(IPEndPoint remoteEP, ITcpSocketSaeaClientEventDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
: this(remoteEP, null, dispatcher, configuration)
{
}

public TcpSocketSaeaClient(IPEndPoint remoteEP, IPEndPoint localEP, ITcpSocketSaeaClientMessageDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
public TcpSocketSaeaClient(IPEndPoint remoteEP, IPEndPoint localEP, ITcpSocketSaeaClientEventDispatcher dispatcher, TcpSocketSaeaClientConfiguration configuration = null)
{
if (remoteEP == null)
throw new ArgumentNullException("remoteEP");
Expand Down Expand Up @@ -120,7 +120,7 @@ public TcpSocketSaeaClient(IPEndPoint remoteEP, IPEndPoint localEP,
Func<TcpSocketSaeaClient, Task> onServerDisconnected = null,
TcpSocketSaeaClientConfiguration configuration = null)
: this(remoteEP, localEP,
new InternalTcpSocketSaeaClientMessageDispatcherImplementation(onServerDataReceived, onServerConnected, onServerDisconnected),
new DefaultTcpSocketSaeaClientEventDispatcher(onServerDataReceived, onServerConnected, onServerDisconnected),
configuration)
{
}
Expand Down
14 changes: 7 additions & 7 deletions Cowboy/Cowboy.Sockets/Tcp/Client/TAP/AsyncTcpSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AsyncTcpSocketClient

private static readonly ILog _log = Logger.Get<AsyncTcpSocketClient>();
private TcpClient _tcpClient;
private readonly IAsyncTcpSocketClientMessageDispatcher _dispatcher;
private readonly IAsyncTcpSocketClientEventDispatcher _dispatcher;
private readonly AsyncTcpSocketClientConfiguration _configuration;
private readonly IPEndPoint _remoteEndPoint;
private readonly IPEndPoint _localEndPoint;
Expand All @@ -35,27 +35,27 @@ public class AsyncTcpSocketClient

#region Constructors

public AsyncTcpSocketClient(IPAddress remoteAddress, int remotePort, IPAddress localAddress, int localPort, IAsyncTcpSocketClientMessageDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
public AsyncTcpSocketClient(IPAddress remoteAddress, int remotePort, IPAddress localAddress, int localPort, IAsyncTcpSocketClientEventDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
: this(new IPEndPoint(remoteAddress, remotePort), new IPEndPoint(localAddress, localPort), dispatcher, configuration)
{
}

public AsyncTcpSocketClient(IPAddress remoteAddress, int remotePort, IPEndPoint localEP, IAsyncTcpSocketClientMessageDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
public AsyncTcpSocketClient(IPAddress remoteAddress, int remotePort, IPEndPoint localEP, IAsyncTcpSocketClientEventDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
: this(new IPEndPoint(remoteAddress, remotePort), localEP, dispatcher, configuration)
{
}

public AsyncTcpSocketClient(IPAddress remoteAddress, int remotePort, IAsyncTcpSocketClientMessageDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
public AsyncTcpSocketClient(IPAddress remoteAddress, int remotePort, IAsyncTcpSocketClientEventDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
: this(new IPEndPoint(remoteAddress, remotePort), dispatcher, configuration)
{
}

public AsyncTcpSocketClient(IPEndPoint remoteEP, IAsyncTcpSocketClientMessageDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
public AsyncTcpSocketClient(IPEndPoint remoteEP, IAsyncTcpSocketClientEventDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
: this(remoteEP, null, dispatcher, configuration)
{
}

public AsyncTcpSocketClient(IPEndPoint remoteEP, IPEndPoint localEP, IAsyncTcpSocketClientMessageDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
public AsyncTcpSocketClient(IPEndPoint remoteEP, IPEndPoint localEP, IAsyncTcpSocketClientEventDispatcher dispatcher, AsyncTcpSocketClientConfiguration configuration = null)
{
if (remoteEP == null)
throw new ArgumentNullException("remoteEP");
Expand Down Expand Up @@ -119,7 +119,7 @@ public AsyncTcpSocketClient(IPEndPoint remoteEP, IPEndPoint localEP,
Func<AsyncTcpSocketClient, Task> onServerDisconnected = null,
AsyncTcpSocketClientConfiguration configuration = null)
: this(remoteEP, localEP,
new InternalAsyncTcpSocketClientMessageDispatcherImplementation(onServerDataReceived, onServerConnected, onServerDisconnected),
new DefaultAsyncTcpSocketClientEventDispatcher(onServerDataReceived, onServerConnected, onServerDisconnected),
configuration)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

namespace Cowboy.Sockets
{
internal class InternalAsyncTcpSocketClientMessageDispatcherImplementation : IAsyncTcpSocketClientMessageDispatcher
internal class DefaultAsyncTcpSocketClientEventDispatcher : IAsyncTcpSocketClientEventDispatcher
{
private Func<AsyncTcpSocketClient, byte[], int, int, Task> _onServerDataReceived;
private Func<AsyncTcpSocketClient, Task> _onServerConnected;
private Func<AsyncTcpSocketClient, Task> _onServerDisconnected;

public InternalAsyncTcpSocketClientMessageDispatcherImplementation()
public DefaultAsyncTcpSocketClientEventDispatcher()
{
}

public InternalAsyncTcpSocketClientMessageDispatcherImplementation(
public DefaultAsyncTcpSocketClientEventDispatcher(
Func<AsyncTcpSocketClient, byte[], int, int, Task> onServerDataReceived,
Func<AsyncTcpSocketClient, Task> onServerConnected,
Func<AsyncTcpSocketClient, Task> onServerDisconnected)
Expand Down
Loading

0 comments on commit 55787c5

Please sign in to comment.