Add deadline reader/conn

This commit is contained in:
世界 2023-04-08 13:24:15 +08:00
parent cee74ef1f4
commit df54c89b04
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
10 changed files with 707 additions and 3 deletions

View file

@ -164,13 +164,13 @@ func (b *Buffer) WriteByte(d byte) error {
return nil
}
func (b *Buffer) ReadOnceFrom(r io.Reader) (int64, error) {
func (b *Buffer) ReadOnceFrom(r io.Reader) (int, error) {
if b.IsFull() {
return 0, io.ErrShortBuffer
}
n, err := r.Read(b.FreeBytes())
b.end += n
return int64(n), err
return n, err
}
func (b *Buffer) ReadPacketFrom(r net.PacketConn) (int64, net.Addr, error) {
@ -184,7 +184,8 @@ func (b *Buffer) ReadPacketFrom(r net.PacketConn) (int64, net.Addr, error) {
func (b *Buffer) ReadAtLeastFrom(r io.Reader, min int) (int64, error) {
if min <= 0 {
return b.ReadOnceFrom(r)
n, err := b.ReadOnceFrom(r)
return int64(n), err
}
if b.IsFull() {
return 0, io.ErrShortBuffer