This commit is contained in:
crusader 2018-03-09 18:11:03 +09:00
parent bd224840cf
commit dfb3b53775
2 changed files with 27 additions and 22 deletions

View File

@ -135,9 +135,9 @@ func (src *ServerRequestCodec) ReadParams(args []interface{}) error {
func (src *ServerRequestCodec) Params() ([]string, error) { func (src *ServerRequestCodec) Params() ([]string, error) {
if src.err == nil && src.req.Params != nil { if src.err == nil && src.req.Params != nil {
var results []string var values []interface{}
if err := json.Unmarshal(*src.req.Params, &results); err != nil { if err := json.Unmarshal(*src.req.Params, &values); err != nil {
src.err = &Error{ src.err = &Error{
Code: E_INVALID_REQ, Code: E_INVALID_REQ,
Message: err.Error(), Message: err.Error(),
@ -146,6 +146,20 @@ func (src *ServerRequestCodec) Params() ([]string, error) {
return nil, src.err return nil, src.err
} }
var results []string
for _, v := range values {
b, err := json.Marshal(v)
if nil != err {
src.err = &Error{
Code: E_INVALID_REQ,
Message: err.Error(),
Data: src.req.Params,
}
return nil, src.err
}
results = append(results, string(b))
}
return results, nil return results, nil
} }
return nil, src.err return nil, src.err

View File

@ -42,6 +42,10 @@ type rpcServlet struct {
stopWg sync.WaitGroup stopWg sync.WaitGroup
} }
func (s *rpcServlet) Context() ServletContext {
return s.ctx
}
func (s *rpcServlet) Start(parentCTX cuc.Context, conn interface{}, doneChan chan<- error) error { func (s *rpcServlet) Start(parentCTX cuc.Context, conn interface{}, doneChan chan<- error) error {
if nil == s.sh { if nil == s.sh {
panic("Servlet: servlet handler must be specified.") panic("Servlet: servlet handler must be specified.")
@ -80,17 +84,6 @@ func (s *rpcServlet) Start(parentCTX cuc.Context, conn interface{}, doneChan cha
return nil return nil
} }
func (s *rpcServlet) Stop() {
if s.stopChan == nil {
logging.Logger().Warn("Server: server must be started before stopping it")
return
}
close(s.stopChan)
s.destroy(nil)
}
func (s *rpcServlet) Send(method string, args ...interface{}) (err error) { func (s *rpcServlet) Send(method string, args ...interface{}) (err error) {
noti := &notification{ noti := &notification{
method: method, method: method,
@ -105,11 +98,12 @@ func (s *rpcServlet) Send(method string, args ...interface{}) (err error) {
return nil return nil
} }
func (s *rpcServlet) Context() ServletContext { func (s *rpcServlet) Stop() {
return s.ctx if s.stopChan == nil {
} logging.Logger().Warn("Server: server must be started before stopping it")
return
func (s *rpcServlet) destroy(err error) { }
close(s.stopChan)
s.stopWg.Wait() s.stopWg.Wait()
s.sh.Destroy(s.ctx) s.sh.Destroy(s.ctx)
@ -120,8 +114,6 @@ func (s *rpcServlet) destroy(err error) {
s.serverCodec = nil s.serverCodec = nil
logging.Logger().Info(fmt.Sprintf("Servlet is stopped")) logging.Logger().Info(fmt.Sprintf("Servlet is stopped"))
s.doneChan <- err
} }
func handleServlet(s *rpcServlet) { func handleServlet(s *rpcServlet) {
@ -131,7 +123,7 @@ func handleServlet(s *rpcServlet) {
defer func() { defer func() {
s.stopWg.Done() s.stopWg.Done()
s.destroy(err) s.doneChan <- err
}() }()
subStopChan := make(chan struct{}) subStopChan := make(chan struct{})
@ -158,7 +150,6 @@ func handleServlet(s *rpcServlet) {
if err != nil { if err != nil {
logging.Logger().Error(fmt.Sprintf("RPC Server: servlet error %v", err)) logging.Logger().Error(fmt.Sprintf("RPC Server: servlet error %v", err))
} }
} }
func handleReader(s *rpcServlet, stopChan chan struct{}, doneChan chan error) { func handleReader(s *rpcServlet, stopChan chan struct{}, doneChan chan error) {