From e3c2bcf1ca9adb49adc91d39ae6efd4cf02e2183 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 9 Aug 2012 01:15:26 +0200 Subject: [PATCH] callagent: Work on re-creating the socket after image resume Use the same approach as with the SIP UDP Transport to close the socket and terminate the two handlers. This way both processes are stopped at the end of the session. --- callagent/MGCPCallAgent.st | 63 +++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/callagent/MGCPCallAgent.st b/callagent/MGCPCallAgent.st index 672b018..d22cc39 100644 --- a/callagent/MGCPCallAgent.st +++ b/callagent/MGCPCallAgent.st @@ -19,7 +19,7 @@ PackageLoader fileInPackage: 'Sockets'. Object subclass: MGCPCallAgentBase [ - | socket queue rx tx trunks sem addr port | + | socket queue rx tx trunks sem addr port net_exit | @@ -44,6 +44,7 @@ Object subclass: MGCPCallAgentBase [ trunks := OrderedCollection new. addr := anAddress. port := aPort. + net_exit := Semaphore new. ] addTrunk: aTrunk [ @@ -68,29 +69,55 @@ Object subclass: MGCPCallAgentBase [ "Receive datagrams from the socket..." rx := [ - Processor activeProcess name: 'MGCP RX'. - [ | data | - data := socket next. - data ifNotNil: [ - OsmoDispatcher dispatchBlock: [self handleData: data]. - ]. - ] repeat. - ] fork. + [Processor activeProcess name: 'MGCP RX'. + self runRXProcess] ensure: [net_exit signal]] fork. "Send data to the MGWs" tx := [ - Processor activeProcess name: 'MGCP TX'. - [ | data | - data := queue next. - socket nextPut: data. - ] repeat. - ] fork. + [Processor activeProcess name: 'MGCP TX'. + self runTXProcess] ensure: [net_exit signal]] fork. + ] + + runRXProcess [ + + + [ | data | + socket ensureReadable. + socket isOpen ifFalse: [ + ^self logNotice: 'MGCPCallAgent socket closed.' area: #mgcp]. + OsmoDispatcher dispatchBlock: [self handleData: data]. + ] repeat. + ] + + runTXProcess [ + + + [ | data | + data := queue next. + data = nil ifTrue: [ + ^self logNotice: 'MGCPCallAgent TX asked to quit.' area: #mgcp]. + + socket nextPut: data. + ] repeat. ] stop [ - socket ifNotNil: [socket close]. - tx ifNotNil: [tx terminate]. - rx ifNotNil: [rx terminate]. + socket ifNil: [^self]. + + "Close" + socket close. + queue nextPut: nil. + + "Wait for the process to exit" + self logNotice: 'MGCPCallAgent waiting for IO handlers to exit.' area: #mgcp. + net_exit + wait; + wait. + + "Forget things" + socket := nil. + tx := nil. + rx := nil. ] queueData: aDatagram [