Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Moved frame creation methods into Sessions to further break logic bet…
Browse files Browse the repository at this point in the history
…ween the socket and the MqSessions.
  • Loading branch information
DJGosnell committed Sep 11, 2016
1 parent 02e8028 commit 8311936
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 52 deletions.
6 changes: 3 additions & 3 deletions DtronixMessageQueue.Tests/MqClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void Client_does_not_send_empty_message() {

[Fact]
public void Client_does_not_notify_on_command_frame() {
var command_frame = Client.CreateFrame(new byte[21]);
command_frame.FrameType = MqFrameType.Command;

var command_frame = new MqFrame(new byte[21], MqFrameType.Command, Config);

Client.Connected += (sender, args) => {
Client.Send(command_frame);
Expand All @@ -96,7 +96,7 @@ public void Client_does_not_notify_on_command_frame() {

[Fact]
public void Client_does_not_notify_on_ping_frame() {
var command_frame = Client.CreateFrame(null, MqFrameType.Ping);
var command_frame = new MqFrame(null, MqFrameType.Ping, Config);

Client.Connected += (sender, args) => {
Client.Send(command_frame);
Expand Down
3 changes: 1 addition & 2 deletions DtronixMessageQueue/MqClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class MqClient<TSession> : SocketClient<TSession>
/// </summary>
private readonly Timer timeout_timer;


/// <summary>
/// Initializes a new instance of a message queue.
/// </summary>
Expand Down Expand Up @@ -66,7 +65,7 @@ protected override void OnClose(TSession session, SocketCloseReason reason) {
/// </summary>
/// <param name="state">Concurrent dictionary of the sessions.</param>
private void TimeoutCallback(object state) {
Session.Send(CreateFrame(null, MqFrameType.Ping));
Session.Send(Session.CreateFrame(null, MqFrameType.Ping));
}

/// <summary>
Expand Down
21 changes: 20 additions & 1 deletion DtronixMessageQueue/MqSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public override void Close(SocketCloseReason reason) {
if (CurrentState == State.Connected) {
CurrentState = State.Closing;

close_frame = BaseSocket.CreateFrame(new byte[2]);
close_frame = CreateFrame(new byte[2]);
close_frame.FrameType = MqFrameType.Command;

close_frame.Write(0, (byte) 0);
Expand Down Expand Up @@ -284,6 +284,25 @@ public void Send(MqMessage message) {
EnqueueOutgoingMessage(message);
}

/// <summary>
/// Creates a frame with the specified bytes and the current configurations.
/// </summary>
/// <param name="bytes">Bytes to put in the frame.</param>
/// <returns>Configured frame.</returns>
public MqFrame CreateFrame(byte[] bytes) {
return Utilities.CreateFrame(bytes, MqFrameType.Unset, (MqSocketConfig)Config);
}

/// <summary>
/// Creates a frame with the specified bytes and the current configurations.
/// </summary>
/// <param name="bytes">Bytes to put in the frame.</param>
/// <param name="type">Type of frame to create.</param>
/// <returns>Configured frame.</returns>
public MqFrame CreateFrame(byte[] bytes, MqFrameType type) {
return Utilities.CreateFrame(bytes, type, (MqSocketConfig)Config);
}


/// <summary>
/// Processes an incoming command frame from the connection.
Expand Down
5 changes: 0 additions & 5 deletions DtronixMessageQueue/Socket/SocketBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,5 @@ protected virtual TSession CreateSession(System.Net.Sockets.Socket socket) {
session.Closed += (sender, args) => OnClose(session, args.CloseReason);
return session;
}


public abstract MqFrame CreateFrame(byte[] bytes);

public abstract MqFrame CreateFrame(byte[] bytes, MqFrameType type);
}
}
20 changes: 0 additions & 20 deletions DtronixMessageQueue/Socket/SocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,5 @@ public void Connect(IPEndPoint end_point) {

MainSocket.ConnectAsync(event_arg);
}


/// <summary>
/// Creates a frame with the specified bytes and the current configurations.
/// </summary>
/// <param name="bytes">Bytes to put in the frame.</param>
/// <returns>Configured frame.</returns>
public override MqFrame CreateFrame(byte[] bytes) {
return Utilities.CreateFrame(bytes, MqFrameType.Unset, (MqSocketConfig) Config);
}

/// <summary>
/// Creates a frame with the specified bytes and the current configurations.
/// </summary>
/// <param name="bytes">Bytes to put in the frame.</param>
/// <param name="type">Type of frame to create.</param>
/// <returns>Configured frame.</returns>
public override MqFrame CreateFrame(byte[] bytes, MqFrameType type) {
return Utilities.CreateFrame(bytes, type, (MqSocketConfig)Config);
}
}
}
21 changes: 0 additions & 21 deletions DtronixMessageQueue/Socket/SocketServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,6 @@ private void RemoveClientEvent(object sender, SessionClosedEventArgs<SocketSessi
e.Session.Closed -= RemoveClientEvent;
}

/// <summary>
/// Creates a frame with the specified bytes and the current configurations.
/// </summary>
/// <param name="bytes">Bytes to put in the frame.</param>
/// <returns>Configured frame.</returns>
public override MqFrame CreateFrame(byte[] bytes) {
return Utilities.CreateFrame(bytes, MqFrameType.Unset, (MqSocketConfig)Config);
}

/// <summary>
/// Creates a frame with the specified bytes and the current configurations.
/// </summary>
/// <param name="bytes">Bytes to put in the frame.</param>
/// <param name="type">Type of frame to create.</param>
/// <returns>Configured frame.</returns>
public override MqFrame CreateFrame(byte[] bytes, MqFrameType type) {
return Utilities.CreateFrame(bytes, type, (MqSocketConfig)Config);
}



/// <summary>
/// Terminates this server and notify all connected clients.
/// </summary>
Expand Down

0 comments on commit 8311936

Please sign in to comment.