Make it possible to request stop of message loop
Add a `RequestStopMessageLoop()` method to `Ricochet` to be able to stop handling new connections. Right now, ProcessMessages is an infinite loop.
This commit is contained in:
parent
f2788c929f
commit
c16dce9f60
|
@ -93,10 +93,19 @@ func (r *Ricochet) processNewConnection(conn net.Conn, service RicochetService)
|
|||
func (r *Ricochet) ProcessMessages(service RicochetService) {
|
||||
for {
|
||||
oc := <-r.newconns
|
||||
if oc == nil {
|
||||
return
|
||||
}
|
||||
go r.processConnection(oc, service)
|
||||
}
|
||||
}
|
||||
|
||||
// Request that the ProcessMessages loop is stopped after handling all currently
|
||||
// queued new connections.
|
||||
func (r *Ricochet) RequestStopMessageLoop() {
|
||||
r.newconns <- nil
|
||||
}
|
||||
|
||||
// ProcessConnection starts a blocking process loop which continually waits for
|
||||
// new messages to arrive from the connection and uses the given RicochetService
|
||||
// to process them.
|
||||
|
|
Loading…
Reference in New Issue