Skip to content

Commit

Permalink
use Link.Wait to wait loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Li Jian committed Apr 15, 2017
1 parent efbf3a4 commit dec4950
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 2 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (client *Client) startTCP() {
IsServerSide: false,
KeepaliveInterval: client.keepaliveInterval,
})
errCh, _ := l.Bind(conn)
l.Bind(conn)

for _, t := range client.tunnels {
proto, localHost, localPort, remoteHost, remotePort, reverse, err := parseTunnel(t)
Expand All @@ -185,9 +185,7 @@ func (client *Client) startTCP() {
l.OpenTunnel(proto, localHost, localPort, remoteHost, remotePort, reverse)
}

if err := <-errCh; err != nil {
logrus.WithField("error", err).Error("connection error")
}
l.Wait()
l.Close()
time.Sleep(1 * time.Second) // TODO: sleep smartly
}
Expand Down
7 changes: 2 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,8 @@ func (s *Server) handleTCPClient(conn es.Conn) {
IsServerSide: true,
KeepaliveInterval: s.keepaliveInterval,
})
errCh, _ := l.Bind(conn)
if err := <-errCh; err != nil {
logrus.WithField("error", err).Error("connection error")
}
// client 断开连接
l.Bind(conn)
l.Wait()
logrus.Warnf("client %#v is offline", conn)
l.Close()
conn.Close()
Expand Down

0 comments on commit dec4950

Please sign in to comment.