@@ -54,7 +54,7 @@ type Conn struct {
54
54
closed bool
55
55
outLck sync.RWMutex
56
56
57
- signals chan * Signal
57
+ signals [] chan * Signal
58
58
signalsLck sync.Mutex
59
59
60
60
eavesdropped chan * Message
@@ -186,8 +186,8 @@ func (conn *Conn) Close() error {
186
186
conn .closed = true
187
187
conn .outLck .Unlock ()
188
188
conn .signalsLck .Lock ()
189
- if conn . signals != nil {
190
- close (conn . signals )
189
+ for _ , ch := range conn . signals {
190
+ close (ch )
191
191
}
192
192
conn .signalsLck .Unlock ()
193
193
conn .eavesdroppedLck .Lock ()
@@ -304,11 +304,13 @@ func (conn *Conn) inWorker() {
304
304
Name : iface + "." + member ,
305
305
Body : msg .Body ,
306
306
}
307
- // don't block trying to send a signal
308
307
conn .signalsLck .Lock ()
309
- select {
310
- case conn .signals <- signal :
311
- default :
308
+ for _ , ch := range conn .signals {
309
+ // don't block trying to send a signal
310
+ select {
311
+ case ch <- signal :
312
+ default :
313
+ }
312
314
}
313
315
conn .signalsLck .Unlock ()
314
316
case TypeMethodCall :
@@ -476,18 +478,20 @@ func (conn *Conn) serials() {
476
478
}
477
479
}
478
480
479
- // Signal sets the channel to which all received signal messages are forwarded .
480
- // The caller has to make sure that c is sufficiently buffered; if a message
481
+ // Signal registers the given channel to be passed all received signal messages.
482
+ // The caller has to make sure that ch is sufficiently buffered; if a message
481
483
// arrives when a write to c is not possible, it is discarded.
482
484
//
483
- // The channel can be reset by passing nil.
485
+ // Multiple of these channels can be registered at the same time. Passing a
486
+ // channel that already is registered will remove it from the list of the
487
+ // registered channels.
484
488
//
485
- // This channel is "overwritten" by Eavesdrop; i.e., if there currently is a
486
- // channel for eavesdropped messages, this channel receives all signals, and the
487
- // channel passed to Signal will not receive any signals.
488
- func (conn * Conn ) Signal (c chan * Signal ) {
489
+ // Thess channels are "overwritten" by Eavesdrop; i.e., if there currently is a
490
+ // channel for eavesdropped messages, this channel receives all signals, and
491
+ // none of the channels passed to Signal will receive any signals.
492
+ func (conn * Conn ) Signal (ch chan * Signal ) {
489
493
conn .signalsLck .Lock ()
490
- conn .signals = c
494
+ conn .signals = append ( conn . signals , ch )
491
495
conn .signalsLck .Unlock ()
492
496
}
493
497
0 commit comments