Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*/*.??proj.user
*/bin
*/obj

Packages/
packages/
/.vs
/.editorconfig
4 changes: 3 additions & 1 deletion AberrantSMPP.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
# Visual Studio 15
VisualStudioVersion = 15.0.26430.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AberrantSMPP", "AberrantSMPP\AberrantSMPP.csproj", "{CB0A2871-0BC6-4ADC-BA61-AE23144F8A3C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestClient", "TestClient\TestClient.csproj", "{9A549B1F-9027-4FC6-B67A-390B3F532A4B}"
Expand Down
12 changes: 10 additions & 2 deletions AberrantSMPP/ASyncSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,16 @@ private void SendComplete(IAsyncResult state)
using (new ReadOnlyLock(_socketLock))
{
_SendPending = true;
var packet = _SendQueue.Dequeue();
_TcpClient.GetStream().BeginWrite(packet, 0, packet.Length, _CallbackWriteMethod, null);
try
{
var packet = _SendQueue.Dequeue();
_TcpClient.GetStream().BeginWrite(packet, 0, packet.Length, _CallbackWriteMethod, null);
}
catch (Exception ex)
{
_Log.Warn(string.Format("Instance {0} - {1} => Async send failed.", this.GetHashCode(), _ThreadId), ex);
_SendPending = false;
}
}
}
}
Expand Down
32 changes: 22 additions & 10 deletions AberrantSMPP/SMPPCommunicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System.Net.Sockets;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Threading;
using System.Timers;
using System.ComponentModel;
Expand Down Expand Up @@ -86,12 +87,12 @@ public RequestState(uint seqno)
private bool _SentUnbindPacket = true; //default to true since we start out unbound
private Random _random = new Random();
private uint _SequenceNumber = 0;
private IDictionary<uint, RequestState> _RequestsAwaitingResponse = new Dictionary<uint, RequestState>();
private ConcurrentDictionary<uint, RequestState> _RequestsAwaitingResponse = new ConcurrentDictionary<uint, RequestState>();

/// <summary>
/// Required designer variable.
/// </summary>
protected Container components = null;
/// <summary>
/// Required designer variable.
/// </summary>
protected Container components = null;

#region properties
/// <summary>
Expand Down Expand Up @@ -622,14 +623,17 @@ public SmppResponse SendRequest(SmppRequest request)
lock (_RequestsAwaitingResponse)
{
state = new RequestState(SendPdu(request));
_RequestsAwaitingResponse.Add(state.SequenceNumber, state);
if(!_RequestsAwaitingResponse.TryAdd(state.SequenceNumber, state))
{
throw new Exception("Could not add AwaitingResponse it already exists.");
}
}

var signalled = state.EventHandler.WaitOne(_ResponseTimeout);

lock (_RequestsAwaitingResponse)
{
_RequestsAwaitingResponse.Remove(state.SequenceNumber);
_RequestsAwaitingResponse.TryRemove(state.SequenceNumber, out state);

if (signalled)
{
Expand All @@ -649,9 +653,14 @@ public IEnumerable<SmppResponse> SendRequests(IEnumerable<SmppRequest> requests)
{
foreach (var request in requests)
list.Add(new RequestState(SendPdu(request)));

foreach (var state in list)
_RequestsAwaitingResponse.Add(state.SequenceNumber, state);
{
if (_RequestsAwaitingResponse.TryAdd(state.SequenceNumber, state))
{
_Log.Debug("Could not add the AwaitingResponse.");
}
}
}

var handlers = list.Select(x => x.EventHandler).ToArray();
Expand Down Expand Up @@ -688,8 +697,11 @@ public IEnumerable<SmppResponse> SendRequests(IEnumerable<SmppRequest> requests)

lock (_RequestsAwaitingResponse)
{
RequestState reqstate;
foreach (var state in list)
_RequestsAwaitingResponse.Remove(state.SequenceNumber);
{
_RequestsAwaitingResponse.TryRemove(state.SequenceNumber, out reqstate);
}

if (signalled)
{
Expand Down
5 changes: 4 additions & 1 deletion AberrantSMPP/Utility/TlvTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ private void InjectTlv(byte[] tlvData, ref Int32 index)

data.TrimToSize();
//add the values to the hashtable
tlvTable.Add(tag, data.ToArray(typeof(byte)));
if (!tlvTable.ContainsKey(tag)) // Sometimes we receive mulitple tags. http://smppapi.sourceforge.net/apidocs/ie/omk/smpp/message/tlv/TLVTable.html
{
tlvTable.Add(tag, data.ToArray(typeof(byte)));
}
//set it up for the next run
index += length;
}
Expand Down