first client/server connection test passes.

This commit is contained in:
Jae Kwon
2014-06-30 16:53:04 -07:00
parent e52166017d
commit a714d12085
9 changed files with 217 additions and 209 deletions

View File

@ -33,18 +33,17 @@ func (self ByteSlice) WriteTo(w io.Writer) (n int64, err error) {
return int64(n_+4), err
}
func ReadByteSlice(r io.Reader) ByteSlice {
length := int(ReadUInt32(r))
bytes := make([]byte, length)
_, err := io.ReadFull(r, bytes)
if err != nil { panic(err) }
return ByteSlice(bytes)
func ReadByteSliceSafe(r io.Reader) (ByteSlice, error) {
length, err := ReadUInt32Safe(r)
if err != nil { return nil, err }
bytes := make([]byte, int(length))
_, err = io.ReadFull(r, bytes)
if err != nil { return nil, err }
return bytes, nil
}
func ReadByteSliceSafe(r io.Reader) (ByteSlice, error) {
length := int(ReadUInt32(r))
bytes := make([]byte, length)
_, err := io.ReadFull(r, bytes)
if err != nil { return nil, err }
return ByteSlice(bytes), nil
func ReadByteSlice(r io.Reader) ByteSlice {
bytes, err := ReadByteSliceSafe(r)
if r != nil { panic(err) }
return bytes
}