From 3b17bb5b470df604098c0b1a2411668af5db5d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=97=AD?= <120582243@qq.com> Date: Thu, 11 Mar 2021 00:57:33 +0800 Subject: [PATCH] fix write return error EAGAIN (#61) * fix unix.Write return EAGAIN --- connection/connection.go | 11 ++++------- go.mod | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/connection/connection.go b/connection/connection.go index 70969dc..1d5faa3 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -7,10 +7,9 @@ import ( "strconv" "time" - "github.com/Allenxuxu/gev/metrics" - "github.com/Allenxuxu/gev/eventloop" "github.com/Allenxuxu/gev/log" + "github.com/Allenxuxu/gev/metrics" "github.com/Allenxuxu/gev/poller" "github.com/Allenxuxu/ringbuffer" "github.com/Allenxuxu/ringbuffer/pool" @@ -286,14 +285,12 @@ func (c *Connection) sendInLoop(data []byte) { _, _ = c.outBuffer.Write(data) } else { n, err := unix.Write(c.fd, data) - if err != nil { - if err == unix.EAGAIN { - return - } + if err != nil && err != unix.EAGAIN { c.handleClose(c.fd) return } - if n == 0 { + + if n <= 0 { _, _ = c.outBuffer.Write(data) } else if n < len(data) { _, _ = c.outBuffer.Write(data[n:]) diff --git a/go.mod b/go.mod index 11e744b..57fbfa3 100644 --- a/go.mod +++ b/go.mod @@ -16,4 +16,5 @@ require ( github.com/tidwall/evio v1.0.2 golang.org/x/net v0.0.0-20200625001655-4c5254603344 golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e + google.golang.org/protobuf v1.23.0 )