Skip to content

Commit a389bdd

Browse files
authored
Merge pull request #92 from jsouthworth/fix/move-async-signals
Allow implementations to decide when to make signal handling asynchronous.
2 parents 7f21b8d + 023e603 commit a389bdd

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

conn.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func Dial(address string) (*Conn, error) {
160160
if err != nil {
161161
return nil, err
162162
}
163-
return newConn(tr, newDefaultHandler(), newDefaultSignalHandler())
163+
return newConn(tr, NewDefaultHandler(), NewDefaultSignalHandler())
164164
}
165165

166166
// DialHandler establishes a new private connection to the message bus specified by address, using the supplied handlers.
@@ -174,7 +174,7 @@ func DialHandler(address string, handler Handler, signalHandler SignalHandler) (
174174

175175
// NewConn creates a new private *Conn from an already established connection.
176176
func NewConn(conn io.ReadWriteCloser) (*Conn, error) {
177-
return NewConnHandler(conn, newDefaultHandler(), newDefaultSignalHandler())
177+
return NewConnHandler(conn, NewDefaultHandler(), NewDefaultSignalHandler())
178178
}
179179

180180
// NewConnHandler creates a new private *Conn from an already established connection, using the supplied handlers.
@@ -368,7 +368,7 @@ func (conn *Conn) inWorker() {
368368
conn.namesLck.Unlock()
369369
}
370370
}
371-
go conn.handleSignal(msg)
371+
conn.handleSignal(msg)
372372
case TypeMethodCall:
373373
go conn.handleCall(msg)
374374
}

default_handler.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ func newIntrospectIntf(h *defaultHandler) *exportedIntf {
1818
return newExportedIntf(methods, true)
1919
}
2020

21-
func newDefaultHandler() *defaultHandler {
21+
//NewDefaultHandler returns an instance of the default
22+
//call handler. This is useful if you want to implement only
23+
//one of the two handlers but not both.
24+
func NewDefaultHandler() *defaultHandler {
2225
h := &defaultHandler{
2326
objects: make(map[ObjectPath]*exportedObj),
2427
defaultIntf: make(map[string]*exportedIntf),
@@ -214,7 +217,10 @@ func (obj *exportedIntf) isFallbackInterface() bool {
214217
return obj.includeSubtree
215218
}
216219

217-
func newDefaultSignalHandler() *defaultSignalHandler {
220+
//NewDefaultSignalHandler returns an instance of the default
221+
//signal handler. This is useful if you want to implement only
222+
//one of the two handlers but not both.
223+
func NewDefaultSignalHandler() *defaultSignalHandler {
218224
return &defaultSignalHandler{}
219225
}
220226

@@ -230,14 +236,16 @@ type defaultSignalHandler struct {
230236
}
231237

232238
func (sh *defaultSignalHandler) DeliverSignal(intf, name string, signal *Signal) {
233-
sh.RLock()
234-
defer sh.RUnlock()
235-
if sh.closed {
236-
return
237-
}
238-
for _, ch := range sh.signals {
239-
ch <- signal
240-
}
239+
go func() {
240+
sh.RLock()
241+
defer sh.RUnlock()
242+
if sh.closed {
243+
return
244+
}
245+
for _, ch := range sh.signals {
246+
ch <- signal
247+
}
248+
}()
241249
}
242250

243251
func (sh *defaultSignalHandler) Init() error {

0 commit comments

Comments
 (0)