Commit f7505d10 authored by AlexStocks's avatar AlexStocks

add ws comperss feature

parent b3e7c618
......@@ -11,11 +11,16 @@
## develop history ##
---
- 2016/11/19
> 1 add conn.go:(*gettyWSConn) setCompressType to add zip compress feature for ws connection
>
> 2 version: 0.6.2
- 2016/11/16
> 1 add zip/snappy compress for tcp/ws connection
> 1 add zip/snappy compress for tcp connection
>
> 2 version: 0.6.01
> 2 version: 0.6.1
- 2016/11/02
> 1 add session.go:Session{ID(), LocalAddr(), RemoteAddr()}
>
......
......@@ -128,6 +128,7 @@ func (this *Client) dialWS() *Session {
session *Session
)
dialer.EnableCompression = true
for {
if this.IsClosed() {
return nil
......@@ -161,6 +162,7 @@ func (this *Client) dialWSS() *Session {
session *Session
)
dialer.EnableCompression = true
certPem, err = ioutil.ReadFile(this.certFile)
if err != nil {
panic(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err{%#v}", this.certFile, err))
......@@ -170,6 +172,7 @@ func (this *Client) dialWSS() *Session {
panic("failed to parse root certificate")
}
// dialer.EnableCompression = true
dialer.TLSClientConfig = &tls.Config{RootCAs: certPool}
for {
if this.IsClosed() {
......@@ -273,7 +276,7 @@ func (this *Client) RunEventLoop(newSession NewSessionCallback) {
if maxTimes < times {
times = maxTimes
}
time.Sleep(time.Duration(times * defaultInterval))
time.Sleep(time.Duration(int64(times) * defaultInterval))
continue
}
times = 0
......
......@@ -301,6 +301,7 @@ func newGettyWSConn(conn *websocket.Conn) *gettyWSConn {
peer: peerAddr,
},
}
conn.EnableWriteCompression(false)
conn.SetPingHandler(gettyWSConn.handlePing)
conn.SetPongHandler(gettyWSConn.handlePong)
......@@ -314,6 +315,8 @@ func (this *gettyWSConn) setCompressType(t CompressType) {
this.conn.EnableWriteCompression(true)
case t == CompressSnappy:
this.conn.EnableWriteCompression(true)
default:
this.conn.EnableWriteCompression(false)
}
}
......
......@@ -142,7 +142,8 @@ 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 }, // allow connections from any origin
CheckOrigin: func(_ *http.Request) bool { return true }, // allow connections from any origin
EnableCompression: true,
},
}
}
......
......@@ -10,9 +10,9 @@
package getty
const (
Version = "0.6.01"
DATE = "2016/11/16"
Version = "0.6.2"
DATE = "2016/11/19"
GETTY_MAJOR = 0
GETTY_MINOR = 6
GETTY_BUILD = 1
GETTY_BUILD = 2
)
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