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 | 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 ] ]