Browse Source

Add debug String method to frameWriteMsg and writeData

Brad Fitzpatrick 11 years ago
parent
commit
021bb68637
2 changed files with 22 additions and 0 deletions
  1. 5 0
      write.go
  2. 17 0
      writesched.go

+ 5 - 0
write.go

@@ -9,6 +9,7 @@ package http2
 
 
 import (
 import (
 	"bytes"
 	"bytes"
+	"fmt"
 	"net/http"
 	"net/http"
 	"time"
 	"time"
 
 
@@ -80,6 +81,10 @@ type writeData struct {
 	endStream bool
 	endStream bool
 }
 }
 
 
+func (w *writeData) String() string {
+	return fmt.Sprintf("writeData(stream=%d, p=%d, endStream=%v)", w.streamID, len(w.p), w.endStream)
+}
+
 func (w *writeData) writeFrame(ctx writeContext) error {
 func (w *writeData) writeFrame(ctx writeContext) error {
 	return ctx.Framer().WriteData(w.streamID, w.endStream, w.p)
 	return ctx.Framer().WriteData(w.streamID, w.endStream, w.p)
 }
 }

+ 17 - 0
writesched.go

@@ -7,6 +7,8 @@
 
 
 package http2
 package http2
 
 
+import "fmt"
+
 // frameWriteMsg is a request to write a frame.
 // frameWriteMsg is a request to write a frame.
 type frameWriteMsg struct {
 type frameWriteMsg struct {
 	// write is the interface value that does the writing, once the
 	// write is the interface value that does the writing, once the
@@ -22,6 +24,21 @@ type frameWriteMsg struct {
 	done chan error
 	done chan error
 }
 }
 
 
+// for debugging only:
+func (wm frameWriteMsg) String() string {
+	var streamID uint32
+	if wm.stream != nil {
+		streamID = wm.stream.id
+	}
+	var des string
+	if s, ok := wm.write.(fmt.Stringer); ok {
+		des = s.String()
+	} else {
+		des = fmt.Sprintf("%T", wm.write)
+	}
+	return fmt.Sprintf("[frameWriteMsg stream=%d, ch=%v, type: %v]", streamID, wm.done != nil, des)
+}
+
 // writeScheduler tracks pending frames to write, priorities, and decides
 // writeScheduler tracks pending frames to write, priorities, and decides
 // the next one to use. It is not thread-safe.
 // the next one to use. It is not thread-safe.
 type writeScheduler struct {
 type writeScheduler struct {