mgcp: Use the common UDPSocket code to reduce the complexity
This commit is contained in:
parent
e3c2bcf1ca
commit
ca0d7624a8
|
@ -16,10 +16,12 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"
|
||||
|
||||
PackageLoader fileInPackage: 'Sockets'.
|
||||
PackageLoader
|
||||
fileInPackage: 'Sockets';
|
||||
fileInPackage: 'OsmoNetwork'.
|
||||
|
||||
Object subclass: MGCPCallAgentBase [
|
||||
| socket queue rx tx trunks sem addr port net_exit |
|
||||
| net trunks sem addr port |
|
||||
<category: 'MGCP-Callagent'>
|
||||
<comment: 'I am responsible for the networking'>
|
||||
|
||||
|
@ -40,11 +42,14 @@ Object subclass: MGCPCallAgentBase [
|
|||
initialize: anAddress port: aPort [
|
||||
<category: 'creation'>
|
||||
sem := Semaphore forMutualExclusion.
|
||||
queue := SharedQueue new.
|
||||
trunks := OrderedCollection new.
|
||||
addr := anAddress.
|
||||
port := aPort.
|
||||
net_exit := Semaphore new.
|
||||
|
||||
net := Osmo.OsmoUDPSocket new
|
||||
name: 'MGCPCallAgent';
|
||||
onData: [:data | OsmoDispatcher dispatchBlock: [self handleData: data]];
|
||||
yourself.
|
||||
]
|
||||
|
||||
addTrunk: aTrunk [
|
||||
|
@ -60,6 +65,7 @@ Object subclass: MGCPCallAgentBase [
|
|||
]
|
||||
|
||||
start [
|
||||
| socket |
|
||||
<category: 'handling'>
|
||||
|
||||
self stop.
|
||||
|
@ -67,61 +73,17 @@ Object subclass: MGCPCallAgentBase [
|
|||
bufferSize: 2048;
|
||||
yourself.
|
||||
|
||||
"Receive datagrams from the socket..."
|
||||
rx := [
|
||||
[Processor activeProcess name: 'MGCP RX'.
|
||||
self runRXProcess] ensure: [net_exit signal]] fork.
|
||||
|
||||
"Send data to the MGWs"
|
||||
tx := [
|
||||
[Processor activeProcess name: 'MGCP TX'.
|
||||
self runTXProcess] ensure: [net_exit signal]] fork.
|
||||
]
|
||||
|
||||
runRXProcess [
|
||||
<category: 'processing'>
|
||||
|
||||
[ | data |
|
||||
socket ensureReadable.
|
||||
socket isOpen ifFalse: [
|
||||
^self logNotice: 'MGCPCallAgent socket closed.' area: #mgcp].
|
||||
OsmoDispatcher dispatchBlock: [self handleData: data].
|
||||
] repeat.
|
||||
]
|
||||
|
||||
runTXProcess [
|
||||
<category: 'processing'>
|
||||
|
||||
[ | data |
|
||||
data := queue next.
|
||||
data = nil ifTrue: [
|
||||
^self logNotice: 'MGCPCallAgent TX asked to quit.' area: #mgcp].
|
||||
|
||||
socket nextPut: data.
|
||||
] repeat.
|
||||
net start: socket.
|
||||
]
|
||||
|
||||
stop [
|
||||
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.
|
||||
<category: 'processing'>
|
||||
net stop
|
||||
]
|
||||
|
||||
queueData: aDatagram [
|
||||
queue nextPut: aDatagram.
|
||||
<category: 'sending'>
|
||||
net queueData: aDatagram.
|
||||
]
|
||||
]
|
||||
|
||||
|
|
Reference in New Issue