callagent: Move to the common udp socket handling code
This commit is contained in:
parent
90083758e1
commit
554903c345
|
@ -65,9 +65,6 @@ Object subclass: SIPTransport [
|
||||||
yourself
|
yourself
|
||||||
]
|
]
|
||||||
|
|
||||||
closeSocket [
|
|
||||||
]
|
|
||||||
|
|
||||||
initialize [
|
initialize [
|
||||||
queue := SharedQueue new.
|
queue := SharedQueue new.
|
||||||
]
|
]
|
||||||
|
@ -110,7 +107,7 @@ Object subclass: SIPTransport [
|
||||||
]
|
]
|
||||||
|
|
||||||
SIPTransport subclass: SIPUdpTransport [
|
SIPTransport subclass: SIPUdpTransport [
|
||||||
| socket rx tx net_exit |
|
| socket net |
|
||||||
<category: 'SIP-Callagent'>
|
<category: 'SIP-Callagent'>
|
||||||
<comment: 'I should share some things with MGCPCallAgent'>
|
<comment: 'I should share some things with MGCPCallAgent'>
|
||||||
|
|
||||||
|
@ -142,68 +139,25 @@ SIPTransport subclass: SIPUdpTransport [
|
||||||
]
|
]
|
||||||
|
|
||||||
initialize: anAddress port: aPort [
|
initialize: anAddress port: aPort [
|
||||||
net_exit := Semaphore new.
|
|
||||||
socket := Sockets.DatagramSocket local: anAddress port: aPort.
|
socket := Sockets.DatagramSocket local: anAddress port: aPort.
|
||||||
socket
|
socket
|
||||||
bufferSize: 2048;
|
bufferSize: 2048;
|
||||||
addToBeFinalized.
|
addToBeFinalized.
|
||||||
]
|
|
||||||
|
|
||||||
closeSocket [
|
net := Osmo.OsmoUDPSocket new
|
||||||
socket close.
|
name: 'SIPTransport';
|
||||||
|
onData: [:data |self handleData: data];
|
||||||
|
yourself
|
||||||
]
|
]
|
||||||
|
|
||||||
stop [
|
stop [
|
||||||
<category: 'lifetime'>
|
<category: 'lifetime'>
|
||||||
|
net stop.
|
||||||
"Close the socket and insert a nil"
|
|
||||||
self closeSocket.
|
|
||||||
queue nextPut: nil.
|
|
||||||
|
|
||||||
"Wait for exit"
|
|
||||||
self logNotice: 'SIPTransport waiting for IO handlers to exit.' area: #sip.
|
|
||||||
net_exit wait.
|
|
||||||
net_exit wait.
|
|
||||||
|
|
||||||
"Reset"
|
|
||||||
socket := nil.
|
socket := nil.
|
||||||
tx := nil.
|
|
||||||
rx := nil.
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
start [
|
start [
|
||||||
"Receive datagrams from the socket..."
|
net start: socket.
|
||||||
rx := [
|
|
||||||
[Processor activeProcess name: 'SIPTransport RX'.
|
|
||||||
self runRXProcess.] ensure: [net_exit signal]] fork.
|
|
||||||
|
|
||||||
"Send data to the MGWs"
|
|
||||||
tx := [
|
|
||||||
[Processor activeProcess name: 'SIPTransport TX'.
|
|
||||||
self runTXProcess] ensure: [net_exit signal]] fork.
|
|
||||||
]
|
|
||||||
|
|
||||||
runRXProcess [
|
|
||||||
<category: 'processing'>
|
|
||||||
[ | data |
|
|
||||||
socket ensureReadable.
|
|
||||||
socket isOpen ifFalse: [
|
|
||||||
^self logNotice: 'SIPTransport socket closed.' area: #sip].
|
|
||||||
data := socket next.
|
|
||||||
self handleData: data.
|
|
||||||
] repeat.
|
|
||||||
]
|
|
||||||
|
|
||||||
runTXProcess [
|
|
||||||
<category: 'processing'>
|
|
||||||
[ | data |
|
|
||||||
data := queue next.
|
|
||||||
data = nil ifTrue: [
|
|
||||||
^self logNotice: 'SIPTransport TX asked to quit.' area: #sip].
|
|
||||||
|
|
||||||
socket nextPut: data.
|
|
||||||
] repeat.
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Reference in New Issue