Skip to content

Commit 9715df5

Browse files
authored
Merge pull request #399 from cloudwego/develop
chore: release v0.7.1
2 parents 4b375b6 + 3f9d740 commit 9715df5

18 files changed

+64
-115
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Before you submit your Pull Request (PR) consider the following guidelines:
3131
3. [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) the cloudwego/netpoll repo.
3232
4. In your forked repository, make your changes in a new git branch:
3333
```
34-
git checkout -b my-fix-branch develop
34+
git checkout -b my-fix-branch main
3535
```
3636
5. Create your patch, including appropriate test cases.
3737
6. Follow our [Style Guides](#code-style-guides).
@@ -41,7 +41,7 @@ Before you submit your Pull Request (PR) consider the following guidelines:
4141
```
4242
git push origin my-fix-branch
4343
```
44-
9. In GitHub, send a pull request to `netpoll:develop`
44+
9. In GitHub, send a pull request to `netpoll:main`
4545
4646
## Contribution Prerequisites
4747
- Our development environment keeps up with [Go Official](https://golang.org/project/).
@@ -50,9 +50,5 @@ Before you submit your Pull Request (PR) consider the following guidelines:
5050
- Maybe you need familiar with [Actions](https://github.com/features/actions)(our default workflow tool).
5151
5252
## Code Style Guides
53-
Also see [Pingcap General advice](https://pingcap.github.io/style-guide/general.html).
54-
55-
Good resources:
5653
- [Effective Go](https://golang.org/doc/effective_go)
5754
- [Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments)
58-
- [Uber Go Style Guide](https://github.com/uber-go/guide/blob/master/style.md)

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)

nocopy_linkbuffer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func (b *UnsafeLinkBuffer) MallocAck(n int) (err error) {
403403
}
404404
// discard the rest
405405
for node := b.write.next; node != nil; node = node.next {
406-
node.off, node.malloc, node.refer, node.buf = 0, 0, 1, node.buf[:0]
406+
node.malloc, node.refer, node.buf = node.off, 1, node.buf[:node.off]
407407
}
408408
return nil
409409
}

nocopy_linkbuffer_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"bytes"
2222
"encoding/binary"
2323
"fmt"
24+
"reflect"
2425
"runtime"
2526
"sync/atomic"
2627
"testing"
@@ -778,6 +779,34 @@ func TestLinkBufferPeekOutOfMemory(t *testing.T) {
778779
}
779780
}
780781

782+
func TestMallocAck(t *testing.T) {
783+
sLen := 1024 * 7
784+
buf1 := []byte{1, 2, 3, 4}
785+
buf2 := []byte{5, 6, 7, 8}
786+
lb := NewLinkBuffer(0)
787+
788+
buf, err := lb.Malloc(4 + sLen)
789+
MustNil(t, err)
790+
copy(buf[:4], buf1)
791+
s := make([]byte, sLen)
792+
err = lb.WriteDirect(s, sLen)
793+
MustNil(t, err)
794+
795+
err = lb.MallocAck(4 + sLen)
796+
MustNil(t, err)
797+
lb.Flush()
798+
799+
buf, err = lb.Malloc(4)
800+
MustNil(t, err)
801+
copy(buf[:4], buf2)
802+
lb.Flush()
803+
804+
buf, err = lb.Next(8 + sLen)
805+
MustNil(t, err)
806+
807+
MustTrue(t, reflect.DeepEqual(buf, append(append(buf1, s...), buf2...)))
808+
}
809+
781810
func BenchmarkStringToSliceByte(b *testing.B) {
782811
b.StopTimer()
783812
s := "hello world"

0 commit comments

Comments
 (0)