optimize timeout of http(s)\socks\nat
Signed-off-by: arraykeys@gmail.com <arraykeys@gmail.com>
This commit is contained in:
@ -94,7 +94,9 @@ func (s *HTTP) InitService() {
|
|||||||
for {
|
for {
|
||||||
conn, err := utils.ConnectHost(s.Resolve(*s.cfg.Parent), *s.cfg.Timeout*2)
|
conn, err := utils.ConnectHost(s.Resolve(*s.cfg.Parent), *s.cfg.Timeout*2)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = conn.Write([]byte{0})
|
_, err = conn.Write([]byte{0})
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if s.sshClient != nil {
|
if s.sshClient != nil {
|
||||||
@ -215,7 +217,7 @@ func (s *HTTP) OutToTCP(useProxy bool, address string, inConn *net.Conn, req *ut
|
|||||||
if *s.cfg.ParentType == "ssh" {
|
if *s.cfg.ParentType == "ssh" {
|
||||||
outConn, err = s.getSSHConn(address)
|
outConn, err = s.getSSHConn(address)
|
||||||
} else {
|
} else {
|
||||||
//log.Printf("%v", s.outPool)
|
// log.Printf("%v", s.outPool)
|
||||||
_outConn, err = s.outPool.Pool.Get()
|
_outConn, err = s.outPool.Pool.Get()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
outConn = _outConn.(net.Conn)
|
outConn = _outConn.(net.Conn)
|
||||||
@ -237,16 +239,16 @@ func (s *HTTP) OutToTCP(useProxy bool, address string, inConn *net.Conn, req *ut
|
|||||||
utils.CloseConn(inConn)
|
utils.CloseConn(inConn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
outAddr := outConn.RemoteAddr().String()
|
outAddr := outConn.RemoteAddr().String()
|
||||||
//outLocalAddr := outConn.LocalAddr().String()
|
//outLocalAddr := outConn.LocalAddr().String()
|
||||||
|
|
||||||
if req.IsHTTPS() && (!useProxy || *s.cfg.ParentType == "ssh") {
|
if req.IsHTTPS() && (!useProxy || *s.cfg.ParentType == "ssh") {
|
||||||
//https无上级或者上级非代理,proxy需要响应connect请求,并直连目标
|
//https无上级或者上级非代理,proxy需要响应connect请求,并直连目标
|
||||||
err = req.HTTPSReply()
|
err = req.HTTPSReply()
|
||||||
} else {
|
} else {
|
||||||
//https或者http,上级是代理,proxy需要转发
|
//https或者http,上级是代理,proxy需要转发
|
||||||
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = outConn.Write(req.HeadBuf)
|
_, err = outConn.Write(req.HeadBuf)
|
||||||
|
outConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("write to %s , err:%s", *s.cfg.Parent, err)
|
log.Printf("write to %s , err:%s", *s.cfg.Parent, err)
|
||||||
utils.CloseConn(inConn)
|
utils.CloseConn(inConn)
|
||||||
|
|||||||
@ -75,7 +75,9 @@ func (s *MuxBridge) handler(inConn net.Conn) {
|
|||||||
var err error
|
var err error
|
||||||
var connType uint8
|
var connType uint8
|
||||||
var key string
|
var key string
|
||||||
|
inConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
err = utils.ReadPacket(reader, &connType, &key)
|
err = utils.ReadPacket(reader, &connType, &key)
|
||||||
|
inConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("read error,ERR:%s", err)
|
log.Printf("read error,ERR:%s", err)
|
||||||
return
|
return
|
||||||
@ -83,7 +85,9 @@ func (s *MuxBridge) handler(inConn net.Conn) {
|
|||||||
switch connType {
|
switch connType {
|
||||||
case CONN_SERVER:
|
case CONN_SERVER:
|
||||||
var serverID string
|
var serverID string
|
||||||
|
inConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
err = utils.ReadPacketData(reader, &serverID)
|
err = utils.ReadPacketData(reader, &serverID)
|
||||||
|
inConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("read error,ERR:%s", err)
|
log.Printf("read error,ERR:%s", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -68,7 +68,9 @@ func (s *MuxClient) Start(args interface{}) (err error) {
|
|||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = conn.Write(utils.BuildPacket(CONN_CLIENT, fmt.Sprintf("%s-%d", *s.cfg.Key, i)))
|
_, err = conn.Write(utils.BuildPacket(CONN_CLIENT, fmt.Sprintf("%s-%d", *s.cfg.Key, i)))
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
log.Printf("connection err: %s, retrying...", err)
|
log.Printf("connection err: %s, retrying...", err)
|
||||||
@ -98,7 +100,9 @@ func (s *MuxClient) Start(args interface{}) (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var ID, clientLocalAddr, serverID string
|
var ID, clientLocalAddr, serverID string
|
||||||
|
stream.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
err = utils.ReadPacketData(stream, &ID, &clientLocalAddr, &serverID)
|
err = utils.ReadPacketData(stream, &ID, &clientLocalAddr, &serverID)
|
||||||
|
stream.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("read stream signal err: %s", err)
|
log.Printf("read stream signal err: %s", err)
|
||||||
stream.Close()
|
stream.Close()
|
||||||
@ -140,7 +144,9 @@ func (s *MuxClient) getParentConn() (conn net.Conn, err error) {
|
|||||||
func (s *MuxClient) ServeUDP(inConn *smux.Stream, localAddr, ID string) {
|
func (s *MuxClient) ServeUDP(inConn *smux.Stream, localAddr, ID string) {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
inConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
srcAddr, body, err := utils.ReadUDPPacket(inConn)
|
srcAddr, body, err := utils.ReadUDPPacket(inConn)
|
||||||
|
inConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("udp packet revecived fail, err: %s", err)
|
log.Printf("udp packet revecived fail, err: %s", err)
|
||||||
log.Printf("connection %s released", ID)
|
log.Printf("connection %s released", ID)
|
||||||
@ -169,13 +175,16 @@ func (s *MuxClient) processUDPPacket(inConn *smux.Stream, srcAddr, localAddr str
|
|||||||
}
|
}
|
||||||
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = conn.Write(body)
|
_, err = conn.Write(body)
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("send udp packet to %s fail,ERR:%s", dstAddr.String(), err)
|
log.Printf("send udp packet to %s fail,ERR:%s", dstAddr.String(), err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//log.Printf("send udp packet to %s success", dstAddr.String())
|
//log.Printf("send udp packet to %s success", dstAddr.String())
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
length, _, err := conn.ReadFromUDP(buf)
|
length, _, err := conn.ReadFromUDP(buf)
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("read udp response from %s fail ,ERR:%s", dstAddr.String(), err)
|
log.Printf("read udp response from %s fail ,ERR:%s", dstAddr.String(), err)
|
||||||
return
|
return
|
||||||
@ -183,7 +192,9 @@ func (s *MuxClient) processUDPPacket(inConn *smux.Stream, srcAddr, localAddr str
|
|||||||
respBody := buf[0:length]
|
respBody := buf[0:length]
|
||||||
//log.Printf("revecived udp packet from %s , %v", dstAddr.String(), respBody)
|
//log.Printf("revecived udp packet from %s , %v", dstAddr.String(), respBody)
|
||||||
bs := utils.UDPPacket(srcAddr, respBody)
|
bs := utils.UDPPacket(srcAddr, respBody)
|
||||||
|
(*inConn).SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = (*inConn).Write(bs)
|
_, err = (*inConn).Write(bs)
|
||||||
|
(*inConn).SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("send udp response fail ,ERR:%s", err)
|
log.Printf("send udp response fail ,ERR:%s", err)
|
||||||
inConn.Close()
|
inConn.Close()
|
||||||
|
|||||||
@ -227,7 +227,9 @@ func (s *MuxServer) GetOutConn() (outConn net.Conn, ID string, err error) {
|
|||||||
remoteAddr = "udp:" + *s.cfg.Remote
|
remoteAddr = "udp:" + *s.cfg.Remote
|
||||||
}
|
}
|
||||||
ID = utils.Uniqueid()
|
ID = utils.Uniqueid()
|
||||||
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = outConn.Write(utils.BuildPacketData(ID, remoteAddr, s.cfg.Mgr.serverID))
|
_, err = outConn.Write(utils.BuildPacketData(ID, remoteAddr, s.cfg.Mgr.serverID))
|
||||||
|
outConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("write stream data err: %s ,retrying...", err)
|
log.Printf("write stream data err: %s ,retrying...", err)
|
||||||
utils.CloseConn(&outConn)
|
utils.CloseConn(&outConn)
|
||||||
@ -253,7 +255,9 @@ func (s *MuxServer) GetConn(index string) (conn net.Conn, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
c.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = c.Write(utils.BuildPacket(CONN_SERVER, *s.cfg.Key, s.cfg.Mgr.serverID))
|
_, err = c.Write(utils.BuildPacket(CONN_SERVER, *s.cfg.Key, s.cfg.Mgr.serverID))
|
||||||
|
c.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Close()
|
c.Close()
|
||||||
return
|
return
|
||||||
@ -327,7 +331,9 @@ func (s *MuxServer) UDPConnDeamon() {
|
|||||||
// outConn.Close()
|
// outConn.Close()
|
||||||
}()
|
}()
|
||||||
for {
|
for {
|
||||||
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
srcAddrFromConn, body, err := utils.ReadUDPPacket(outConn)
|
srcAddrFromConn, body, err := utils.ReadUDPPacket(outConn)
|
||||||
|
outConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("parse revecived udp packet fail, err: %s ,%v", err, body)
|
log.Printf("parse revecived udp packet fail, err: %s ,%v", err, body)
|
||||||
log.Printf("UDP deamon connection %s exited", ID)
|
log.Printf("UDP deamon connection %s exited", ID)
|
||||||
@ -341,7 +347,9 @@ func (s *MuxServer) UDPConnDeamon() {
|
|||||||
}
|
}
|
||||||
port, _ := strconv.Atoi(_srcAddr[1])
|
port, _ := strconv.Atoi(_srcAddr[1])
|
||||||
dstAddr := &net.UDPAddr{IP: net.ParseIP(_srcAddr[0]), Port: port}
|
dstAddr := &net.UDPAddr{IP: net.ParseIP(_srcAddr[0]), Port: port}
|
||||||
|
s.sc.UDPListener.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = s.sc.UDPListener.WriteToUDP(body, dstAddr)
|
_, err = s.sc.UDPListener.WriteToUDP(body, dstAddr)
|
||||||
|
s.sc.UDPListener.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("udp response to local %s fail,ERR:%s", srcAddrFromConn, err)
|
log.Printf("udp response to local %s fail,ERR:%s", srcAddrFromConn, err)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -104,7 +104,9 @@ func (s *Socks) InitService() {
|
|||||||
for {
|
for {
|
||||||
conn, err := utils.ConnectHost(s.Resolve(*s.cfg.Parent), *s.cfg.Timeout*2)
|
conn, err := utils.ConnectHost(s.Resolve(*s.cfg.Parent), *s.cfg.Timeout*2)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = conn.Write([]byte{0})
|
_, err = conn.Write([]byte{0})
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if s.sshClient != nil {
|
if s.sshClient != nil {
|
||||||
@ -216,6 +218,7 @@ func (s *Socks) udpCallback(b []byte, localAddr, srcAddr *net.UDPAddr) {
|
|||||||
}
|
}
|
||||||
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout*5)))
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout*5)))
|
||||||
_, err = conn.Write(rawB)
|
_, err = conn.Write(rawB)
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
log.Printf("udp request:%v", len(rawB))
|
log.Printf("udp request:%v", len(rawB))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("send udp packet to %s fail,ERR:%s", dstAddr.String(), err)
|
log.Printf("send udp packet to %s fail,ERR:%s", dstAddr.String(), err)
|
||||||
@ -225,7 +228,9 @@ func (s *Socks) udpCallback(b []byte, localAddr, srcAddr *net.UDPAddr) {
|
|||||||
|
|
||||||
//log.Printf("send udp packet to %s success", dstAddr.String())
|
//log.Printf("send udp packet to %s success", dstAddr.String())
|
||||||
buf := make([]byte, 10*1024)
|
buf := make([]byte, 10*1024)
|
||||||
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
length, _, err := conn.ReadFromUDP(buf)
|
length, _, err := conn.ReadFromUDP(buf)
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("read udp response from %s fail ,ERR:%s", dstAddr.String(), err)
|
log.Printf("read udp response from %s fail ,ERR:%s", dstAddr.String(), err)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
@ -250,10 +255,14 @@ func (s *Socks) udpCallback(b []byte, localAddr, srcAddr *net.UDPAddr) {
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.udpSC.UDPListener.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
s.udpSC.UDPListener.WriteToUDP(d, srcAddr)
|
s.udpSC.UDPListener.WriteToUDP(d, srcAddr)
|
||||||
|
s.udpSC.UDPListener.SetDeadline(time.Time{})
|
||||||
log.Printf("udp reply:%v", len(d))
|
log.Printf("udp reply:%v", len(d))
|
||||||
} else {
|
} else {
|
||||||
|
s.udpSC.UDPListener.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
s.udpSC.UDPListener.WriteToUDP(respBody, srcAddr)
|
s.udpSC.UDPListener.WriteToUDP(respBody, srcAddr)
|
||||||
|
s.udpSC.UDPListener.SetDeadline(time.Time{})
|
||||||
log.Printf("udp reply:%v", len(respBody))
|
log.Printf("udp reply:%v", len(respBody))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +281,7 @@ func (s *Socks) udpCallback(b []byte, localAddr, srcAddr *net.UDPAddr) {
|
|||||||
}
|
}
|
||||||
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout*3)))
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout*3)))
|
||||||
_, err = conn.Write(p.Data())
|
_, err = conn.Write(p.Data())
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
log.Printf("udp send:%v", len(p.Data()))
|
log.Printf("udp send:%v", len(p.Data()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("send udp packet to %s fail,ERR:%s", dstAddr.String(), err)
|
log.Printf("send udp packet to %s fail,ERR:%s", dstAddr.String(), err)
|
||||||
@ -280,7 +290,10 @@ func (s *Socks) udpCallback(b []byte, localAddr, srcAddr *net.UDPAddr) {
|
|||||||
}
|
}
|
||||||
//log.Printf("send udp packet to %s success", dstAddr.String())
|
//log.Printf("send udp packet to %s success", dstAddr.String())
|
||||||
buf := make([]byte, 10*1024)
|
buf := make([]byte, 10*1024)
|
||||||
|
conn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
length, _, err := conn.ReadFromUDP(buf)
|
length, _, err := conn.ReadFromUDP(buf)
|
||||||
|
conn.SetDeadline(time.Time{})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("read udp response from %s fail ,ERR:%s", dstAddr.String(), err)
|
log.Printf("read udp response from %s fail ,ERR:%s", dstAddr.String(), err)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
@ -297,9 +310,13 @@ func (s *Socks) udpCallback(b []byte, localAddr, srcAddr *net.UDPAddr) {
|
|||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.udpSC.UDPListener.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
s.udpSC.UDPListener.WriteToUDP(d, srcAddr)
|
s.udpSC.UDPListener.WriteToUDP(d, srcAddr)
|
||||||
|
s.udpSC.UDPListener.SetDeadline(time.Time{})
|
||||||
} else {
|
} else {
|
||||||
|
s.udpSC.UDPListener.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
s.udpSC.UDPListener.WriteToUDP(respPacket, srcAddr)
|
s.udpSC.UDPListener.WriteToUDP(respPacket, srcAddr)
|
||||||
|
s.udpSC.UDPListener.SetDeadline(time.Time{})
|
||||||
}
|
}
|
||||||
log.Printf("udp reply:%v", len(respPacket))
|
log.Printf("udp reply:%v", len(respPacket))
|
||||||
}
|
}
|
||||||
@ -371,9 +388,15 @@ func (s *Socks) socksConnCallback(inConn net.Conn) {
|
|||||||
//auth
|
//auth
|
||||||
_addr := strings.Split(inConn.RemoteAddr().String(), ":")
|
_addr := strings.Split(inConn.RemoteAddr().String(), ":")
|
||||||
if s.basicAuth.CheckUserPass(user, pass, _addr[0], "") {
|
if s.basicAuth.CheckUserPass(user, pass, _addr[0], "") {
|
||||||
|
inConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
inConn.Write([]byte{0x01, 0x00})
|
inConn.Write([]byte{0x01, 0x00})
|
||||||
|
inConn.SetDeadline(time.Time{})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
inConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
inConn.Write([]byte{0x01, 0x01})
|
inConn.Write([]byte{0x01, 0x01})
|
||||||
|
inConn.SetDeadline(time.Time{})
|
||||||
|
|
||||||
utils.CloseConn(&inConn)
|
utils.CloseConn(&inConn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -496,25 +519,32 @@ func (s *Socks) getOutConn(methodBytes, reqBytes []byte, host string) (outConn n
|
|||||||
}
|
}
|
||||||
var buf = make([]byte, 1024)
|
var buf = make([]byte, 1024)
|
||||||
//var n int
|
//var n int
|
||||||
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = outConn.Write(methodBytes)
|
_, err = outConn.Write(methodBytes)
|
||||||
|
outConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("write method fail,%s", err)
|
err = fmt.Errorf("write method fail,%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = outConn.Read(buf)
|
_, err = outConn.Read(buf)
|
||||||
|
outConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("read method reply fail,%s", err)
|
err = fmt.Errorf("read method reply fail,%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//resp := buf[:n]
|
//resp := buf[:n]
|
||||||
//log.Printf("resp:%v", resp)
|
//log.Printf("resp:%v", resp)
|
||||||
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = outConn.Write(reqBytes)
|
_, err = outConn.Write(reqBytes)
|
||||||
|
outConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("write req detail fail,%s", err)
|
err = fmt.Errorf("write req detail fail,%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = outConn.Read(buf)
|
_, err = outConn.Read(buf)
|
||||||
|
outConn.SetDeadline(time.Time{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("read req reply fail,%s", err)
|
err = fmt.Errorf("read req reply fail,%s", err)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user