Connection -> MConnection, huge refactor. True multiplexing.

This commit is contained in:
Jae Kwon
2014-07-28 01:41:25 -07:00
parent 197c8328c9
commit 34fe442514
19 changed files with 825 additions and 654 deletions

View File

@ -35,21 +35,35 @@ func (self ByteSlice) WriteTo(w io.Writer) (n int64, err error) {
return int64(n_ + 4), err
}
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 (self ByteSlice) Reader() io.Reader {
return bytes.NewReader([]byte(self))
}
func ReadByteSlice(r io.Reader) ByteSlice {
bytes, err := ReadByteSliceSafe(r)
func ReadByteSliceSafe(r io.Reader) (bytes ByteSlice, n int64, err error) {
length, n_, err := ReadUInt32Safe(r)
n += n_
if err != nil {
return nil, n, err
}
bytes = make([]byte, int(length))
n__, err := io.ReadFull(r, bytes)
n += int64(n__)
if err != nil {
return nil, n, err
}
return bytes, n, nil
}
func ReadByteSliceN(r io.Reader) (bytes ByteSlice, n int64) {
bytes, n, err := ReadByteSliceSafe(r)
if err != nil {
panic(err)
}
return bytes, n
}
func ReadByteSlice(r io.Reader) (bytes ByteSlice) {
bytes, _, err := ReadByteSliceSafe(r)
if err != nil {
panic(err)
}