Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: v2.5.4 #617

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# env
# IDEs
.idea/
.vscode/

# dependencies
/node_modules
Expand Down
91 changes: 84 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ English | [中文](README_ZH.md)

`gnet` is available as a Go module and we highly recommend that you use `gnet` via [Go Modules](https://go.dev/blog/using-go-modules), with Go 1.11 Modules enabled (Go 1.11+), you can just simply add `import "github.com/panjf2000/gnet/v2"` to the codebase and run `go mod download/go mod tidy` or `go [build|run|test]` to download the necessary dependencies automatically.

## With v2
## With v2

```bash
go get -u github.com/panjf2000/gnet/v2
Expand All @@ -68,7 +68,44 @@ go get -u github.com/panjf2000/gnet

The following companies/organizations use `gnet` as the underlying network service in production.

<a href="https://www.tencent.com"><img src="https://res.strikefreedom.top/static_res/logos/tencent_logo.png" width="250" align="middle"/></a>&nbsp;&nbsp;<a href="https://www.iqiyi.com" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/iqiyi-logo.png" width="200" align="middle"/></a>&nbsp;&nbsp;<a href="https://www.mi.com" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/mi-logo.png" width="150" align="middle"/></a>&nbsp;&nbsp;<a href="https://www.360.com" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/360-logo.png" width="200" align="middle"/></a>&nbsp;&nbsp;<a href="https://tieba.baidu.com/" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/baidu-tieba-logo.png" width="200" align="middle"/></a>&nbsp;&nbsp;<a href="https://game.qq.com/" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/tencent-games-logo.jpeg" width="200" align="middle"/></a>
<table>
<tbody>
<tr>
<td align="center" valign="middle">
<a href="https://www.tencent.com">
<img src="https://res.strikefreedom.top/static_res/logos/tencent_logo.png" width="250" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.iqiyi.com" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/iqiyi-logo.png" width="200" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.mi.com" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/mi-logo.png" width="150" />
</a>
</td>
</tr>
<tr>
<td align="center" valign="middle">
<a href="https://www.360.com" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/360-logo.png" width="200" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://tieba.baidu.com/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/baidu-tieba-logo.png" width="200" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://game.qq.com/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/tencent-games-logo.jpeg" width="200" />
</a>
</td>
</tr>
</tbody>
</table>

If you have `gnet` integrated into projects, feel free to open a pull request refreshing this list.

Expand Down Expand Up @@ -160,7 +197,7 @@ The source code of `gnet` should be distributed under the Apache-2.0 license.
Please read the [Contributing Guidelines](CONTRIBUTING.md) before opening a PR and thank you to all the developers who already made contributions to `gnet`!

<a href="https://github.com/panjf2000/gnet/graphs/contributors">
<img src="https://contrib.rocks/image?repo=panjf2000/gnet" />
<img src="https://contrib.rocks/image?repo=panjf2000/gnet" />
</a>

# ⚓ Relevant Articles
Expand Down Expand Up @@ -193,7 +230,47 @@ Become a bronze sponsor with a monthly donation of $10 and get your logo on our

# 💴 Patrons

<a target="_blank" href="https://github.com/patrick-othmer"><img src="https://avatars1.githubusercontent.com/u/8964313" width="100" alt="Patrick Othmer" /></a>&nbsp;<a target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://avatars2.githubusercontent.com/u/50285334" width="100" alt="Jimmy" /></a>&nbsp;<a target="_blank" href="https://github.com/cafra"><img src="https://avatars0.githubusercontent.com/u/13758306" width="100" alt="ChenZhen" /></a>&nbsp;<a target="_blank" href="https://github.com/yangwenmai"><img src="https://avatars0.githubusercontent.com/u/1710912" width="100" alt="Mai Yang" /></a>&nbsp;<a target="_blank" href="https://github.com/BeijingWks"><img src="https://avatars3.githubusercontent.com/u/33656339" width="100" alt="王开帅" /></a>&nbsp;<a target="_blank" href="https://github.com/refs"><img src="https://avatars3.githubusercontent.com/u/6905948" width="100" alt="Unger Alejandro" /></a>&nbsp;<a target="_blank" href="https://github.com/Swaggadan"><img src="https://avatars.githubusercontent.com/u/137142" width="100" alt="Swaggadan" /></a>&nbsp;<a target="_blank" href="https://github.com/Wuvist"><img src="https://avatars.githubusercontent.com/u/657796" width="100" alt="Weng Wei" /></a>
<table>
<tbody>
<tr>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/patrick-othmer">
<img src="https://avatars1.githubusercontent.com/u/8964313" width="100" alt="Patrick Othmer" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/panjf2000/ants">
<img src="https://avatars2.githubusercontent.com/u/50285334" width="100" alt="Jimmy" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/cafra">
<img src="https://avatars0.githubusercontent.com/u/13758306" width="100" alt="ChenZhen" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/yangwenmai">
<img src="https://avatars0.githubusercontent.com/u/1710912" width="100" alt="Mai Yang" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/BeijingWks">
<img src="https://avatars3.githubusercontent.com/u/33656339" width="100" alt="王开帅" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/refs">
<img src="https://avatars3.githubusercontent.com/u/6905948" width="100" alt="Unger Alejandro" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/Wuvist">
<img src="https://avatars.githubusercontent.com/u/657796" width="100" alt="Weng Wei" />
</a>
</td>
</tr>
</tbody>
</table>

# 🔑 JetBrains OS licenses

Expand All @@ -204,7 +281,7 @@ Become a bronze sponsor with a monthly donation of $10 and get your logo on our
# 🔋 Sponsorship

<p>
<h3>This project is supported by:</h3>
<a href="https://www.digitalocean.com/"><img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px" />
</a>
<h3>This project is supported by:</h3>
<a href="https://www.digitalocean.com/"><img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px" />
</a>
</p>
91 changes: 84 additions & 7 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

`gnet` 是一个 Go module,而且我们也强烈推荐通过 [Go Modules](https://go.dev/blog/using-go-modules) 来使用 `gnet`,在开启 Go Modules 支持(Go 1.11+)之后可以通过简单地在代码中写 `import "github.com/panjf2000/gnet/v2"` 来引入 `gnet`,然后执行 `go mod download/go mod tidy` 或者 `go [build|run|test]` 这些命令来自动下载所依赖的包。

## 使用 v2
## 使用 v2

```bash
go get -u github.com/panjf2000/gnet/v2
Expand All @@ -68,7 +68,44 @@ go get -u github.com/panjf2000/gnet

以下公司/组织在生产环境上使用了 `gnet` 作为底层网络服务。

<a href="https://www.tencent.com"><img src="https://res.strikefreedom.top/static_res/logos/tencent_logo.png" width="250" align="middle"/></a>&nbsp;&nbsp;<a href="https://www.iqiyi.com" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/iqiyi-logo.png" width="200" align="middle"/></a>&nbsp;&nbsp;<a href="https://www.mi.com" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/mi-logo.png" width="150" align="middle"/></a>&nbsp;&nbsp;<a href="https://www.360.com" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/360-logo.png" width="200" align="middle"/></a>&nbsp;&nbsp;<a href="https://tieba.baidu.com/" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/baidu-tieba-logo.png" width="200" align="middle"/></a>&nbsp;&nbsp;<a href="https://game.qq.com/" target="_blank"><img src="https://res.strikefreedom.top/static_res/logos/tencent-games-logo.jpeg" width="200" align="middle"/></a>
<table>
<tbody>
<tr>
<td align="center" valign="middle">
<a href="https://www.tencent.com">
<img src="https://res.strikefreedom.top/static_res/logos/tencent_logo.png" width="250" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.iqiyi.com" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/iqiyi-logo.png" width="200" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://www.mi.com" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/mi-logo.png" width="150" />
</a>
</td>
</tr>
<tr>
<td align="center" valign="middle">
<a href="https://www.360.com" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/360-logo.png" width="200" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://tieba.baidu.com/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/baidu-tieba-logo.png" width="200" />
</a>
</td>
<td align="center" valign="middle">
<a href="https://game.qq.com/" target="_blank">
<img src="https://res.strikefreedom.top/static_res/logos/tencent-games-logo.jpeg" width="200" />
</a>
</td>
</tr>
</tbody>
</table>

如果你的项目也在使用 `gnet`,欢迎给我提 Pull Request 来更新这份列表。

Expand Down Expand Up @@ -160,7 +197,7 @@ Test duration : 15s
请在提 PR 之前仔细阅读 [Contributing Guidelines](CONTRIBUTING.md),感谢那些为 `gnet` 贡献过代码的开发者!

<a href="https://github.com/panjf2000/gnet/graphs/contributors">
<img src="https://contrib.rocks/image?repo=panjf2000/gnet" />
<img src="https://contrib.rocks/image?repo=panjf2000/gnet" />
</a>

# ⚓ 相关文章
Expand Down Expand Up @@ -193,7 +230,47 @@ Test duration : 15s

# 💴 资助者

<a target="_blank" href="https://github.com/patrick-othmer"><img src="https://avatars1.githubusercontent.com/u/8964313" width="100" alt="Patrick Othmer" /></a>&nbsp;<a target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://avatars2.githubusercontent.com/u/50285334" width="100" alt="Jimmy" /></a>&nbsp;<a target="_blank" href="https://github.com/cafra"><img src="https://avatars0.githubusercontent.com/u/13758306" width="100" alt="ChenZhen" /></a>&nbsp;<a target="_blank" href="https://github.com/yangwenmai"><img src="https://avatars0.githubusercontent.com/u/1710912" width="100" alt="Mai Yang" /></a>&nbsp;<a target="_blank" href="https://github.com/BeijingWks"><img src="https://avatars3.githubusercontent.com/u/33656339" width="100" alt="王开帅" /></a>&nbsp;<a target="_blank" href="https://github.com/refs"><img src="https://avatars3.githubusercontent.com/u/6905948" width="100" alt="Unger Alejandro" /></a>&nbsp;<a target="_blank" href="https://github.com/Swaggadan"><img src="https://avatars.githubusercontent.com/u/137142" width="100" alt="Swaggadan" /></a>&nbsp;<a target="_blank" href="https://github.com/Wuvist"><img src="https://avatars.githubusercontent.com/u/657796" width="100" alt="Weng Wei" /></a>
<table>
<tbody>
<tr>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/patrick-othmer">
<img src="https://avatars1.githubusercontent.com/u/8964313" width="100" alt="Patrick Othmer" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/panjf2000/ants">
<img src="https://avatars2.githubusercontent.com/u/50285334" width="100" alt="Jimmy" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/cafra">
<img src="https://avatars0.githubusercontent.com/u/13758306" width="100" alt="ChenZhen" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/yangwenmai">
<img src="https://avatars0.githubusercontent.com/u/1710912" width="100" alt="Mai Yang" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/BeijingWks">
<img src="https://avatars3.githubusercontent.com/u/33656339" width="100" alt="王开帅" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/refs">
<img src="https://avatars3.githubusercontent.com/u/6905948" width="100" alt="Unger Alejandro" />
</a>
</td>
<td align="center" valign="middle">
<a target="_blank" href="https://github.com/Wuvist">
<img src="https://avatars.githubusercontent.com/u/657796" width="100" alt="Weng Wei" />
</a>
</td>
</tr>
</tbody>
</table>

# 🔑 JetBrains 开源证书支持

Expand All @@ -204,7 +281,7 @@ Test duration : 15s
# 🔋 赞助商

<p>
<h3>本项目由以下机构赞助:</h3>
<a href="https://www.digitalocean.com/"><img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px" />
</a>
<h3>本项目由以下机构赞助:</h3>
<a href="https://www.digitalocean.com/"><img src="https://opensource.nyc3.cdn.digitaloceanspaces.com/attribution/assets/SVG/DO_Logo_horizontal_blue.svg" width="201px" />
</a>
</p>
8 changes: 4 additions & 4 deletions connection_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ func (c *conn) Next(n int) (buf []byte, err error) {
}
head, tail := c.inboundBuffer.Peek(n)
defer c.inboundBuffer.Discard(n) //nolint:errcheck
if len(head) == n {
if len(head) >= n {
return head[:n], err
}
c.loop.cache.Reset()
c.loop.cache.Write(head)
c.loop.cache.Write(tail)
if inBufferLen == n {
if inBufferLen >= n {
return c.loop.cache.Bytes(), err
}

Expand All @@ -352,13 +352,13 @@ func (c *conn) Peek(n int) (buf []byte, err error) {
return c.buffer[:n], err
}
head, tail := c.inboundBuffer.Peek(n)
if len(head) == n {
if len(head) >= n {
return head[:n], err
}
c.loop.cache.Reset()
c.loop.cache.Write(head)
c.loop.cache.Write(tail)
if inBufferLen == n {
if inBufferLen >= n {
return c.loop.cache.Bytes(), err
}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module github.com/panjf2000/gnet/v2

require (
github.com/panjf2000/ants/v2 v2.9.0
github.com/stretchr/testify v1.8.4
github.com/panjf2000/ants/v2 v2.10.0
github.com/stretchr/testify v1.9.0
github.com/valyala/bytebufferpool v1.0.0
go.uber.org/zap v1.21.0 // don't upgrade this one
golang.org/x/sync v0.7.0
golang.org/x/sys v0.19.0
golang.org/x/sys v0.21.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

Expand Down
12 changes: 7 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/panjf2000/ants/v2 v2.9.0 h1:SztCLkVxBRigbg+vt0S5QvF5vxAbxbKt09/YfAJ0tEo=
github.com/panjf2000/ants/v2 v2.9.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/panjf2000/ants/v2 v2.10.0 h1:zhRg1pQUtkyRiOFo2Sbqwjp0GfBNo9cUY2/Grpx1p+8=
github.com/panjf2000/ants/v2 v2.10.0/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
Expand Down Expand Up @@ -53,8 +55,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
Loading