Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Jan 18, 2024
1 parent 9725a36 commit d4d83eb
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
4 changes: 3 additions & 1 deletion conn_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func (c *Conn) flush() error {
continue
}
if errors.Is(err, syscall.EAGAIN) {
c.modWrite()
// c.modWrite()
return nil
}
if err != nil {
Expand All @@ -616,6 +616,8 @@ func (c *Conn) flush() error {
}
}

c.resetRead()

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions lmux/lmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (lm *ListenerMux) Start() {
c, err := l.Accept()
if err != nil {
var ne net.Error
if ok := errors.As(err, &ne); ok && ne.Temporary() {
logging.Error("Accept failed: temporary error, retrying...")
if ok := errors.As(err, &ne); ok && ne.Timeout() {
logging.Error("Accept failed: timeout error, retrying...")
time.Sleep(time.Second / 20)
continue
} else {
Expand Down
4 changes: 2 additions & 2 deletions nbhttp/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ func (e *Engine) listen(ln net.Listener, tlsConfig *tls.Config, addConn func(*Co
addConn(&Conn{Conn: conn}, tlsConfig, decrease)
} else {
var ne net.Error
if ok := errors.As(err, &ne); ok && ne.Temporary() {
logging.Error("Accept failed: temporary error, retrying...")
if ok := errors.As(err, &ne); ok && ne.Timeout() {
logging.Error("Accept failed: timeout error, retrying...")
time.Sleep(time.Second / 20)
} else {
if !e.shutdown {
Expand Down
4 changes: 2 additions & 2 deletions poller_epoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func (p *poller) acceptorLoop() {
p.g.pollers[c.Hash()%len(p.g.pollers)].addConn(c)
} else {
var ne net.Error
if ok := errors.As(err, &ne); ok && ne.Temporary() {
logging.Error("NBIO[%v][%v_%v] Accept failed: temporary error, retrying...", p.g.Name, p.pollType, p.index)
if ok := errors.As(err, &ne); ok && ne.Timeout() {
logging.Error("NBIO[%v][%v_%v] Accept failed: timeout error, retrying...", p.g.Name, p.pollType, p.index)
time.Sleep(time.Second / 20)
} else {
if !p.shutdown {
Expand Down
16 changes: 9 additions & 7 deletions poller_kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package nbio

import (
"errors"
"fmt"
"io"
"net"
Expand All @@ -32,7 +33,6 @@ const (
)

const (
// for build
IPPROTO_TCP = 0
TCP_KEEPINTVL = 0
TCP_KEEPIDLE = 0
Expand Down Expand Up @@ -147,10 +147,10 @@ func (p *poller) readWrite(ev *syscall.Kevent_t) {
p.g.onData(rc, buffer[:n])
}
p.g.payback(c, buffer)
if err == syscall.EINTR {
if errors.Is(err, syscall.EINTR) {
continue
}
if err == syscall.EAGAIN {
if errors.Is(err, syscall.EAGAIN) {
return
}
if (err != nil || n == 0) && ev.Flags&syscall.EV_DELETE == 0 {
Expand Down Expand Up @@ -205,15 +205,17 @@ func (p *poller) acceptorLoop() {
for !p.shutdown {
conn, err := p.listener.Accept()
if err == nil {
c, err := NBConn(conn)
var c *Conn
c, err = NBConn(conn)
if err != nil {
conn.Close()
continue
}
p.g.pollers[c.Hash()%len(p.g.pollers)].addConn(c)
} else {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
logging.Error("NBIO[%v][%v_%v] Accept failed: temporary error, retrying...", p.g.Name, p.pollType, p.index)
var ne net.Error
if ok := errors.As(err, &ne); ok && ne.Timeout() {
logging.Error("NBIO[%v][%v_%v] Accept failed: timeout error, retrying...", p.g.Name, p.pollType, p.index)
time.Sleep(time.Second / 20)
} else {
if !p.shutdown {
Expand Down Expand Up @@ -241,7 +243,7 @@ func (p *poller) readWriteLoop() {
p.eventList = nil
p.mux.Unlock()
n, err := syscall.Kevent(p.kfd, changes, events, nil)
if err != nil && err != syscall.EINTR {
if err != nil && errors.Is(err, syscall.EINTR) {
return
}

Expand Down
6 changes: 4 additions & 2 deletions poller_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package nbio

import (
"errors"
"net"
"runtime"
"time"
Expand Down Expand Up @@ -109,8 +110,9 @@ func (p *poller) start() {
for !p.shutdown {
err = p.accept()
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
logging.Error("NBIO[%v][%v_%v] Accept failed: temporary error, retrying...", p.g.Name, p.pollType, p.index)
var ne net.Error
if ok := errors.As(err, &ne); ok && ne.Timeout() {
logging.Error("NBIO[%v][%v_%v] Accept failed: timeout error, retrying...", p.g.Name, p.pollType, p.index)
time.Sleep(time.Second / 20)
} else {
if !p.shutdown {
Expand Down
4 changes: 2 additions & 2 deletions sendfile_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ func (c *Conn) Sendfile(f *os.File, remain int64) (int64, error) {
remain = size - offset
}

var src int
if len(c.writeList) > 0 {
src, err := syscall.Dup(int(f.Fd()))
src, err = syscall.Dup(int(f.Fd()))
if err != nil {
c.closeWithErrorWithoutLock(err)
return 0, err
Expand All @@ -58,7 +59,6 @@ func (c *Conn) Sendfile(f *os.File, remain int64) (int64, error) {

var (
n int
src = int(f.Fd())
dst = c.fd
total = remain
)
Expand Down

0 comments on commit d4d83eb

Please sign in to comment.