Feature: add interval url test for load-balance

This commit is contained in:
Dreamacro
2019-03-28 19:00:41 +08:00
parent d3b280a7e5
commit 18f885a92a
3 changed files with 57 additions and 8 deletions

View File

@ -43,7 +43,9 @@ func (p *Proxy) Alive() bool {
func (p *Proxy) Dial(metadata *C.Metadata) (net.Conn, error) {
conn, err := p.ProxyAdapter.Dial(metadata)
p.alive = err == nil
if err != nil {
p.alive = false
}
return conn, err
}
@ -89,6 +91,7 @@ func (p *Proxy) MarshalJSON() ([]byte, error) {
// URLTest get the delay for the specified URL
func (p *Proxy) URLTest(url string) (t uint16, err error) {
defer func() {
p.alive = err == nil
record := C.DelayHistory{Time: time.Now()}
if err == nil {
record.Delay = t