mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
crypto/rand: Added read buffer to speed up requests for small amounts of bytes.
R=agl1, rsc CC=golang-dev https://golang.org/cl/4170056
This commit is contained in:
parent
00d8d0052a
commit
712888910b
1 changed files with 3 additions and 2 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
package rand
|
package rand
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -23,7 +24,7 @@ func init() { Reader = &devReader{name: "/dev/urandom"} }
|
||||||
// A devReader satisfies reads by reading the file named name.
|
// A devReader satisfies reads by reading the file named name.
|
||||||
type devReader struct {
|
type devReader struct {
|
||||||
name string
|
name string
|
||||||
f *os.File
|
f io.Reader
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,7 +36,7 @@ func (r *devReader) Read(b []byte) (n int, err os.Error) {
|
||||||
if f == nil {
|
if f == nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
r.f = f
|
r.f = bufio.NewReader(f)
|
||||||
}
|
}
|
||||||
return r.f.Read(b)
|
return r.f.Read(b)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue