Fix ss-server close

This commit is contained in:
世界 2022-05-15 23:52:19 +08:00
parent 2be8304e36
commit cd0e6406c3
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
14 changed files with 56 additions and 366 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"net"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
@ -33,8 +34,8 @@ type ServerConnError struct {
}
func (e *ServerConnError) Close() error {
if tcpConn, ok := e.Conn.(*net.TCPConn); ok {
tcpConn.SetLinger(0)
if conn, ok := common.Cast[*net.TCPConn](e.Conn); ok {
conn.SetLinger(0)
}
return e.Conn.Close()
}

View file

@ -53,18 +53,10 @@ func NewRawReader(upstream io.Reader, cipher cipher.AEAD, buffer []byte, nonce [
}
}
func (r *Reader) UpstreamReader() io.Reader {
func (r *Reader) Upstream() any {
return r.upstream
}
func (r *Reader) ReaderReplaceable() bool {
return false
}
func (r *Reader) SetReader(reader io.Reader) {
r.upstream = reader
}
func (r *Reader) WriteTo(writer io.Writer) (n int64, err error) {
if r.cached > 0 {
writeN, writeErr := writer.Write(r.buffer[r.index : r.index+r.cached])
@ -295,18 +287,10 @@ func NewRawWriter(upstream io.Writer, cipher cipher.AEAD, maxPacketSize int, buf
}
}
func (w *Writer) UpstreamWriter() io.Writer {
func (w *Writer) Upstream() any {
return w.upstream
}
func (w *Writer) WriterReplaceable() bool {
return false
}
func (w *Writer) SetWriter(writer io.Writer) {
w.upstream = writer
}
func (w *Writer) ReadFrom(r io.Reader) (n int64, err error) {
for {
offset := Overhead + PacketLengthBufferSize

View file

@ -279,26 +279,8 @@ func (c *clientConn) ReadFrom(r io.Reader) (n int64, err error) {
return c.writer.ReadFrom(r)
}
func (c *clientConn) UpstreamReader() io.Reader {
if c.reader == nil {
return c.Conn
}
return c.reader
}
func (c *clientConn) ReaderReplaceable() bool {
return c.reader != nil
}
func (c *clientConn) UpstreamWriter() io.Writer {
if c.writer == nil {
return c.Conn
}
return c.writer
}
func (c *clientConn) WriterReplaceable() bool {
return c.writer != nil
func (c *clientConn) Upstream() any {
return c.Conn
}
type clientPacketConn struct {
@ -375,18 +357,6 @@ func (c *clientPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
return len(p), nil
}
func (c *clientPacketConn) UpstreamReader() io.Reader {
func (c *clientPacketConn) Upstream() any {
return c.Conn
}
func (c *clientPacketConn) ReaderReplaceable() bool {
return false
}
func (c *clientPacketConn) UpstreamWriter() io.Writer {
return c.Conn
}
func (c *clientPacketConn) WriterReplaceable() bool {
return false
}

View file

@ -186,26 +186,8 @@ func (c *serverConn) WriteTo(w io.Writer) (n int64, err error) {
return c.reader.WriteTo(w)
}
func (c *serverConn) UpstreamReader() io.Reader {
if c.reader == nil {
return c.Conn
}
return c.reader
}
func (c *serverConn) ReaderReplaceable() bool {
return c.reader != nil
}
func (c *serverConn) UpstreamWriter() io.Writer {
if c.writer == nil {
return c.Conn
}
return c.writer
}
func (c *serverConn) WriterReplaceable() bool {
return c.writer != nil
func (c *serverConn) Upstream() any {
return c.Conn
}
func (s *Service) NewPacket(conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error {

View file

@ -394,26 +394,8 @@ func (c *clientConn) ReadFrom(r io.Reader) (n int64, err error) {
return c.writer.ReadFrom(r)
}
func (c *clientConn) UpstreamReader() io.Reader {
if c.reader == nil {
return c.Conn
}
return c.reader
}
func (c *clientConn) ReaderReplaceable() bool {
return c.reader != nil
}
func (c *clientConn) UpstreamWriter() io.Writer {
if c.writer == nil {
return c.Conn
}
return c.writer
}
func (c *clientConn) WriterReplaceable() bool {
return c.writer != nil
func (c *clientConn) Upstream() any {
return c.Conn
}
type clientPacketConn struct {
@ -732,18 +714,6 @@ func (m *Method) newUDPSession() *udpSession {
return session
}
func (c *clientPacketConn) UpstreamReader() io.Reader {
func (c *clientPacketConn) Upstream() any {
return c.Conn
}
func (c *clientPacketConn) ReaderReplaceable() bool {
return false
}
func (c *clientPacketConn) UpstreamWriter() io.Writer {
return c.Conn
}
func (c *clientPacketConn) WriterReplaceable() bool {
return false
}

View file

@ -279,26 +279,8 @@ func (c *serverConn) WriteTo(w io.Writer) (n int64, err error) {
return c.reader.WriteTo(w)
}
func (c *serverConn) UpstreamReader() io.Reader {
if c.reader == nil {
return c.Conn
}
return c.reader
}
func (c *serverConn) ReaderReplaceable() bool {
return c.reader != nil
}
func (c *serverConn) UpstreamWriter() io.Writer {
if c.writer == nil {
return c.Conn
}
return c.writer
}
func (c *serverConn) WriterReplaceable() bool {
return c.writer != nil
func (c *serverConn) Upstream() any {
return c.Conn
}
func (s *Service) NewPacket(conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error {

View file

@ -303,22 +303,10 @@ func (c *clientConn) Write(p []byte) (n int, err error) {
return c.Conn.Write(p)
}
func (c *clientConn) UpstreamReader() io.Reader {
func (c *clientConn) Upstream() any {
return c.Conn
}
func (c *clientConn) ReaderReplaceable() bool {
return false
}
func (c *clientConn) UpstreamWriter() io.Writer {
return c.Conn
}
func (c *clientConn) WriterReplaceable() bool {
return false
}
type clientPacketConn struct {
*Method
net.Conn
@ -400,18 +388,6 @@ func (c *clientPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
return len(p), nil
}
func (c *clientPacketConn) UpstreamReader() io.Reader {
func (c *clientPacketConn) Upstream() any {
return c.Conn
}
func (c *clientPacketConn) ReaderReplaceable() bool {
return false
}
func (c *clientPacketConn) UpstreamWriter() io.Writer {
return c.Conn
}
func (c *clientPacketConn) WriterReplaceable() bool {
return false
}