Commit a8f2e95a authored by AlexStocks's avatar AlexStocks

time.Sleep() -> wheel.After()

parent 96c2170a
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
* close net.UDPConn when connected failed * close net.UDPConn when connected failed
* close net.Conn when connected failed * close net.Conn when connected failed
* Session::EndPointType() -> Session::EndPoint() * Session::EndPointType() -> Session::EndPoint()
* time.Sleep() -> wheel.After()
* do not check server.go:server::caCert
- 2018/03/17 - 2018/03/17
> improvement > improvement
......
...@@ -135,7 +135,8 @@ func (c *client) dialTCP() Session { ...@@ -135,7 +135,8 @@ func (c *client) dialTCP() Session {
} }
log.Info("net.DialTimeout(addr:%s, timeout:%v) = error{%s}", c.addr, err) log.Info("net.DialTimeout(addr:%s, timeout:%v) = error{%s}", c.addr, err)
time.Sleep(connInterval) // time.Sleep(connInterval)
<-wheel.After(connInterval)
} }
} }
...@@ -163,7 +164,8 @@ func (c *client) dialUDP() Session { ...@@ -163,7 +164,8 @@ func (c *client) dialUDP() Session {
} }
if err != nil { if err != nil {
log.Warn("net.DialTimeout(addr:%s, timeout:%v) = error{%s}", c.addr, err) log.Warn("net.DialTimeout(addr:%s, timeout:%v) = error{%s}", c.addr, err)
time.Sleep(connInterval) // time.Sleep(connInterval)
<-wheel.After(connInterval)
continue continue
} }
...@@ -173,7 +175,8 @@ func (c *client) dialUDP() Session { ...@@ -173,7 +175,8 @@ func (c *client) dialUDP() Session {
if length, err = conn.Write(buf[:len(pingPacket)]); err != nil { if length, err = conn.Write(buf[:len(pingPacket)]); err != nil {
conn.Close() conn.Close()
log.Warn("conn.Write(%s) = {length:%d, err:%s}", pingPacket, length, err) log.Warn("conn.Write(%s) = {length:%d, err:%s}", pingPacket, length, err)
time.Sleep(connInterval) // time.Sleep(connInterval)
<-wheel.After(connInterval)
continue continue
} }
conn.SetReadDeadline(wheel.Now().Add(1e9)) conn.SetReadDeadline(wheel.Now().Add(1e9))
...@@ -184,7 +187,8 @@ func (c *client) dialUDP() Session { ...@@ -184,7 +187,8 @@ func (c *client) dialUDP() Session {
if err != nil { if err != nil {
log.Info("conn{%#v}.Read() = {length:%d, err:%s}", conn, length, err) log.Info("conn{%#v}.Read() = {length:%d, err:%s}", conn, length, err)
conn.Close() conn.Close()
time.Sleep(connInterval) // time.Sleep(connInterval)
<-wheel.After(connInterval)
continue continue
} }
//if err == nil { //if err == nil {
...@@ -222,7 +226,8 @@ func (c *client) dialWS() Session { ...@@ -222,7 +226,8 @@ func (c *client) dialWS() Session {
} }
log.Info("websocket.dialer.Dial(addr:%s) = error:%s", c.addr, err) log.Info("websocket.dialer.Dial(addr:%s) = error:%s", c.addr, err)
time.Sleep(connInterval) // time.Sleep(connInterval)
<-wheel.After(connInterval)
} }
} }
...@@ -300,7 +305,8 @@ func (c *client) dialWSS() Session { ...@@ -300,7 +305,8 @@ func (c *client) dialWSS() Session {
} }
log.Info("websocket.dialer.Dial(addr:%s) = error{%s}", c.addr, err) log.Info("websocket.dialer.Dial(addr:%s) = error{%s}", c.addr, err)
time.Sleep(connInterval) // time.Sleep(connInterval)
<-wheel.After(connInterval)
} }
} }
...@@ -389,7 +395,8 @@ func (c *client) RunEventLoop(newSession NewSessionCallback) { ...@@ -389,7 +395,8 @@ func (c *client) RunEventLoop(newSession NewSessionCallback) {
if maxTimes < times { if maxTimes < times {
times = maxTimes times = maxTimes
} }
time.Sleep(time.Duration(int64(times) * connInterval)) // time.Sleep(time.Duration(int64(times) * connInterval))
<-wheel.After(time.Duration(int64(times) * connInterval))
continue continue
} }
times = 0 times = 0
......
...@@ -89,7 +89,7 @@ func NewWSServer(opts ...ServerOption) Server { ...@@ -89,7 +89,7 @@ func NewWSServer(opts ...ServerOption) Server {
func NewWSSServer(opts ...ServerOption) Server { func NewWSSServer(opts ...ServerOption) Server {
s := newServer(WSS_SERVER, opts...) s := newServer(WSS_SERVER, opts...)
if s.addr == "" || s.cert == "" || s.privateKey == "" || s.caCert == "" { if s.addr == "" || s.cert == "" || s.privateKey == "" {
panic(fmt.Sprintf("@addr:%s, @cert:%s, @privateKey:%s, @caCert:%s", panic(fmt.Sprintf("@addr:%s, @cert:%s, @privateKey:%s, @caCert:%s",
s.addr, s.cert, s.privateKey, s.caCert)) s.addr, s.cert, s.privateKey, s.caCert))
} }
...@@ -237,7 +237,8 @@ func (s *server) runTcpEventLoop(newSession NewSessionCallback) { ...@@ -237,7 +237,8 @@ func (s *server) runTcpEventLoop(newSession NewSessionCallback) {
return return
} }
if delay != 0 { if delay != 0 {
time.Sleep(delay) // time.Sleep(delay)
<-wheel.After(delay)
} }
client, err = s.accept(newSession) client, err = s.accept(newSession)
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment