// Discard the error which occurred during the creation of pipe buffer,
// redirecting the data transmission to the conventional way utilizing read() + write() as a fallback.
p := newPipe()
- if p != nil {
- runtime.SetFinalizer(p, destroyPipe)
+ if p == nil {
+ return nil
}
+ runtime.SetFinalizer(p, destroyPipe)
return p
}
func BenchmarkSplicePipe(b *testing.B) {
b.Run("SplicePipeWithPool", func(b *testing.B) {
for i := 0; i < b.N; i++ {
- p, _, _ := poll.GetPipe()
+ p, _, err := poll.GetPipe()
+ if err != nil {
+ continue
+ }
poll.PutPipe(p)
}
})
b.Run("SplicePipeWithoutPool", func(b *testing.B) {
for i := 0; i < b.N; i++ {
p := poll.NewPipe()
+ if p == nil {
+ b.Skip("newPipe returned nil")
+ }
poll.DestroyPipe(p)
}
})
func BenchmarkSplicePipePoolParallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
- p, _, _ := poll.GetPipe()
+ p, _, err := poll.GetPipe()
+ if err != nil {
+ continue
+ }
poll.PutPipe(p)
}
})
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
p := poll.NewPipe()
+ if p == nil {
+ b.Skip("newPipe returned nil")
+ }
poll.DestroyPipe(p)
}
})