Commit f7505d10 authored by AlexStocks's avatar AlexStocks

add ws comperss feature

parent b3e7c618
...@@ -11,11 +11,16 @@ ...@@ -11,11 +11,16 @@
## develop history ## ## 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 - 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 - 2016/11/02
> 1 add session.go:Session{ID(), LocalAddr(), RemoteAddr()} > 1 add session.go:Session{ID(), LocalAddr(), RemoteAddr()}
> >
......
...@@ -128,6 +128,7 @@ func (this *Client) dialWS() *Session { ...@@ -128,6 +128,7 @@ func (this *Client) dialWS() *Session {
session *Session session *Session
) )
dialer.EnableCompression = true
for { for {
if this.IsClosed() { if this.IsClosed() {
return nil return nil
...@@ -161,6 +162,7 @@ func (this *Client) dialWSS() *Session { ...@@ -161,6 +162,7 @@ func (this *Client) dialWSS() *Session {
session *Session session *Session
) )
dialer.EnableCompression = true
certPem, err = ioutil.ReadFile(this.certFile) certPem, err = ioutil.ReadFile(this.certFile)
if err != nil { if err != nil {
panic(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err{%#v}", this.certFile, err)) panic(fmt.Errorf("ioutil.ReadFile(certFile{%s}) = err{%#v}", this.certFile, err))
...@@ -170,6 +172,7 @@ func (this *Client) dialWSS() *Session { ...@@ -170,6 +172,7 @@ func (this *Client) dialWSS() *Session {
panic("failed to parse root certificate") panic("failed to parse root certificate")
} }
// dialer.EnableCompression = true
dialer.TLSClientConfig = &tls.Config{RootCAs: certPool} dialer.TLSClientConfig = &tls.Config{RootCAs: certPool}
for { for {
if this.IsClosed() { if this.IsClosed() {
...@@ -273,7 +276,7 @@ func (this *Client) RunEventLoop(newSession NewSessionCallback) { ...@@ -273,7 +276,7 @@ func (this *Client) RunEventLoop(newSession NewSessionCallback) {
if maxTimes < times { if maxTimes < times {
times = maxTimes times = maxTimes
} }
time.Sleep(time.Duration(times * defaultInterval)) time.Sleep(time.Duration(int64(times) * defaultInterval))
continue continue
} }
times = 0 times = 0
......
...@@ -301,6 +301,7 @@ func newGettyWSConn(conn *websocket.Conn) *gettyWSConn { ...@@ -301,6 +301,7 @@ func newGettyWSConn(conn *websocket.Conn) *gettyWSConn {
peer: peerAddr, peer: peerAddr,
}, },
} }
conn.EnableWriteCompression(false)
conn.SetPingHandler(gettyWSConn.handlePing) conn.SetPingHandler(gettyWSConn.handlePing)
conn.SetPongHandler(gettyWSConn.handlePong) conn.SetPongHandler(gettyWSConn.handlePong)
...@@ -314,6 +315,8 @@ func (this *gettyWSConn) setCompressType(t CompressType) { ...@@ -314,6 +315,8 @@ func (this *gettyWSConn) setCompressType(t CompressType) {
this.conn.EnableWriteCompression(true) this.conn.EnableWriteCompression(true)
case t == CompressSnappy: case t == CompressSnappy:
this.conn.EnableWriteCompression(true) this.conn.EnableWriteCompression(true)
default:
this.conn.EnableWriteCompression(false)
} }
} }
......
...@@ -142,7 +142,8 @@ func newWSHandler(server *Server, newSession NewSessionCallback) *wsHandler { ...@@ -142,7 +142,8 @@ func newWSHandler(server *Server, newSession NewSessionCallback) *wsHandler {
upgrader: websocket.Upgrader{ upgrader: websocket.Upgrader{
// in default, ReadBufferSize & WriteBufferSize is 4k // in default, ReadBufferSize & WriteBufferSize is 4k
// HandshakeTimeout: server.HTTPTimeout, // 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 @@ ...@@ -10,9 +10,9 @@
package getty package getty
const ( const (
Version = "0.6.01" Version = "0.6.2"
DATE = "2016/11/16" DATE = "2016/11/19"
GETTY_MAJOR = 0 GETTY_MAJOR = 0
GETTY_MINOR = 6 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