-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from libp2p/qlog
export qlogs when the QLOGDIR env variable is set
- Loading branch information
Showing
5 changed files
with
100 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package libp2pquic | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
) | ||
|
||
type bufferedWriteCloser struct { | ||
*bufio.Writer | ||
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package libp2pquic | ||
|
||
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")) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters