all: add "--reload" command for frps, reload ini file without kill old program

This commit is contained in:
fatedier
2016-06-03 17:51:45 +08:00
parent ee8786a6b3
commit 5febee6201
9 changed files with 203 additions and 42 deletions

View File

@@ -92,6 +92,7 @@ type Conn struct {
TcpConn net.Conn
Reader *bufio.Reader
closeFlag bool
mutex sync.RWMutex
}
func NewConn(conn net.Conn) (c *Conn) {
@@ -129,7 +130,9 @@ func (c *Conn) GetLocalAddr() (addr string) {
func (c *Conn) ReadLine() (buff string, err error) {
buff, err = c.Reader.ReadString('\n')
if err == io.EOF {
c.mutex.Lock()
c.closeFlag = true
c.mutex.Unlock()
}
return buff, err
}
@@ -146,14 +149,19 @@ func (c *Conn) SetDeadline(t time.Time) error {
}
func (c *Conn) Close() {
c.mutex.Lock()
if c.TcpConn != nil && c.closeFlag == false {
c.closeFlag = true
c.TcpConn.Close()
}
c.mutex.Unlock()
}
func (c *Conn) IsClosed() bool {
return c.closeFlag
func (c *Conn) IsClosed() (closeFlag bool) {
c.mutex.RLock()
closeFlag = c.closeFlag
c.mutex.RUnlock()
return
}
// will block until connection close