diff options
author | bas-vk <bas-vk@users.noreply.github.com> | 2016-07-25 16:07:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-25 16:07:05 +0800 |
commit | 771655e3fee585ce4bc47dfaa279557c6c1c2421 (patch) | |
tree | 9071e157a54c40f06f0e5895643c82ca9a0b037a /rpc/server.go | |
parent | 60cd5bf9397bd8331bce3bb1884524d43c31dbb5 (diff) | |
parent | 91b769042857f542b2792b23ec407e1c9bd4fe8d (diff) | |
download | dexon-771655e3fee585ce4bc47dfaa279557c6c1c2421.tar dexon-771655e3fee585ce4bc47dfaa279557c6c1c2421.tar.gz dexon-771655e3fee585ce4bc47dfaa279557c6c1c2421.tar.bz2 dexon-771655e3fee585ce4bc47dfaa279557c6c1c2421.tar.lz dexon-771655e3fee585ce4bc47dfaa279557c6c1c2421.tar.xz dexon-771655e3fee585ce4bc47dfaa279557c6c1c2421.tar.zst dexon-771655e3fee585ce4bc47dfaa279557c6c1c2421.zip |
Merge pull request #2808 from fjl/rpc-client-3
rpc: add new client, use it everywhere
Diffstat (limited to 'rpc/server.go')
-rw-r--r-- | rpc/server.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/rpc/server.go b/rpc/server.go index 7b7d22063..040805a5c 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -21,7 +21,6 @@ import ( "reflect" "runtime" "sync/atomic" - "time" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" @@ -30,8 +29,6 @@ import ( ) const ( - stopPendingRequestTimeout = 3 * time.Second // give pending requests stopPendingRequestTimeout the time to finish when the server is stopped - notificationBufferSize = 10000 // max buffered notifications before codec is closed MetadataApi = "rpc" @@ -183,7 +180,7 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO for atomic.LoadInt32(&s.run) == 1 { reqs, batch, err := s.readRequest(codec) if err != nil { - glog.V(logger.Debug).Infof("%v\n", err) + glog.V(logger.Debug).Infof("read error %v\n", err) codec.Write(codec.CreateErrorResponse(nil, err)) return nil } @@ -240,13 +237,11 @@ func (s *Server) ServeSingleRequest(codec ServerCodec, options CodecOption) { func (s *Server) Stop() { if atomic.CompareAndSwapInt32(&s.run, 1, 0) { glog.V(logger.Debug).Infoln("RPC Server shutdown initiatied") - time.AfterFunc(stopPendingRequestTimeout, func() { - s.codecsMu.Lock() - defer s.codecsMu.Unlock() - s.codecs.Each(func(c interface{}) bool { - c.(ServerCodec).Close() - return true - }) + s.codecsMu.Lock() + defer s.codecsMu.Unlock() + s.codecs.Each(func(c interface{}) bool { + c.(ServerCodec).Close() + return true }) } } @@ -386,7 +381,7 @@ func (s *Server) execBatch(ctx context.Context, codec ServerCodec, requests []*s // readRequest requests the next (batch) request from the codec. It will return the collection // of requests, an indication if the request was a batch, the invalid request identifier and an // error when the request could not be read/parsed. -func (s *Server) readRequest(codec ServerCodec) ([]*serverRequest, bool, RPCError) { +func (s *Server) readRequest(codec ServerCodec) ([]*serverRequest, bool, Error) { reqs, batch, err := codec.ReadRequestHeaders() if err != nil { return nil, batch, err @@ -399,6 +394,11 @@ func (s *Server) readRequest(codec ServerCodec) ([]*serverRequest, bool, RPCErro var ok bool var svc *service + if r.err != nil { + requests[i] = &serverRequest{id: r.id, err: r.err} + continue + } + if r.isPubSub && r.method == unsubscribeMethod { requests[i] = &serverRequest{id: r.id, isUnsubscribe: true} argTypes := []reflect.Type{reflect.TypeOf("")} // expect subscription id as first arg |