mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 20:07:38 +03:00
Add bufio read/write only conn
This commit is contained in:
parent
57d12d875b
commit
53c9f8d137
1 changed files with 95 additions and 0 deletions
95
common/bufio/only.go
Normal file
95
common/bufio/only.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
package bufio
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ReadOnlyConn struct {
|
||||
reader io.Reader
|
||||
}
|
||||
|
||||
func NewReadOnlyConn(reader io.Reader) net.Conn {
|
||||
return &ReadOnlyConn{reader}
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) Read(b []byte) (n int, err error) {
|
||||
return c.reader.Read(b)
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) Write(b []byte) (n int, err error) {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) LocalAddr() net.Addr {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) RemoteAddr() net.Addr {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) SetDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) SetWriteDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) SetReadDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ReadOnlyConn) Upstream() any {
|
||||
return c.reader
|
||||
}
|
||||
|
||||
type WriteOnlyConn struct {
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
func NewWriteOnlyConn(writer io.Writer) net.Conn {
|
||||
return &WriteOnlyConn{writer}
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) Read(b []byte) (n int, err error) {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) Write(b []byte) (n int, err error) {
|
||||
return c.writer.Write(b)
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) LocalAddr() net.Addr {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) RemoteAddr() net.Addr {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) SetDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) SetWriteDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) SetReadDeadline(t time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *WriteOnlyConn) Upstream() any {
|
||||
return c.writer
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue