Fix length bug in mockNetChan.

Using the length of the provided buffer is dangerous after the first buffered
read from it, as it'll be the length of the buffer size...
This commit is contained in:
Alex Bramley 2011-11-11 08:34:55 +00:00
parent 38cd23891a
commit 0d4e83ea7f
1 changed files with 4 additions and 2 deletions

View File

@ -103,13 +103,15 @@ func (m *mockNetConn) Read(b []byte) (int, os.Error) {
if m.closed {
return 0, os.EINVAL
}
l := 0
select {
case s := <-m.in:
l = len(s)
copy(b, s)
case <-m.rc:
return 0, os.EOF
}
return len(b), nil
return l, nil
}
func (m *mockNetConn) Write(s []byte) (int, os.Error) {
@ -119,7 +121,7 @@ func (m *mockNetConn) Write(s []byte) (int, os.Error) {
b := make([]byte, len(s))
copy(b, s)
m.out <- b
return len(b), nil
return len(s), nil
}
func (m *mockNetConn) Close() os.Error {