Commit ef9876b2 authored by alexstocks's avatar alexstocks

add conn.go:(gettyWSConn)writePing

parent ee832003
......@@ -183,6 +183,10 @@ func (this *gettyWSConn) write(p []byte) error {
return this.conn.WriteMessage(websocket.BinaryMessage, p)
}
func (this *gettyWSConn) writePing() error {
return this.conn.WriteMessage(websocket.PingMessage, []byte{})
}
// close websocket connection
func (this *gettyWSConn) close(waitSec int) {
this.conn.UnderlyingConn().(*net.TCPConn).SetLinger(waitSec)
......
......@@ -11,10 +11,17 @@
## develop history ##
---
- 2016/10/13
> 1 add conn.go:(gettyWSConn)writePing
>
> 2 modify session.go:(Session)handleLoop:Websocket session will send ping frame automatically every peroid.
>
> 3 version: 0.4.03
- 2016/10/11
> 1 fix bug: use websocket.BinaryMessage in conn.go:(gettyWSConn)write
>
> 2 version: 0.4.02
> 2 version: 0.4.02
- 2016/10/10
> 1 delete session.go:Session{errFlag} to invoke codec.go:EventListener{OnClose&OnError} both when got a error
......@@ -25,7 +32,7 @@
>
> 4 add modify session.go:(Session)maxMsgLen for websocket session
>
> 5 version: 0.4.01
> 5 version: 0.4.01
- 2016/10/09
> 1 add client.go:NewWSSClient
......
......@@ -141,7 +141,7 @@ func newWSHandler(server *Server, newSession NewSessionCallback) *wsHandler {
upgrader: websocket.Upgrader{
// in default, ReadBufferSize & WriteBufferSize is 4k
// HandshakeTimeout: server.HTTPTimeout,
CheckOrigin: func(_ *http.Request) bool { return true },
CheckOrigin: func(_ *http.Request) bool { return true }, // allow connections from any origin
},
}
}
......
......@@ -204,7 +204,7 @@ func (this *Session) SetWriter(writer Writer) {
this.writer = writer
}
// period is in millisecond
// period is in millisecond. Websocket session will send ping frame automatically every peroid.
func (this *Session) SetCronPeriod(period int) {
if period < 1 {
panic("@period < 1")
......@@ -400,8 +400,10 @@ func (this *Session) RunEventLoop() {
func (this *Session) handleLoop() {
var (
err error
flag bool
err error
flag bool
wsFlag bool
wsConn *gettyWSConn
// start time.Time
counter gxtime.CountWatch
// ticker *time.Ticker // use wheel instead, 2016/09/26
......@@ -428,6 +430,7 @@ func (this *Session) handleLoop() {
this.gc()
}()
wsConn, wsFlag = this.iConn.(*gettyWSConn)
flag = true // do not do any read/write/cron operation while got write error
// ticker = time.NewTicker(this.period) // use wheel instead, 2016/09/26
LOOP:
......@@ -474,6 +477,12 @@ LOOP:
// case <-ticker.C: // use wheel instead, 2016/09/26
case <-wheel.After(this.period):
if flag {
if wsFlag {
err = wsConn.writePing()
if err != nil {
log.Warn("wsConn.writePing() = error{%#v}", err)
}
}
this.listener.OnCron(this)
}
}
......
......@@ -10,9 +10,9 @@
package getty
const (
Version = "0.4.02"
DATE = "2016/10/12"
Version = "0.4.03"
DATE = "2016/10/13"
GETTY_MAJOR = 0
GETTY_MINOR = 4
GETTY_BUILD = 2
GETTY_BUILD = 3
)
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