@@ -9,10 +9,10 @@ import (
99
1010 "github.com/sagernet/sing-tun/internal/gtcpip/checksum"
1111 "github.com/sagernet/sing-tun/internal/gtcpip/header"
12- "github.com/sagernet/sing/common/atomic"
1312 "github.com/sagernet/sing/common/buf"
1413 "github.com/sagernet/sing/common/control"
1514 M "github.com/sagernet/sing/common/metadata"
15+ "github.com/sagernet/sing/common/pipe"
1616)
1717
1818type UnprivilegedConn struct {
@@ -21,7 +21,7 @@ type UnprivilegedConn struct {
2121 controlFunc control.Func
2222 destination netip.Addr
2323 receiveChan chan * unprivilegedResponse
24- readDeadline atomic. TypedValue [time. Time ]
24+ readDeadline pipe. Deadline
2525}
2626
2727type unprivilegedResponse struct {
@@ -53,6 +53,8 @@ func (c *UnprivilegedConn) Read(b []byte) (n int, err error) {
5353 packet .Buffer .Release ()
5454 packet .Cmsg .Release ()
5555 return
56+ case <- c .readDeadline .Wait ():
57+ return 0 , os .ErrDeadlineExceeded
5658 case <- c .ctx .Done ():
5759 return 0 , os .ErrClosed
5860 }
@@ -67,6 +69,8 @@ func (c *UnprivilegedConn) ReadMsg(b []byte, oob []byte) (n, oobn int, addr neti
6769 packet .Buffer .Release ()
6870 packet .Cmsg .Release ()
6971 return
72+ case <- c .readDeadline .Wait ():
73+ return 0 , 0 , netip.Addr {}, os .ErrDeadlineExceeded
7074 case <- c .ctx .Done ():
7175 return 0 , 0 , netip.Addr {}, os .ErrClosed
7276 }
@@ -85,9 +89,6 @@ func (c *UnprivilegedConn) Write(b []byte) (n int, err error) {
8589 icmpHdr := header .ICMPv6 (b )
8690 identifier = icmpHdr .Ident ()
8791 }
88- if readDeadline := c .readDeadline .Load (); ! readDeadline .IsZero () {
89- conn .SetReadDeadline (readDeadline )
90- }
9192 n , err = conn .Write (b )
9293 if err != nil {
9394 conn .Close ()
@@ -157,7 +158,7 @@ func (c *UnprivilegedConn) SetDeadline(t time.Time) error {
157158}
158159
159160func (c * UnprivilegedConn ) SetReadDeadline (t time.Time ) error {
160- c .readDeadline .Store (t )
161+ c .readDeadline .Set (t )
161162 return nil
162163}
163164
0 commit comments