diff --git a/app/commander/outbound.go b/app/commander/outbound.go index 99ed49bd9..3a874921d 100644 --- a/app/commander/outbound.go +++ b/app/commander/outbound.go @@ -19,7 +19,7 @@ type OutboundListener struct { func (l *OutboundListener) add(conn net.Conn) { select { case l.buffer <- conn: - case <-l.done.C(): + case <-l.done.Wait(): common.Ignore(conn.Close(), "We can do nothing if Close() returns error.") default: common.Ignore(conn.Close(), "We can do nothing if Close() returns error.") @@ -29,7 +29,7 @@ func (l *OutboundListener) add(conn net.Conn) { // Accept implements net.Listener. func (l *OutboundListener) Accept() (net.Conn, error) { select { - case <-l.done.C(): + case <-l.done.Wait(): return nil, newError("listen closed") case c := <-l.buffer: return c, nil diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index fbc10a4ab..8a8194673 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -134,7 +134,7 @@ func (c *udpConn) Read(buf []byte) (int, error) { c.uplink.Add(int64(nBytes)) } return nBytes, nil - case <-c.done.C(): + case <-c.done.Wait(): return 0, io.EOF } } @@ -239,7 +239,7 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest conn, existing := w.getConnection(id) select { case conn.input <- b: - case <-conn.done.C(): + case <-conn.done.Wait(): b.Release() default: b.Release() @@ -308,7 +308,7 @@ func (w *udpWorker) monitor() { for { select { - case <-w.done.C(): + case <-w.done.Wait(): return case <-timer.C: nowSec := time.Now().Unix() diff --git a/app/proxyman/mux/mux.go b/app/proxyman/mux/mux.go index 25c26a65a..ce9bea438 100644 --- a/app/proxyman/mux/mux.go +++ b/app/proxyman/mux/mux.go @@ -125,7 +125,7 @@ func (m *Client) monitor() { for { select { - case <-m.done.C(): + case <-m.done.Wait(): m.sessionManager.Close() m.inboundRay.InboundInput().Close() m.inboundRay.InboundOutput().CloseError() diff --git a/common/log/logger.go b/common/log/logger.go index b3008720b..0e4293519 100644 --- a/common/log/logger.go +++ b/common/log/logger.go @@ -51,7 +51,7 @@ func (l *generalLogger) run() { for { select { - case <-l.done.C(): + case <-l.done.Wait(): return case msg := <-l.buffer: logger.Write(msg.String() + platform.LineSeparator()) diff --git a/common/signal/done.go b/common/signal/done.go index 351f8c630..cbf59acc8 100755 --- a/common/signal/done.go +++ b/common/signal/done.go @@ -21,23 +21,18 @@ func NewDone() *Done { // Done returns true if Close() is called. func (d *Done) Done() bool { select { - case <-d.c: + case <-d.Wait(): return true default: return false } } -// C returns a channel for waiting for done. -func (d *Done) C() chan struct{} { +// Wait returns a channel for waiting for done. +func (d *Done) Wait() <-chan struct{} { return d.c } -// Wait blocks until Close() is called. -func (d *Done) Wait() { - <-d.c -} - // Close marks this Done 'done'. This method may be called multiple times. All calls after first call will have no effect on its status. func (d *Done) Close() error { d.access.Lock() diff --git a/transport/internet/http/hub.go b/transport/internet/http/hub.go index b15f54049..6c9828452 100644 --- a/transport/internet/http/hub.go +++ b/transport/internet/http/hub.go @@ -71,7 +71,7 @@ func (l *Listener) ServeHTTP(writer http.ResponseWriter, request *http.Request) Local: l.Addr(), Remote: l.Addr(), }) - <-done.C() + <-done.Wait() } func Listen(ctx context.Context, address net.Address, port net.Port, handler internet.ConnHandler) (internet.Listener, error) {