-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientconn.go
37 lines (29 loc) · 868 Bytes
/
clientconn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package brpc
import (
"context"
"net"
"google.golang.org/grpc"
)
const (
defaultConcurrency = 128
)
var _ grpc.ClientConnInterface = &ClientConn{}
type ClientConn struct {
s *stream
}
// Invoke performs a unary RPC and returns after the response is received
// into reply.
func (c *ClientConn) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error {
return c.s.Invoke(ctx, method, args, reply, opts...)
}
func (c *ClientConn) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error) {
return nil, nil
}
func DialContext(ctx context.Context, address string) (*ClientConn, error) {
conn, err := net.Dial("tcp", address)
if err != nil {
return nil, err
}
s := newStream(conn, defaultConcurrency)
return &ClientConn{s: s}, nil
}