From 1eaade8434ac79f3da516a619bc0bfc9db6e01ea Mon Sep 17 00:00:00 2001 From: Dingjun Date: Sat, 8 Apr 2017 10:49:16 +0800 Subject: [PATCH] use empty struct as signal context --- client.go | 10 +++++----- server.go | 4 ++-- util.go | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index e11a174..b14e891 100644 --- a/client.go +++ b/client.go @@ -17,7 +17,7 @@ type Client struct { sshConn ssh.Conn client *ssh.Client listeners []net.Listener - ch chan int + ch chan struct{} } // NewClient create a new ssh Client @@ -51,7 +51,7 @@ func NewClient(c net.Conn, config *ssh.ClientConfig, addr string, conf *Conf) (* sshClient := ssh.NewClient(sshConn, newch, reqs) client := &Client{ conn: c, sshConn: sshConn, client: sshClient, - ch: make(chan int), + ch: make(chan struct{}), } go client.keepAlive(conf.KeepAliveInterval, conf.KeepAliveMax) return client, nil @@ -74,7 +74,7 @@ func (cc *Client) Run() { go func() { cc.sshConn.Wait() select { - case cc.ch <- 1: + case cc.ch <- struct{}{}: default: } }() @@ -305,7 +305,7 @@ func (cc *Client) keepAlive(interval time.Duration, maxCount int) { cc.sshConn.Close() // send exit signal select { - case cc.ch <- 1: + case cc.ch <- struct{}{}: default: } return @@ -321,7 +321,7 @@ func (cc *Client) registerSignal() { case s1 := <-c: Log(ERROR, "signal %d received, exit", s1) select { - case cc.ch <- 1: + case cc.ch <- struct{}{}: default: } } diff --git a/server.go b/server.go index 8f0d45f..6b41280 100644 --- a/server.go +++ b/server.go @@ -12,7 +12,7 @@ type Server struct { conn net.Conn sshConn *ssh.ServerConn forwardedPorts map[string]net.Listener - exitCh chan int + exitCh chan struct{} } // NewServer create a new struct for Server @@ -47,7 +47,7 @@ func NewServer(c net.Conn, config *ssh.ServerConfig, conf *Conf) (*Server, error sc := &Server{conn: c, sshConn: sshConn, forwardedPorts: map[string]net.Listener{}, - exitCh: make(chan int)} + exitCh: make(chan struct{})} go sc.handleGlobalRequest(req) go sc.handleNewChannelRequest(ch) return sc, nil diff --git a/util.go b/util.go index b8fce2b..65f47f5 100644 --- a/util.go +++ b/util.go @@ -22,16 +22,16 @@ var SSHLogLevel = ERROR func PipeAndClose(c io.ReadWriteCloser, s io.ReadWriteCloser) { defer c.Close() defer s.Close() - cc := make(chan int, 2) + cc := make(chan struct{}, 2) go func() { io.Copy(c, s) - cc <- 1 + cc <- struct{}{} }() go func() { io.Copy(s, c) - cc <- 1 + cc <- struct{}{} }() <-cc