This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Removed dependency over ReactiveSockets - Added TcpChannel as an adapter of TcpClient to replace ReactiveSocket - Applied Disposable pattern over all the Channel implementations
- Loading branch information
Showing
28 changed files
with
410 additions
and
356 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
namespace Hermes | ||
{ | ||
public interface IPacketBuffer | ||
{ | ||
bool TryGetPacket (byte[] sequence, out byte[] packet); | ||
} | ||
} |
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,99 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Hermes | ||
{ | ||
public class PacketBuffer : IPacketBuffer | ||
{ | ||
bool readStarted; | ||
bool remainingLengthRead; | ||
int remainingLength = 0; | ||
bool packetReady; | ||
|
||
readonly IList<byte> mainBuffer; | ||
readonly IList<byte> pendingBuffer; | ||
|
||
public PacketBuffer () | ||
{ | ||
this.mainBuffer = new List<byte> (); | ||
this.pendingBuffer = new List<byte> (); | ||
} | ||
|
||
public bool TryGetPacket (byte[] sequence, out byte[] packet) | ||
{ | ||
this.Buffer (sequence); | ||
|
||
if (this.packetReady) { | ||
packet = this.mainBuffer.ToArray (); | ||
this.Reset (); | ||
} else { | ||
packet = default (byte[]); | ||
} | ||
|
||
return packet != default(byte[]); | ||
} | ||
|
||
private void Buffer(byte[] sequence) | ||
{ | ||
foreach(var @byte in sequence) { | ||
this.Buffer (@byte); | ||
} | ||
} | ||
|
||
private void Buffer (byte @byte) | ||
{ | ||
if (this.packetReady) { | ||
this.pendingBuffer.Add (@byte); | ||
return; | ||
} | ||
|
||
this.mainBuffer.Add(@byte); | ||
|
||
if (!this.readStarted) | ||
{ | ||
this.readStarted = true; | ||
return; | ||
} | ||
|
||
if (!this.remainingLengthRead) | ||
{ | ||
if ((@byte & 128) == 0) { | ||
var bytesLenght = default (int); | ||
|
||
this.remainingLength = Protocol.Encoding.DecodeRemainingLength(mainBuffer.ToArray(), out bytesLenght); | ||
this.remainingLengthRead = true; | ||
|
||
if (remainingLength == 0) | ||
this.packetReady = true; | ||
} | ||
|
||
return; | ||
} | ||
|
||
if (remainingLength == 1) | ||
{ | ||
this.packetReady = true; | ||
} | ||
else | ||
{ | ||
remainingLength--; | ||
} | ||
} | ||
|
||
private void Reset() | ||
{ | ||
this.mainBuffer.Clear(); | ||
this.readStarted = false; | ||
this.remainingLengthRead = false; | ||
this.remainingLength = 0; | ||
this.packetReady = false; | ||
|
||
if (this.pendingBuffer.Any ()) { | ||
var pendingSequence = this.pendingBuffer.ToArray (); | ||
|
||
this.pendingBuffer.Clear (); | ||
this.Buffer (pendingSequence); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.