This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed classes, added support for setting socket options (makes it m…
…ore flexible), and added interfaces for all major components (easier testing)
- Loading branch information
Showing
24 changed files
with
812 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Need this additional manifest because having a dependency on an "rc" release means your | ||
release also needs to be "rc". For .NET 4.5 we're release, not pre-release --> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<metadata> | ||
<id>ReactiveSockets</id> | ||
<version>0.1.0-rc</version> | ||
<title>Reactive Sockets</title> | ||
<summary>The easiest way to do socket programming in .NET, leveraging simple Rx queries to implement your protocols.</summary> | ||
<description> | ||
Implementing socket-based prototols in .NET has never been easier. Example: | ||
from header in socket.Receiver.Buffer(4) | ||
let length = BitConverter.ToInt32(header.ToArray(), 0) | ||
let body = socket.Receiver.Take(length) | ||
select Encoding.UTF8.GetString(body.ToEnumerable().ToArray()) | ||
</description> | ||
<authors>Daniel Cazzulino, kzu, Clarius</authors> | ||
<language>en-US</language> | ||
<projectUrl>https://github.com/clariuslabs/reactivesockets</projectUrl> | ||
<licenseUrl>http://opensource.org/licenses/BSD-2-Clause</licenseUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<iconUrl>https://github.com/clariuslabs/adapter/raw/master/Common/ClariusLabsIcon.png</iconUrl> | ||
<tags>reactive socket</tags> | ||
<dependencies> | ||
<group targetFramework="net40"> | ||
<dependency id="Microsoft.Bcl.Async" version="1.0.14-rc" /> | ||
<dependency id="Rx-Main" version="2.1.30214.0" /> | ||
</group> | ||
<group targetFramework="net45"> | ||
<dependency id="Rx-Main" version="2.1.30214.0" /> | ||
</group> | ||
</dependencies> | ||
<frameworkAssemblies> | ||
<frameworkAssembly assemblyName="System.Net" targetFramework="net40" /> | ||
<frameworkAssembly assemblyName="System.Net" targetFramework="net45" /> | ||
</frameworkAssemblies> | ||
</metadata> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<metadata> | ||
<id>ReactiveSockets</id> | ||
<version>0.1.0</version> | ||
<title>Reactive Sockets</title> | ||
<summary>The easiest way to do socket programming in .NET, leveraging simple Rx queries to implement your protocols.</summary> | ||
<description> | ||
Implementing socket-based prototols in .NET has never been easier. Example: | ||
from header in socket.Receiver.Buffer(4) | ||
let length = BitConverter.ToInt32(header.ToArray(), 0) | ||
let body = socket.Receiver.Take(length) | ||
select Encoding.UTF8.GetString(body.ToEnumerable().ToArray()) | ||
</description> | ||
<authors>Daniel Cazzulino, kzu, Clarius</authors> | ||
<language>en-US</language> | ||
<projectUrl>https://github.com/clariuslabs/reactivesockets</projectUrl> | ||
<licenseUrl>http://opensource.org/licenses/BSD-2-Clause</licenseUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<iconUrl>https://github.com/clariuslabs/adapter/raw/master/Common/ClariusLabsIcon.png</iconUrl> | ||
<tags>reactive socket</tags> | ||
<dependencies> | ||
<group targetFramework="net45"> | ||
<dependency id="Rx-Main" version="2.1.30214.0" /> | ||
</group> | ||
</dependencies> | ||
<frameworkAssemblies> | ||
<frameworkAssembly assemblyName="System.Net" targetFramework="net45" /> | ||
</frameworkAssemblies> | ||
</metadata> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace ReactiveSockets | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// Interface implemented by the reactive client socket that can | ||
/// connect, send data to and receive data from a server. | ||
/// </summary> | ||
interface IReactiveClient : IReactiveSocket | ||
{ | ||
/// <summary> | ||
/// Attempts to connect to a server. | ||
/// </summary> | ||
Task ConnectAsync(); | ||
|
||
/// <summary> | ||
/// Disconnects the underlying connection to the server. | ||
/// </summary> | ||
void Disconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace ReactiveSockets | ||
{ | ||
using System; | ||
|
||
/// <summary> | ||
/// Interface implemented by the reactive listeners which can | ||
/// accept incoming connections. | ||
/// </summary> | ||
public interface IReactiveListener | ||
{ | ||
/// <summary> | ||
/// Observable connections that are being accepted by the listener. | ||
/// </summary> | ||
IObservable<ReactiveSocket> Connections { get; } | ||
|
||
/// <summary> | ||
/// Disposes the listener, releasing all resources and closing | ||
/// any active connections. | ||
/// </summary> | ||
void Dispose(); | ||
|
||
/// <summary> | ||
/// Starts accepting connections. | ||
/// </summary> | ||
void Start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
namespace ReactiveSockets | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// Low level channel between client and server. | ||
/// </summary> | ||
public interface IReactiveSocket : ISocket, IDisposable | ||
{ | ||
/// <summary> | ||
/// Raised when the socket is connected. | ||
/// </summary> | ||
event EventHandler Connected; | ||
|
||
/// <summary> | ||
/// Raised when the socket is disconnected. | ||
/// </summary> | ||
event EventHandler Disconnected; | ||
|
||
/// <summary> | ||
/// Raised when the socket is disposed. | ||
/// </summary> | ||
event EventHandler Disposed; | ||
|
||
/// <summary> | ||
/// Gets whether the socket is connected. | ||
/// </summary> | ||
bool IsConnected { get; } | ||
|
||
/// <summary> | ||
/// Observable bytes that are being received by this endpoint. | ||
/// </summary> | ||
IObservable<byte> Receiver { get; } | ||
|
||
/// <summary> | ||
/// Observable bytes that are being sent through this endpoint | ||
/// by using the <see cref="SendAsync(byte[])"/> or | ||
/// <see cref="SendAsync(byte[], CancellationToken)"/> methods. | ||
/// </summary> | ||
IObservable<byte> Sender { get; } | ||
|
||
/// <summary> | ||
/// Sends data asynchronously through this endpoint. | ||
/// </summary> | ||
Task SendAsync(byte[] data); | ||
|
||
/// <summary> | ||
/// Sends data asynchronously through this endpoint, with support | ||
/// for cancellation. | ||
/// </summary> | ||
Task SendAsync(byte[] bytes, CancellationToken cancellation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
namespace ReactiveSockets | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using System.Net.Sockets; | ||
|
||
/// <summary> | ||
/// Exposes the core SetSocketOption method from .NET sockets. | ||
/// </summary> | ||
public interface ISocket | ||
{ | ||
IObservable<byte> Receiver { get; } | ||
IObservable<byte> Sender { get; } | ||
Task SendAsync(byte[] data); | ||
/// <summary>See <see cref="T:System.Net.Sockets.Socket.GetSocketOption(SocketOptionLevel, SocketOptionName)" />.</summary> | ||
object GetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName); | ||
|
||
/// <summary>See <see cref="T:System.Net.Sockets.Socket.GetSocketOption(SocketOptionLevel, SocketOptionName, byte[])" />.</summary> | ||
void GetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue); | ||
|
||
/// <summary>See <see cref="T:System.Net.Sockets.Socket.GetSocketOption(SocketOptionLevel, SocketOptionName, int)" />.</summary> | ||
byte[] GetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionLength); | ||
|
||
/// <summary>See <see cref="T:System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel, SocketOptionName, bool)" />.</summary> | ||
void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, bool optionValue); | ||
|
||
/// <summary>See <see cref="T:System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel, SocketOptionName, byte[])" />.</summary> | ||
void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, byte[] optionValue); | ||
|
||
/// <summary>See <see cref="T:System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel, SocketOptionName, int)" />.</summary> | ||
void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue); | ||
|
||
/// <summary>See <see cref="T:System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel, SocketOptionName, object)" />.</summary> | ||
void SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, object optionValue); | ||
} | ||
} |
Oops, something went wrong.