Skip to content

Commit 590bf8e

Browse files
authored
chore: fix lint & rm unused zero copy code (#395)
1 parent 5babe71 commit 590bf8e

15 files changed

+32
-108
lines changed

connection_impl.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import (
2727
type connState = int32
2828

2929
const (
30-
defaultZeroCopyTimeoutSec = 60
31-
3230
connStateNone = 0
3331
connStateConnected = 1
3432
connStateDisconnected = 2
@@ -39,21 +37,20 @@ type connection struct {
3937
netFD
4038
onEvent
4139
locker
42-
operator *FDOperator
43-
readTimeout time.Duration
44-
readTimer *time.Timer
45-
readTrigger chan error
46-
waitReadSize int64
47-
writeTimeout time.Duration
48-
writeTimer *time.Timer
49-
writeTrigger chan error
50-
inputBuffer *LinkBuffer
51-
outputBuffer *LinkBuffer
52-
outputBarrier *barrier
53-
supportZeroCopy bool
54-
maxSize int // The maximum size of data between two Release().
55-
bookSize int // The size of data that can be read at once.
56-
state connState // Connection state should be changed sequentially.
40+
operator *FDOperator
41+
readTimeout time.Duration
42+
readTimer *time.Timer
43+
readTrigger chan error
44+
waitReadSize int64
45+
writeTimeout time.Duration
46+
writeTimer *time.Timer
47+
writeTrigger chan error
48+
inputBuffer *LinkBuffer
49+
outputBuffer *LinkBuffer
50+
outputBarrier *barrier
51+
maxSize int // The maximum size of data between two Release().
52+
bookSize int // The size of data that can be read at once.
53+
state connState // Connection state should be changed sequentially.
5754
}
5855

5956
var (
@@ -351,10 +348,6 @@ func (c *connection) init(conn Conn, opts *options) (err error) {
351348
case "tcp", "tcp4", "tcp6":
352349
setTCPNoDelay(c.fd, true)
353350
}
354-
// check zero-copy
355-
if setZeroCopy(c.fd) == nil && setBlockZeroCopySend(c.fd, defaultZeroCopyTimeoutSec, 0) == nil {
356-
c.supportZeroCopy = true
357-
}
358351

359352
// connection initialized and prepare options
360353
return c.onPrepare(opts)
@@ -483,9 +476,8 @@ func (c *connection) flush() error {
483476
if c.outputBuffer.IsEmpty() {
484477
return nil
485478
}
486-
// TODO: Let the upper layer pass in whether to use ZeroCopy.
487479
bs := c.outputBuffer.GetBytes(c.outputBarrier.bs)
488-
n, err := sendmsg(c.fd, bs, c.outputBarrier.ivs, false && c.supportZeroCopy)
480+
n, err := sendmsg(c.fd, bs, c.outputBarrier.ivs, false)
489481
if err != nil && err != syscall.EAGAIN {
490482
return Exception(err, "when flush")
491483
}

connection_lock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ type locker struct {
5959
}
6060

6161
func (l *locker) closeBy(w who) (success bool) {
62-
return atomic.CompareAndSwapInt32(&l.keychain[closing], 0, int32(w))
62+
return atomic.CompareAndSwapInt32(&l.keychain[closing], 0, w)
6363
}
6464

6565
func (l *locker) isCloseBy(w who) (yes bool) {
66-
return atomic.LoadInt32(&l.keychain[closing]) == int32(w)
66+
return atomic.LoadInt32(&l.keychain[closing]) == w
6767
}
6868

6969
func (l *locker) status(k key) int32 {

connection_reactor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ func (c *connection) inputAck(n int) (err error) {
119119
}
120120

121121
// outputs implements FDOperator.
122-
func (c *connection) outputs(vs [][]byte) (rs [][]byte, supportZeroCopy bool) {
122+
func (c *connection) outputs(vs [][]byte) (rs [][]byte, _ bool) {
123123
if c.outputBuffer.IsEmpty() {
124124
c.rw2r()
125-
return rs, c.supportZeroCopy
125+
return rs, false
126126
}
127127
rs = c.outputBuffer.GetBytes(vs)
128-
return rs, c.supportZeroCopy
128+
return rs, false
129129
}
130130

131131
// outputAck implements FDOperator.

connection_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ func TestConnectionServerClose(t *testing.T) {
688688
WithOnPrepare(func(connection Connection) context.Context {
689689
// t.Logf("server.OnPrepare: addr=%s", connection.RemoteAddr())
690690
defer wg.Done()
691+
//nolint:staticcheck // SA1029 no built-in type string as key
691692
return context.WithValue(context.Background(), "prepare", "true")
692693
}),
693694
)

fd_operator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type FDOperator struct {
3636
InputAck func(n int) (err error)
3737

3838
// Outputs will locked if len(rs) > 0, which need unlocked by OutputAck.
39+
// supportZeroCopy is not implemented, and it will be ignored
3940
Outputs func(vs [][]byte) (rs [][]byte, supportZeroCopy bool)
4041
OutputAck func(n int) (err error)
4142

net_listener_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestListenerDialer(t *testing.T) {
8080
conn.SetOnRequest(onRequest)
8181

8282
MustNil(t, err)
83-
n, err := conn.Write([]byte(msg))
83+
n, err := conn.Write(msg)
8484
MustNil(t, err)
8585
Equal(t, n, len(msg))
8686
time.Sleep(10 * time.Millisecond)

net_sock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type sockaddr interface {
4040
}
4141

4242
func internetSocket(ctx context.Context, net string, laddr, raddr sockaddr, sotype, proto int, mode string) (conn *netFD, err error) {
43-
if (runtime.GOOS == "aix" || runtime.GOOS == "windows" || runtime.GOOS == "openbsd" || runtime.GOOS == "nacl") && raddr.isWildcard() {
43+
if (runtime.GOOS == "aix" || runtime.GOOS == "openbsd" || runtime.GOOS == "nacl") && raddr.isWildcard() {
4444
raddr = raddr.toLocal(net)
4545
}
4646
family, ipv6only := favoriteAddrFamily(net, laddr, raddr)

poll_default_bsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func openDefaultPoll() (*defaultPoll, error) {
5252
type defaultPoll struct {
5353
fd int
5454
trigger uint32
55-
m sync.Map // only used in go:race
55+
m sync.Map //nolint:unused // only used in go:race
5656
opcache *operatorCache // operator cache
5757
hups []func(p Poll) error
5858
}

poll_default_linux.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,9 @@ func (p *defaultPoll) handler(events []epollevent) (closed bool) {
199199
operator.OnWrite(p)
200200
} else if operator.Outputs != nil {
201201
// for connection
202-
bs, supportZeroCopy := operator.Outputs(p.barriers[i].bs)
202+
bs, _ := operator.Outputs(p.barriers[i].bs)
203203
if len(bs) > 0 {
204-
// TODO: Let the upper layer pass in whether to use ZeroCopy.
205-
n, err := iosend(operator.FD, bs, p.barriers[i].ivs, false && supportZeroCopy)
204+
n, err := iosend(operator.FD, bs, p.barriers[i].ivs, false)
206205
operator.OutputAck(n)
207206
if err != nil {
208207
p.appendHup(operator)

poll_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ START:
144144
// m.Run() will finish very quickly, so will not many goroutines block on Pick.
145145
_ = m.Run()
146146

147+
//nolint:staticcheck // SA9003: empty branch
147148
if !atomic.CompareAndSwapInt32(&m.status, managerInitializing, managerInitialized) {
148149
// SetNumLoops called during m.Run() which cause CAS failed
149150
// The polls will be adjusted next Pick

0 commit comments

Comments
 (0)