mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-05 21:07:41 +03:00
Add deadline reader/conn
This commit is contained in:
parent
cee74ef1f4
commit
df54c89b04
10 changed files with 707 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue