Name timeout rather than deadline
This commit is contained in:
parent
56aaeff042
commit
66c38b75aa
@ -146,9 +146,9 @@ func (h *httpTransportClient) Send(m *Message) error {
|
|||||||
}
|
}
|
||||||
h.Unlock()
|
h.Unlock()
|
||||||
|
|
||||||
// set deadline if its greater than 0
|
// set timeout if its greater than 0
|
||||||
if h.ht.opts.Deadline > time.Duration(0) {
|
if h.ht.opts.Timeout > time.Duration(0) {
|
||||||
h.conn.SetDeadline(time.Now().Add(h.ht.opts.Deadline))
|
h.conn.SetDeadline(time.Now().Add(h.ht.opts.Timeout))
|
||||||
}
|
}
|
||||||
|
|
||||||
return req.Write(h.conn)
|
return req.Write(h.conn)
|
||||||
@ -170,9 +170,9 @@ func (h *httpTransportClient) Recv(m *Message) error {
|
|||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
// set deadline if its greater than 0
|
// set timeout if its greater than 0
|
||||||
if h.ht.opts.Deadline > time.Duration(0) {
|
if h.ht.opts.Timeout > time.Duration(0) {
|
||||||
h.conn.SetDeadline(time.Now().Add(h.ht.opts.Deadline))
|
h.conn.SetDeadline(time.Now().Add(h.ht.opts.Timeout))
|
||||||
}
|
}
|
||||||
|
|
||||||
rsp, err := http.ReadResponse(h.buff, r)
|
rsp, err := http.ReadResponse(h.buff, r)
|
||||||
@ -224,9 +224,9 @@ func (h *httpTransportSocket) Recv(m *Message) error {
|
|||||||
return errors.New("message passed in is nil")
|
return errors.New("message passed in is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
// set deadline if its greater than 0
|
// set timeout if its greater than 0
|
||||||
if h.ht.opts.Deadline > time.Duration(0) {
|
if h.ht.opts.Timeout > time.Duration(0) {
|
||||||
h.conn.SetDeadline(time.Now().Add(h.ht.opts.Deadline))
|
h.conn.SetDeadline(time.Now().Add(h.ht.opts.Timeout))
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := http.ReadRequest(h.buff)
|
r, err := http.ReadRequest(h.buff)
|
||||||
@ -288,9 +288,9 @@ func (h *httpTransportSocket) Send(m *Message) error {
|
|||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
// set deadline if its greater than 0
|
// set timeout if its greater than 0
|
||||||
if h.ht.opts.Deadline > time.Duration(0) {
|
if h.ht.opts.Timeout > time.Duration(0) {
|
||||||
h.conn.SetDeadline(time.Now().Add(h.ht.opts.Deadline))
|
h.conn.SetDeadline(time.Now().Add(h.ht.opts.Timeout))
|
||||||
}
|
}
|
||||||
|
|
||||||
return rsp.Write(h.conn)
|
return rsp.Write(h.conn)
|
||||||
|
@ -178,8 +178,8 @@ func TestHTTPTransportError(t *testing.T) {
|
|||||||
close(done)
|
close(done)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPTransportDeadline(t *testing.T) {
|
func TestHTTPTransportTimeout(t *testing.T) {
|
||||||
tr := NewTransport(Deadline(time.Millisecond * 100))
|
tr := NewTransport(Timeout(time.Millisecond * 100))
|
||||||
|
|
||||||
l, err := tr.Listen(":0")
|
l, err := tr.Listen(":0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -11,8 +11,8 @@ type Options struct {
|
|||||||
Addrs []string
|
Addrs []string
|
||||||
Secure bool
|
Secure bool
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
// Deadline sets the time to wait to Send/Recv
|
// Timeout sets the timeout for Send/Recv
|
||||||
Deadline time.Duration
|
Timeout time.Duration
|
||||||
// Other options for implementations of the interface
|
// Other options for implementations of the interface
|
||||||
// can be stored in a context
|
// can be stored in a context
|
||||||
Context context.Context
|
Context context.Context
|
||||||
@ -46,10 +46,10 @@ func Addrs(addrs ...string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deadline sets the time to wait for Send/Recv execution
|
// Timeout sets the timeout for Send/Recv execution
|
||||||
func Deadline(t time.Duration) Option {
|
func Timeout(t time.Duration) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Deadline = t
|
o.Timeout = t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user