Skip to content

Commit

Permalink
Merge 0bd1cc0 into 77fad75
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan committed Jun 28, 2018
2 parents 77fad75 + 0bd1cc0 commit 26fd7f5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.12: QmWudFxN9c6GECgcVCTKRdPJPbBd5nABheBM8VBCh7LKN4
1.0.13: QmenmbeGacw4oTgnYiFxLvZG3Wx8JCTu6iuWp72qyg2ZkH
19 changes: 11 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"

host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
protocol "github.com/libp2p/go-libp2p-protocol"
)
Expand Down Expand Up @@ -266,8 +267,6 @@ func (c *Client) send(call *Call) {
call.doneWithError(err)
return
}
defer s.Close()
go call.watchContextWithStream(s)

sWrap := wrapStream(s)

Expand All @@ -289,18 +288,22 @@ func (c *Client) send(call *Call) {
s.Reset()
return
}
receiveResponse(sWrap, call)
err := receiveResponse(sWrap, call)
if err != nil {
s.Reset()
return
}
go inet.FullClose(s)
}

// receiveResponse reads a response to an RPC call
func receiveResponse(s *streamWrap, call *Call) {
func receiveResponse(s *streamWrap, call *Call) error {
logger.Debugf("waiting response for %s.%s to %s", call.SvcID.Name,
call.SvcID.Method, call.Dest)
var resp Response
if err := s.dec.Decode(&resp); err != nil {
call.doneWithError(err)
s.stream.Reset()
return
return err
}

defer call.done()
Expand All @@ -312,7 +315,7 @@ func receiveResponse(s *streamWrap, call *Call) {
// read
if err := s.dec.Decode(call.Reply); err != nil && err != io.EOF {
call.setError(err)
s.stream.Reset()
return err
}
return
return nil
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"license": "MIT/BSD",
"name": "go-libp2p-gorpc",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.0.12"
"version": "1.0.13"
}

3 changes: 1 addition & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,14 @@ func NewServer(h host.Host, p protocol.ID) *Server {
if h != nil {
h.SetStreamHandler(p, func(stream inet.Stream) {
sWrap := wrapStream(stream)
defer stream.Close()
defer inet.FullClose(stream)
err := s.handle(sWrap)
if err != nil {
logger.Error("error handling RPC:", err)
resp := &Response{ServiceID{}, err.Error()}
sendResponse(sWrap, resp, nil)
}
})

}
return s
}
Expand Down

0 comments on commit 26fd7f5

Please sign in to comment.