1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 15:36:41 -05:00

fix command listener

This commit is contained in:
Darien Raymond 2018-02-08 23:37:47 +01:00
parent c05dade00a
commit c1fc7c738a
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 20 additions and 5 deletions

View File

@ -10,6 +10,7 @@ import (
"google.golang.org/grpc"
"v2ray.com/core"
"v2ray.com/core/common"
"v2ray.com/core/common/signal"
)
type Commander struct {
@ -58,6 +59,7 @@ func (c *Commander) Start() error {
listener := &OutboundListener{
buffer: make(chan net.Conn, 4),
done: signal.NewDone(),
}
go func() {

View File

@ -11,26 +11,39 @@ import (
type OutboundListener struct {
buffer chan net.Conn
done *signal.Done
}
func (l *OutboundListener) add(conn net.Conn) {
select {
case l.buffer <- conn:
case <-l.done.C():
conn.Close()
default:
conn.Close()
}
}
func (l *OutboundListener) Accept() (net.Conn, error) {
c, open := <-l.buffer
if !open {
return nil, newError("listener closed")
}
select {
case <-l.done.C():
return nil, newError("listern closed")
case c := <-l.buffer:
return c, nil
}
}
func (l *OutboundListener) Close() error {
close(l.buffer)
l.done.Close()
L:
for {
select {
case c := <-l.buffer:
c.Close()
default:
break L
}
}
return nil
}