summaryrefslogtreecommitdiffstats
path: root/connection
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-07-14 16:41:23 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-07-14 16:41:23 +0200
commit6502e327735d322d601d81e6df51986559cab98c (patch)
tree2e0816f94acf3627ea811ea35365c863b164d076 /connection
parent38fb0d274517070ffaed07b4c8b7079334fd67da (diff)
conn: Remember the sequence number we expect as response and dispatch
This is lacking timeout and sanity checking. E.g. we want to make sure we get a response within the next XYZ seconds and we want the system to check that the response belongs to the request we sent.
Diffstat (limited to 'connection')
-rw-r--r--connection/SMPPConnection.st21
1 files changed, 17 insertions, 4 deletions
diff --git a/connection/SMPPConnection.st b/connection/SMPPConnection.st
index b80cb0a..c244f0f 100644
--- a/connection/SMPPConnection.st
+++ b/connection/SMPPConnection.st
@@ -17,7 +17,7 @@
"
Osmo.OsmoStreamSocketBase subclass: SMPPConnection [
- | writeQueue nextSeq systemId password systemType |
+ | writeQueue nextSeq systemId password systemType pendingCommands |
<category: 'SMPP-Connection'>
createConnection: aHostname port: aPort [
@@ -56,15 +56,19 @@ Osmo.OsmoStreamSocketBase subclass: SMPPConnection [
self send: (SMPPMessage new
header: header;
- body: body)
+ body: body) onResponse: [:resp | ].
]
- send: aMessage [
- | seq |
+ send: aMessage onResponse: aBlock [
+ | seq key |
seq := nextSeq.
nextSeq := nextSeq + 1.
aMessage header sequenceNumber: seq.
+
+ "Remember that we want a response. TODO add timeout handling"
+ pendingCommands at: seq put: aBlock.
+
writeQueue nextPut: aMessage toMessage asByteArray
]
@@ -72,6 +76,7 @@ Osmo.OsmoStreamSocketBase subclass: SMPPConnection [
super connect.
nextSeq := 1.
writeQueue := SharedQueue new.
+ pendingCommands := Dictionary new.
self scheduleBindTrx.
]
@@ -108,5 +113,13 @@ Osmo.OsmoStreamSocketBase subclass: SMPPConnection [
]
receviedResponse: aMessage [
+ | seq block |
+ "Search for a response"
+ seq := aMessage header sequenceNumber.
+ block := pendingCommands removeKey: seq ifAbsent: [
+ "TODO: log it"
+ ^false].
+
+ block value: aMessage
]
]