changed embedded mutex to private field (#153)
This commit is contained in:
8
http.go
8
http.go
@@ -41,7 +41,7 @@ type httpClient struct {
|
|||||||
funcStream client.FuncStream
|
funcStream client.FuncStream
|
||||||
httpcli *http.Client
|
httpcli *http.Client
|
||||||
opts client.Options
|
opts client.Options
|
||||||
sync.RWMutex
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRequest(ctx context.Context, log logger.Logger, addr string, req client.Request, ct string, cf codec.Codec, msg interface{}, opts client.CallOptions) (*http.Request, error) {
|
func newRequest(ctx context.Context, log logger.Logger, addr string, req client.Request, ct string, cf codec.Codec, msg interface{}, opts client.CallOptions) (*http.Request, error) {
|
||||||
@@ -294,18 +294,18 @@ func (c *httpClient) stream(ctx context.Context, addr string, req client.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *httpClient) newCodec(ct string) (codec.Codec, error) {
|
func (c *httpClient) newCodec(ct string) (codec.Codec, error) {
|
||||||
c.RLock()
|
c.mu.RLock()
|
||||||
|
|
||||||
if idx := strings.IndexRune(ct, ';'); idx >= 0 {
|
if idx := strings.IndexRune(ct, ';'); idx >= 0 {
|
||||||
ct = ct[:idx]
|
ct = ct[:idx]
|
||||||
}
|
}
|
||||||
|
|
||||||
if cf, ok := c.opts.Codecs[ct]; ok {
|
if cf, ok := c.opts.Codecs[ct]; ok {
|
||||||
c.RUnlock()
|
c.mu.RUnlock()
|
||||||
return cf, nil
|
return cf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
c.RUnlock()
|
c.mu.RUnlock()
|
||||||
return nil, codec.ErrUnknownContentType
|
return nil, codec.ErrUnknownContentType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
stream.go
14
stream.go
@@ -28,7 +28,7 @@ type httpStream struct {
|
|||||||
address string
|
address string
|
||||||
ct string
|
ct string
|
||||||
opts client.CallOptions
|
opts client.CallOptions
|
||||||
sync.RWMutex
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
var errShutdown = fmt.Errorf("connection is shut down")
|
var errShutdown = fmt.Errorf("connection is shut down")
|
||||||
@@ -59,8 +59,8 @@ func (h *httpStream) SendMsg(msg interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpStream) Send(msg interface{}) error {
|
func (h *httpStream) Send(msg interface{}) error {
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
defer h.Unlock()
|
defer h.mu.Unlock()
|
||||||
|
|
||||||
if h.isClosed() {
|
if h.isClosed() {
|
||||||
h.err = errShutdown
|
h.err = errShutdown
|
||||||
@@ -80,8 +80,8 @@ func (h *httpStream) RecvMsg(msg interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpStream) Recv(msg interface{}) error {
|
func (h *httpStream) Recv(msg interface{}) error {
|
||||||
h.Lock()
|
h.mu.Lock()
|
||||||
defer h.Unlock()
|
defer h.mu.Unlock()
|
||||||
|
|
||||||
if h.isClosed() {
|
if h.isClosed() {
|
||||||
h.err = errShutdown
|
h.err = errShutdown
|
||||||
@@ -98,8 +98,8 @@ func (h *httpStream) Recv(msg interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *httpStream) Error() error {
|
func (h *httpStream) Error() error {
|
||||||
h.RLock()
|
h.mu.RLock()
|
||||||
defer h.RUnlock()
|
defer h.mu.RUnlock()
|
||||||
return h.err
|
return h.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user