smalltalk
/
osmo-st-smpp
Archived
1
0
Fork 0

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.
master
Holger Hans Peter Freyther 9 years ago
parent 38fb0d2745
commit 6502e32773
  1. 21
      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
]
]