Skip to content

Commit

Permalink
Merge pull request #433 from iamqizhao/master
Browse files Browse the repository at this point in the history
Attach the payload from ping frame to ping ack
  • Loading branch information
iamqizhao committed Nov 6, 2015
2 parents 93a9ed0 + bcd6f37 commit 1684e4a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion transport/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func (flushIO) isItem() bool {
}

type ping struct {
ack bool
ack bool
data [8]byte
}

func (ping) isItem() bool {
Expand Down
8 changes: 4 additions & 4 deletions transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,9 @@ func (t *http2Client) handleSettings(f *http2.SettingsFrame) {
}

func (t *http2Client) handlePing(f *http2.PingFrame) {
t.controlBuf.put(&ping{true})
pingAck := &ping{ack: true}
copy(pingAck.data[:], f.Data[:])
t.controlBuf.put(pingAck)
}

func (t *http2Client) handleGoAway(f *http2.GoAwayFrame) {
Expand Down Expand Up @@ -827,9 +829,7 @@ func (t *http2Client) controller() {
case *flushIO:
t.framer.flushWrite()
case *ping:
// TODO(zhaoq): Ack with all-0 data now. will change to some
// meaningful content when this is actually in use.
t.framer.writePing(true, i.ack, [8]byte{})
t.framer.writePing(true, i.ack, i.data)
default:
grpclog.Printf("transport: http2Client.controller got unexpected item type %v\n", i)
}
Expand Down
8 changes: 4 additions & 4 deletions transport/http2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ func (t *http2Server) handleSettings(f *http2.SettingsFrame) {
}

func (t *http2Server) handlePing(f *http2.PingFrame) {
t.controlBuf.put(&ping{true})
pingAck := &ping{ack: true}
copy(pingAck.data[:], f.Data[:])
t.controlBuf.put(pingAck)
}

func (t *http2Server) handleWindowUpdate(f *http2.WindowUpdateFrame) {
Expand Down Expand Up @@ -628,9 +630,7 @@ func (t *http2Server) controller() {
case *flushIO:
t.framer.flushWrite()
case *ping:
// TODO(zhaoq): Ack with all-0 data now. will change to some
// meaningful content when this is actually in use.
t.framer.writePing(true, i.ack, [8]byte{})
t.framer.writePing(true, i.ack, i.data)
default:
grpclog.Printf("transport: http2Server.controller got unexpected item type %v\n", i)
}
Expand Down
12 changes: 6 additions & 6 deletions transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,12 @@ func TestServerContextCanceledOnClosedConnection(t *testing.T) {
}
cc.Close()
select {
case <-ss.Context().Done():
if ss.Context().Err() != context.Canceled {
t.Fatalf("ss.Context().Err() got %v, want %v", ss.Context().Err(), context.Canceled)
}
case <-time.After(5 * time.Second):
t.Fatalf("Failed to cancel the context of the sever side stream.")
case <-ss.Context().Done():
if ss.Context().Err() != context.Canceled {
t.Fatalf("ss.Context().Err() got %v, want %v", ss.Context().Err(), context.Canceled)
}
case <-time.After(5 * time.Second):
t.Fatalf("Failed to cancel the context of the sever side stream.")
}
}

Expand Down

0 comments on commit 1684e4a

Please sign in to comment.