|
|
@ -214,7 +214,7 @@ func (c *Client) Send(dstKey key.Public, b []byte) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := client.Send(dstKey, b); err != nil {
|
|
|
|
if err := client.Send(dstKey, b); err != nil {
|
|
|
|
c.Close()
|
|
|
|
c.closeForReconnect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -226,7 +226,7 @@ func (c *Client) Recv(b []byte) (derp.ReceivedMessage, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m, err := client.Recv(b)
|
|
|
|
m, err := client.Recv(b)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
c.Close()
|
|
|
|
c.closeForReconnect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m, err
|
|
|
|
return m, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -242,12 +242,23 @@ func (c *Client) Close() error {
|
|
|
|
return ErrClientClosed
|
|
|
|
return ErrClientClosed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.closed = true
|
|
|
|
c.closed = true
|
|
|
|
|
|
|
|
if c.netConn != nil {
|
|
|
|
|
|
|
|
c.netConn.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// closeForReconnect closes the underlying network connection and
|
|
|
|
|
|
|
|
// zeros out the client field so future calls to Connect will
|
|
|
|
|
|
|
|
// reconnect.
|
|
|
|
|
|
|
|
func (c *Client) closeForReconnect() {
|
|
|
|
|
|
|
|
c.mu.Lock()
|
|
|
|
|
|
|
|
defer c.mu.Unlock()
|
|
|
|
if c.netConn != nil {
|
|
|
|
if c.netConn != nil {
|
|
|
|
c.netConn.Close()
|
|
|
|
c.netConn.Close()
|
|
|
|
c.netConn = nil
|
|
|
|
c.netConn = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.client = nil
|
|
|
|
c.client = nil
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var ErrClientClosed = errors.New("derphttp.Client closed")
|
|
|
|
var ErrClientClosed = errors.New("derphttp.Client closed")
|
|
|
|