Browse Source

Cleaned up some code in the random reader: use of the closed flag was racy. In

actual usage, reading after close will hang, which is OK for us.
master
J. David Lee 5 years ago
parent
commit
bcffe674e5
1 changed files with 0 additions and 7 deletions
  1. +0
    -7
      randreader.go

+ 0
- 7
randreader.go View File

@ -11,7 +11,6 @@ import (
type RandReader struct {
seed []byte
close chan bool
closed bool
stream chan byte
h hash.Hash
}
@ -20,7 +19,6 @@ func NewRandReader(seed []byte) *RandReader {
rr := RandReader{
seed: seed,
close: make(chan bool),
closed: false,
stream: make(chan byte),
h: sha512.New(),
}
@ -39,7 +37,6 @@ func (rr *RandReader) run() {
for _, b := range buf {
select {
case <-rr.close:
rr.closed = true
return
case rr.stream <- b:
@ -50,10 +47,6 @@ func (rr *RandReader) run() {
}
func (rr *RandReader) Read(p []byte) (n int, err error) {
if rr.closed {
panic("Reading from closed RandReader")
}
for i := range p {
p[i] = <-rr.stream
}


Loading…
Cancel
Save