smalltalk
/
osmo-st-sip
Archived
1
0
Fork 0

callagent: Move to the common udp socket handling code

This commit is contained in:
Holger Hans Peter Freyther 2012-08-09 02:23:21 +02:00
parent 90083758e1
commit 554903c345
1 changed files with 7 additions and 53 deletions

View File

@ -65,9 +65,6 @@ Object subclass: SIPTransport [
yourself
]
closeSocket [
]
initialize [
queue := SharedQueue new.
]
@ -110,7 +107,7 @@ Object subclass: SIPTransport [
]
SIPTransport subclass: SIPUdpTransport [
| socket rx tx net_exit |
| socket net |
<category: 'SIP-Callagent'>
<comment: 'I should share some things with MGCPCallAgent'>
@ -142,68 +139,25 @@ SIPTransport subclass: SIPUdpTransport [
]
initialize: anAddress port: aPort [
net_exit := Semaphore new.
socket := Sockets.DatagramSocket local: anAddress port: aPort.
socket
bufferSize: 2048;
addToBeFinalized.
]
closeSocket [
socket close.
net := Osmo.OsmoUDPSocket new
name: 'SIPTransport';
onData: [:data |self handleData: data];
yourself
]
stop [
<category: 'lifetime'>
"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"
net stop.
socket := nil.
tx := nil.
rx := nil.
]
start [
"Receive datagrams from the 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.
net start: socket.
]
]