mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-07-02 15:23:41 +02:00
fix: don't apply nil CallOption and ConnOpt
This commit is contained in:
parent
549eb959f0
commit
3e2e814648
2 changed files with 13 additions and 4 deletions
13
jsonrpc2.go
13
jsonrpc2.go
|
|
@ -315,14 +315,17 @@ var ErrClosed = errors.New("jsonrpc2: connection is closed")
|
||||||
//
|
//
|
||||||
// NewClient consumes conn, so you should call Close on the returned
|
// NewClient consumes conn, so you should call Close on the returned
|
||||||
// client not on the given conn.
|
// client not on the given conn.
|
||||||
func NewConn(ctx context.Context, stream ObjectStream, h Handler, opt ...ConnOpt) *Conn {
|
func NewConn(ctx context.Context, stream ObjectStream, h Handler, opts ...ConnOpt) *Conn {
|
||||||
c := &Conn{
|
c := &Conn{
|
||||||
stream: stream,
|
stream: stream,
|
||||||
h: h,
|
h: h,
|
||||||
pending: map[ID]*call{},
|
pending: map[ID]*call{},
|
||||||
disconnect: make(chan struct{}),
|
disconnect: make(chan struct{}),
|
||||||
}
|
}
|
||||||
for _, opt := range opt {
|
for _, opt := range opts {
|
||||||
|
if opt == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
opt(c)
|
opt(c)
|
||||||
}
|
}
|
||||||
go c.readMessages(ctx)
|
go c.readMessages(ctx)
|
||||||
|
|
@ -415,6 +418,9 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
|
if opt == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := opt.apply(req); err != nil {
|
if err := opt.apply(req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -458,6 +464,9 @@ func (c *Conn) Notify(ctx context.Context, method string, params interface{}, op
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
|
if opt == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := opt.apply(req); err != nil {
|
if err := opt.apply(req); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -409,12 +409,12 @@ func TestConn_Close_waitingForResponse(t *testing.T) {
|
||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func serve(ctx context.Context, lis net.Listener, h jsonrpc2.Handler, opt ...jsonrpc2.ConnOpt) error {
|
func serve(ctx context.Context, lis net.Listener, h jsonrpc2.Handler, opts ...jsonrpc2.ConnOpt) error {
|
||||||
for {
|
for {
|
||||||
conn, err := lis.Accept()
|
conn, err := lis.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(conn, jsonrpc2.VarintObjectCodec{}), h, opt...)
|
jsonrpc2.NewConn(ctx, jsonrpc2.NewBufferedStream(conn, jsonrpc2.VarintObjectCodec{}), h, opts...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue