Skip to content

Commit

Permalink
remove pkg/broadcaster and make it internal to container/streams
Browse files Browse the repository at this point in the history
This package was only used internally in container/streams and had
no external consumers.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Dec 28, 2024
1 parent f5af46d commit 44db31b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
13 changes: 6 additions & 7 deletions container/stream/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/containerd/containerd/cio"
"github.com/containerd/log"
"github.com/docker/docker/pkg/broadcaster"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/pools"
)
Expand All @@ -25,8 +24,8 @@ import (
// a kind of "broadcaster".
type Config struct {
wg sync.WaitGroup
stdout *broadcaster.Unbuffered
stderr *broadcaster.Unbuffered
stdout *unbuffered
stderr *unbuffered
stdin io.ReadCloser
stdinPipe io.WriteCloser
dio *cio.DirectIO
Expand All @@ -36,18 +35,18 @@ type Config struct {
// the standard err and standard out to new unbuffered broadcasters.
func NewConfig() *Config {
return &Config{
stderr: new(broadcaster.Unbuffered),
stdout: new(broadcaster.Unbuffered),
stderr: new(unbuffered),
stdout: new(unbuffered),
}
}

// Stdout returns the standard output in the configuration.
func (c *Config) Stdout() *broadcaster.Unbuffered {
func (c *Config) Stdout() io.Writer {
return c.stdout
}

// Stderr returns the standard error in the configuration.
func (c *Config) Stderr() *broadcaster.Unbuffered {
func (c *Config) Stderr() io.Writer {
return c.stderr
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/broadcaster/unbuffered.go → container/stream/unbuffered.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package broadcaster // import "github.com/docker/docker/pkg/broadcaster"
package stream

import (
"io"
"sync"
)

// Unbuffered accumulates multiple io.WriteCloser by stream.
type Unbuffered struct {
// unbuffered accumulates multiple io.WriteCloser by stream.
type unbuffered struct {
mu sync.Mutex
writers []io.WriteCloser
}

// Add adds new io.WriteCloser.
func (w *Unbuffered) Add(writer io.WriteCloser) {
func (w *unbuffered) Add(writer io.WriteCloser) {
w.mu.Lock()
w.writers = append(w.writers, writer)
w.mu.Unlock()
}

// Write writes bytes to all writers. Failed writers will be evicted during
// this call.
func (w *Unbuffered) Write(p []byte) (n int, err error) {
func (w *unbuffered) Write(p []byte) (n int, err error) {
w.mu.Lock()
var evict []int
for i, sw := range w.writers {
Expand All @@ -38,7 +38,7 @@ func (w *Unbuffered) Write(p []byte) (n int, err error) {

// Clean closes and removes all writers. Last non-eol-terminated part of data
// will be saved.
func (w *Unbuffered) Clean() error {
func (w *unbuffered) Clean() error {
w.mu.Lock()
for _, sw := range w.writers {
sw.Close()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package broadcaster // import "github.com/docker/docker/pkg/broadcaster"
package stream

import (
"bytes"
Expand Down Expand Up @@ -28,7 +28,7 @@ func (dw *dummyWriter) Close() error {
}

func TestUnbuffered(t *testing.T) {
writer := new(Unbuffered)
writer := new(unbuffered)

// Test 1: Both bufferA and bufferB should contain "foo"
bufferA := &dummyWriter{}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (d devNullCloser) Write(buf []byte) (int, error) {

// This test checks for races. It is only useful when run with the race detector.
func TestRaceUnbuffered(t *testing.T) {
writer := new(Unbuffered)
writer := new(unbuffered)
c := make(chan bool)
go func() {
writer.Add(devNullCloser(0))
Expand All @@ -125,7 +125,7 @@ func TestRaceUnbuffered(t *testing.T) {
}

func BenchmarkUnbuffered(b *testing.B) {
writer := new(Unbuffered)
writer := new(unbuffered)
setUpWriter := func() {
for i := 0; i < 100; i++ {
writer.Add(devNullCloser(0))
Expand Down

0 comments on commit 44db31b

Please sign in to comment.