From b1ce4d421519e431fc8519d3017000e5a7233d9b Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Mon, 23 Sep 2019 11:02:57 +0800 Subject: [PATCH] Optimize eventloop read/write and deprecate eviop --- README.md | 1 - README_ZH.md | 3 +-- eventloop.go | 16 +++------------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e4a02a7f8..863025bca 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,6 @@ Source code in `gnet` is available under the MIT [License](/LICENSE). - [evio](https://github.com/tidwall/evio) - [go-disruptor](https://github.com/smartystreets-prototypes/go-disruptor) - [ants](https://github.com/panjf2000/ants) -- [eviop](https://github.com/Allenxuxu/eviop) # Relevant Articles diff --git a/README_ZH.md b/README_ZH.md index 79ecbdac9..ff2558a09 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -264,12 +264,11 @@ Go Version : go version go1.12.9 darwin/amd64 `gnet` 的源码允许用户在遵循 MIT [开源证书](/LICENSE) 规则的前提下使用。 -# 鸣谢 +# 致谢 - [evio](https://github.com/tidwall/evio) - [go-disruptor](https://github.com/smartystreets-prototypes/go-disruptor) - [ants](https://github.com/panjf2000/ants) -- [eviop](https://github.com/Allenxuxu/eviop) # 相关文章 diff --git a/eventloop.go b/eventloop.go index a745fb1d4..1de751c31 100644 --- a/eventloop.go +++ b/eventloop.go @@ -207,8 +207,8 @@ func (l *loop) loopWrite(svr *server, conn *conn) error { svr.events.PreWrite() } - top, tail := conn.outBuf.PreReadAll() - n, err := unix.Write(conn.fd, top) + out := conn.outBuf.Bytes() + n, err := unix.Write(conn.fd, out) if err != nil { if err == unix.EAGAIN { return nil @@ -216,17 +216,7 @@ func (l *loop) loopWrite(svr *server, conn *conn) error { return l.loopCloseConn(svr, conn, err) } conn.outBuf.Advance(n) - - if len(top) == n && len(tail) > 0 { - n, err := unix.Write(conn.fd, tail) - if err != nil { - if err == unix.EAGAIN { - return nil - } - return l.loopCloseConn(svr, conn, err) - } - conn.outBuf.Advance(n) - } + ringbuffer.Recycle(out) if conn.outBuf.Length() == 0 { l.poller.ModRead(conn.fd)