Merge pull request #16 from iamqizhao/master

Deal with 0 timeout.
This commit is contained in:
Qi Zhao 2015-01-27 17:59:27 -08:00
commit 079097bda4
2 changed files with 6 additions and 3 deletions

View File

@ -156,7 +156,7 @@ func (t *http2Server) operateHeaders(hDec *hpackDecoder, s *Stream, frame header
s.windowHandler = func(n int) { s.windowHandler = func(n int) {
t.addRecvQuota(s, n) t.addRecvQuota(s, n)
} }
if hDec.state.timeout > 0 { if hDec.state.timeoutSet {
s.ctx, s.cancel = context.WithTimeout(context.TODO(), hDec.state.timeout) s.ctx, s.cancel = context.WithTimeout(context.TODO(), hDec.state.timeout)
} else { } else {
s.ctx, s.cancel = context.WithCancel(context.TODO()) s.ctx, s.cancel = context.WithCancel(context.TODO())
@ -426,6 +426,7 @@ func (t *http2Server) WriteStatus(s *Stream, statusCode codes.Code, statusDesc s
} }
s.mu.RUnlock() s.mu.RUnlock()
if _, err := wait(s.ctx, t.shutdownChan, t.writableChan); err != nil { if _, err := wait(s.ctx, t.shutdownChan, t.writableChan); err != nil {
// TODO(zhaoq): Print some errors using glog, e.g., glog.V(1).
return err return err
} }
t.hBuf.Reset() t.hBuf.Reset()

View File

@ -87,8 +87,9 @@ type decodeState struct {
statusCode codes.Code statusCode codes.Code
statusDesc string statusDesc string
// Server side only fields. // Server side only fields.
timeout time.Duration timeoutSet bool
method string timeout time.Duration
method string
// key-value metadata map from the peer. // key-value metadata map from the peer.
mdata map[string]string mdata map[string]string
} }
@ -144,6 +145,7 @@ func newHPACKDecoder() *hpackDecoder {
case "grpc-message": case "grpc-message":
d.state.statusDesc = f.Value d.state.statusDesc = f.Value
case "grpc-timeout": case "grpc-timeout":
d.state.timeoutSet = true
var err error var err error
d.state.timeout, err = timeoutDecode(f.Value) d.state.timeout, err = timeoutDecode(f.Value)
if err != nil { if err != nil {