mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-05 04:47:40 +03:00
Refactor shadowsocks
This commit is contained in:
parent
3f23b25edf
commit
00cd0d4b8f
75 changed files with 3169 additions and 1318 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"crypto/rand"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/list"
|
||||
|
@ -188,6 +189,18 @@ func (b *Buffer) ReadFrom(r io.Reader) (int64, error) {
|
|||
return int64(n), nil
|
||||
}
|
||||
|
||||
func (b *Buffer) ReadPacketFrom(r net.PacketConn) (int64, net.Addr, error) {
|
||||
if b.IsFull() {
|
||||
return 0, nil, io.ErrShortBuffer
|
||||
}
|
||||
n, addr, err := r.ReadFrom(b.FreeBytes())
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
b.end += n
|
||||
return int64(n), addr, nil
|
||||
}
|
||||
|
||||
func (b *Buffer) ReadAtLeastFrom(r io.Reader, min int) (int64, error) {
|
||||
if min <= 0 {
|
||||
return b.ReadFrom(r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue