Skip to content

Commit

Permalink
Merge pull request #92 from jsouthworth/fix/move-async-signals
Browse files Browse the repository at this point in the history
Allow implementations to decide when to make signal handling asynchronous.
  • Loading branch information
jsouthworth authored Sep 18, 2017
2 parents 7f21b8d + 023e603 commit a389bdd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func Dial(address string) (*Conn, error) {
if err != nil {
return nil, err
}
return newConn(tr, newDefaultHandler(), newDefaultSignalHandler())
return newConn(tr, NewDefaultHandler(), NewDefaultSignalHandler())
}

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

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

// NewConnHandler creates a new private *Conn from an already established connection, using the supplied handlers.
Expand Down Expand Up @@ -368,7 +368,7 @@ func (conn *Conn) inWorker() {
conn.namesLck.Unlock()
}
}
go conn.handleSignal(msg)
conn.handleSignal(msg)
case TypeMethodCall:
go conn.handleCall(msg)
}
Expand Down
28 changes: 18 additions & 10 deletions default_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ func newIntrospectIntf(h *defaultHandler) *exportedIntf {
return newExportedIntf(methods, true)
}

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

func newDefaultSignalHandler() *defaultSignalHandler {
//NewDefaultSignalHandler returns an instance of the default
//signal handler. This is useful if you want to implement only
//one of the two handlers but not both.
func NewDefaultSignalHandler() *defaultSignalHandler {
return &defaultSignalHandler{}
}

Expand All @@ -230,14 +236,16 @@ type defaultSignalHandler struct {
}

func (sh *defaultSignalHandler) DeliverSignal(intf, name string, signal *Signal) {
sh.RLock()
defer sh.RUnlock()
if sh.closed {
return
}
for _, ch := range sh.signals {
ch <- signal
}
go func() {
sh.RLock()
defer sh.RUnlock()
if sh.closed {
return
}
for _, ch := range sh.signals {
ch <- signal
}
}()
}

func (sh *defaultSignalHandler) Init() error {
Expand Down

0 comments on commit a389bdd

Please sign in to comment.