Commit effbd7e4 authored by AlexStocks's avatar AlexStocks

disable tcp readdeadline/writedeadline when using compression

parent 370af48b
......@@ -4,13 +4,22 @@
## introdction ##
---
> DESC : a asynchronous network I/O library in golang. In getty there are two goroutines in one connection(session), one handle network read buffer tcp stream, the other handle logic process and write response into network write buffer. If your logic process may take a long time, you should start a new logic process goroutine by yourself in (Codec):OnMessage. Getty is based on "ngo" whose author is sanbit(https://github.com/sanbit).
> DESC : a asynchronous network I/O library in golang. In getty there are two goroutines in one connection(session),
one handle network read buffer tcp stream, the other handle logic process and write response into network
write buffer. If your logic process may take a long time, you should start a new logic process goroutine
by yourself in (Codec):OnMessage. Getty is based on "ngo" whose author is sanbit(https://github.com/sanbit).
>
> LICENCE : Apache License 2.0
## develop history ##
---
- 2018/03/14
> bug fix
* disable SetReadDeadline when enable compression.
Refers to the NextReader/NextWriter of gorilla/websocket, you should make a new compression reader/writer when
read/write a package again.
- 2018/03/10
> improvement
* 1 rDeadline -> rTimeout
......
......@@ -231,18 +231,21 @@ func (t *writeFlusher) Write(p []byte) (int, error) {
func (t *gettyTCPConn) SetCompressType(c CompressType) {
switch c {
case CompressNone, CompressZip, CompressBestSpeed, CompressBestCompression, CompressHuffman:
t.reader = flate.NewReader(t.conn)
ioReader := io.Reader(t.conn)
t.reader = flate.NewReader(ioReader)
w, err := flate.NewWriter(t.conn, int(c))
ioWriter := io.Writer(t.conn)
w, err := flate.NewWriter(ioWriter, int(c))
if err != nil {
panic(fmt.Sprintf("flate.NewReader(flate.DefaultCompress) = err(%s)", err))
}
t.writer = &writeFlusher{flusher: w}
case CompressSnappy:
t.reader = snappy.NewReader(t.conn)
// t.writer = snappy.NewWriter(t.conn)
t.writer = snappy.NewBufferedWriter(t.conn)
ioReader := io.Reader(t.conn)
t.reader = snappy.NewReader(ioReader)
ioWriter := io.Writer(t.conn)
t.writer = snappy.NewBufferedWriter(ioWriter)
default:
panic(fmt.Sprintf("illegal comparess type %d", c))
......@@ -272,6 +275,7 @@ func (t *gettyTCPConn) read(p []byte) (int, error) {
}
length, err = t.reader.Read(p)
fmt.Printf("compress connection now:%s, length:%d, err:%s\n", currentTime, length, err)
atomic.AddUint32(&t.readCount, uint32(length))
return length, err
}
......@@ -288,7 +292,7 @@ func (t *gettyTCPConn) Write(pkg interface{}) (int, error) {
if p, ok = pkg.([]byte); !ok {
return 0, fmt.Errorf("illegal @pkg{%#v} type", pkg)
}
if t.wTimeout > 0 {
if t.compress == CompressNone && t.wTimeout > 0 {
// Optimization: update write deadline only if more than 25%
// of the last write deadline exceeded.
// See https://github.com/golang/go/issues/15133 for details.
......
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