@@ -88,8 +88,8 @@ func (h *exit) DialBind(network, local, remote string) (protect.Conn, error) {
8888}
8989
9090func (h * exit ) dial (network , local , remote string ) (protect.Conn , error ) {
91- if h .status . Load () == END {
92- return nil , errProxyStopped
91+ if err := candial ( h .status ); err != nil {
92+ return nil , err
9393 }
9494 // exit always splits
9595 c , err := localDialStrat (h .outbound , network , local , remote )
@@ -103,8 +103,8 @@ func (h *exit) dial(network, local, remote string) (protect.Conn, error) {
103103
104104// Announce implements Proxy.
105105func (h * exit ) Announce (network , local string ) (protect.PacketConn , error ) {
106- if h .status . Load () == END {
107- return nil , errProxyStopped
106+ if err := candial ( h .status ); err != nil {
107+ return nil , err
108108 }
109109 c , err := dialers .ListenPacket (h .outbound , network , local )
110110 defer localDialStatus (h .status , err )
@@ -114,16 +114,16 @@ func (h *exit) Announce(network, local string) (protect.PacketConn, error) {
114114
115115// Accept implements Proxy.
116116func (h * exit ) Accept (network , local string ) (protect.Listener , error ) {
117- if h .status . Load () == END {
118- return nil , errProxyStopped
117+ if err := candial ( h .status ); err != nil {
118+ return nil , err
119119 }
120120 return dialers .Listen (h .outbound , network , local )
121121}
122122
123123// Probe implements Proxy.
124124func (h * exit ) Probe (network , local string ) (protect.PacketConn , error ) {
125- if h .status . Load () == END {
126- return nil , errProxyStopped
125+ if err := candial ( h .status ); err != nil {
126+ return nil , err
127127 }
128128 c , err := dialers .Probe (h .outbound , network , local )
129129 defer localDialStatus (h .status , err )
@@ -174,15 +174,15 @@ func (h *exit) Stop() error {
174174 return nil
175175}
176176
177- func localDialStatus (status * core.Volatile [int ], err error ) {
178- if status .Load () == END {
179- return
177+ func localDialStatus (status * core.Volatile [int ], err error ) bool {
178+ cur := status .Load ()
179+ if cur == END || cur == TPU {
180+ return false
180181 }
181182 if err != nil {
182- status .Store (TKO )
183- } else {
184- status .Store (TOK )
183+ return status .Cas (cur , TKO )
185184 }
185+ return status .Cas (cur , TOK )
186186}
187187
188188func idhandle (p Proxy ) string {
0 commit comments