From 6502e327735d322d601d81e6df51986559cab98c Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 14 Jul 2014 16:41:23 +0200 Subject: 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. --- connection/SMPPConnection.st | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'connection') 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 ] ] -- cgit v1.2.3