Skip to content

Commit

Permalink
log errors
Browse files Browse the repository at this point in the history
  • Loading branch information
name5566 committed Jul 25, 2016
1 parent 8ea5616 commit bdf2f7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
31 changes: 19 additions & 12 deletions chanrpc/chanrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/name5566/leaf/conf"
"github.com/name5566/leaf/log"
"runtime"
)

Expand Down Expand Up @@ -95,7 +96,7 @@ func (s *Server) ret(ci *CallInfo, ri *RetInfo) (err error) {
return
}

func (s *Server) Exec(ci *CallInfo) (err error) {
func (s *Server) exec(ci *CallInfo) (err error) {
defer func() {
if r := recover(); r != nil {
if conf.LenStackBuf > 0 {
Expand Down Expand Up @@ -126,6 +127,13 @@ func (s *Server) Exec(ci *CallInfo) (err error) {
panic("bug")
}

func (s *Server) Exec(ci *CallInfo) {
err := s.exec(ci)
if err != nil {
log.Error("%v", err)
}
}

// goroutine safe
func (s *Server) Go(id interface{}, args ...interface{}) {
f := s.functions[id]
Expand Down Expand Up @@ -294,9 +302,9 @@ func (c *Client) asynCall(id interface{}, args []interface{}, cb interface{}, n
}
}

func (c *Client) AsynCall(id interface{}, _args ...interface{}) error {
func (c *Client) AsynCall(id interface{}, _args ...interface{}) {
if len(_args) < 1 {
return errors.New("callback function not found")
panic("callback function not found")
}

args := _args[:len(_args)-1]
Expand All @@ -311,29 +319,28 @@ func (c *Client) AsynCall(id interface{}, _args ...interface{}) error {
case func([]interface{}, error):
n = 2
default:
return errors.New("definition of callback function is invalid")
panic("definition of callback function is invalid")
}

// too many calls
if c.pendingAsynCall >= cap(c.ChanAsynRet) {
err := execCb(&RetInfo{err: errors.New("too many calls"), cb: cb})
return err
execCb(&RetInfo{err: errors.New("too many calls"), cb: cb})
return
}

c.asynCall(id, args, cb, n)
c.pendingAsynCall++
return nil
}

func execCb(ri *RetInfo) (err error) {
func execCb(ri *RetInfo) {
defer func() {
if r := recover(); r != nil {
if conf.LenStackBuf > 0 {
buf := make([]byte, conf.LenStackBuf)
l := runtime.Stack(buf, false)
err = fmt.Errorf("%v: %s", r, buf[:l])
log.Error("%v: %s", r, buf[:l])
} else {
err = fmt.Errorf("%v", r)
log.Error("%v", r)
}
}
}()
Expand All @@ -352,9 +359,9 @@ func execCb(ri *RetInfo) (err error) {
return
}

func (c *Client) Cb(ri *RetInfo) error {
func (c *Client) Cb(ri *RetInfo) {
c.pendingAsynCall--
return execCb(ri)
execCb(ri)
}

func (c *Client) Close() {
Expand Down
11 changes: 2 additions & 9 deletions module/skeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/name5566/leaf/chanrpc"
"github.com/name5566/leaf/console"
"github.com/name5566/leaf/go"
"github.com/name5566/leaf/log"
"github.com/name5566/leaf/timer"
"time"
)
Expand Down Expand Up @@ -46,15 +45,9 @@ func (s *Skeleton) Run(closeSig chan bool) {
s.g.Close()
return
case ci := <-s.server.ChanCall:
err := s.server.Exec(ci)
if err != nil {
log.Error("%v", err)
}
s.server.Exec(ci)
case ci := <-s.commandServer.ChanCall:
err := s.commandServer.Exec(ci)
if err != nil {
log.Error("%v", err)
}
s.commandServer.Exec(ci)
case cb := <-s.g.ChanCb:
s.g.Cb(cb)
case t := <-s.dispatcher.ChanTimer:
Expand Down

0 comments on commit bdf2f7d

Please sign in to comment.