зеркало из https://github.com/microsoft/docker.git
Drop EofReader
This is not used any more Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
This commit is contained in:
Родитель
f198ee525a
Коммит
d8c888b3f8
27
utils.go
27
utils.go
|
@ -6,8 +6,6 @@ import (
|
|||
"github.com/dotcloud/docker/pkg/namesgenerator"
|
||||
"github.com/dotcloud/docker/runconfig"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"io"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type Change struct {
|
||||
|
@ -56,28 +54,3 @@ func (c *checker) Exists(name string) bool {
|
|||
func generateRandomName(runtime *Runtime) (string, error) {
|
||||
return namesgenerator.GenerateRandomName(&checker{runtime})
|
||||
}
|
||||
|
||||
// Read an io.Reader and call a function when it returns EOF
|
||||
func EofReader(r io.Reader, callback func()) *eofReader {
|
||||
return &eofReader{
|
||||
Reader: r,
|
||||
callback: callback,
|
||||
}
|
||||
}
|
||||
|
||||
type eofReader struct {
|
||||
io.Reader
|
||||
gotEOF int32
|
||||
callback func()
|
||||
}
|
||||
|
||||
func (r *eofReader) Read(p []byte) (n int, err error) {
|
||||
n, err = r.Reader.Read(p)
|
||||
if err == io.EOF {
|
||||
// Use atomics to make the gotEOF check threadsafe
|
||||
if atomic.CompareAndSwapInt32(&r.gotEOF, 0, 1) {
|
||||
r.callback()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче