mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
make the buffered qlog writer used in interop flush before closing
This commit is contained in:
parent
2f2583beb0
commit
3e8c3cafc1
5 changed files with 57 additions and 21 deletions
|
@ -62,13 +62,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("Creating qlog file %s.\n", filename)
|
||||
return struct {
|
||||
io.Writer
|
||||
io.Closer
|
||||
}{
|
||||
bufio.NewWriter(f),
|
||||
f,
|
||||
}
|
||||
return utils.NewBufferedWriteCloser(bufio.NewWriter(f), f)
|
||||
}
|
||||
}
|
||||
roundTripper := &http3.RoundTripper{
|
||||
|
|
|
@ -216,13 +216,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("Creating qlog file %s.\n", filename)
|
||||
return struct {
|
||||
io.Writer
|
||||
io.Closer
|
||||
}{
|
||||
bufio.NewWriter(f),
|
||||
f,
|
||||
}
|
||||
return utils.NewBufferedWriteCloser(bufio.NewWriter(f), f)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
26
internal/utils/buffered_write_closer.go
Normal file
26
internal/utils/buffered_write_closer.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
)
|
||||
|
||||
type bufferedWriteCloser struct {
|
||||
*bufio.Writer
|
||||
io.Closer
|
||||
}
|
||||
|
||||
// NewBufferedWriteCloser creates an io.WriteCloser from a bufio.Writer and an io.Closer
|
||||
func NewBufferedWriteCloser(writer *bufio.Writer, closer io.Closer) io.WriteCloser {
|
||||
return &bufferedWriteCloser{
|
||||
Writer: writer,
|
||||
Closer: closer,
|
||||
}
|
||||
}
|
||||
|
||||
func (h bufferedWriteCloser) Close() error {
|
||||
if err := h.Writer.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
return h.Closer.Close()
|
||||
}
|
26
internal/utils/buffered_write_closer_test.go
Normal file
26
internal/utils/buffered_write_closer_test.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
type nopCloser struct{}
|
||||
|
||||
func (nopCloser) Close() error { return nil }
|
||||
|
||||
var _ = Describe("buffered io.WriteCloser", func() {
|
||||
It("flushes before closing", func() {
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
w := bufio.NewWriter(buf)
|
||||
wc := NewBufferedWriteCloser(w, &nopCloser{})
|
||||
wc.Write([]byte("foobar"))
|
||||
Expect(buf.Len()).To(BeZero())
|
||||
Expect(wc.Close()).To(Succeed())
|
||||
Expect(buf.String()).To(Equal("foobar"))
|
||||
})
|
||||
})
|
|
@ -7,6 +7,8 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||
)
|
||||
|
||||
// GetSSLKeyLog creates a file for the TLS key log
|
||||
|
@ -39,12 +41,6 @@ func GetQLOGWriter() (func(connID []byte) io.WriteCloser, error) {
|
|||
if err != nil {
|
||||
log.Fatalf("Failed to create qlog file %s: %s", path, err.Error())
|
||||
}
|
||||
return struct {
|
||||
io.Writer
|
||||
io.Closer
|
||||
}{
|
||||
bufio.NewWriter(f),
|
||||
f,
|
||||
}
|
||||
return utils.NewBufferedWriteCloser(bufio.NewWriter(f), f)
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue