Skip to content

Commit

Permalink
Merge branch 'panjf2000:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wubenqi authored Aug 30, 2023
2 parents a22d000 + 89672dc commit 395ff02
Show file tree
Hide file tree
Showing 66 changed files with 735 additions and 578 deletions.
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ body:
- BSD
validations:
required: true
- type: input
id: os-version
attributes:
label: OS version
description: What's the specific version of OS?
placeholder: "Run `uname -srm` command to get the info, for example: Darwin 21.5.0 arm64, Linux 5.4.0-137-generic x86_64"
validations:
required: true
- type: input
id: go-version
attributes:
label: Go version
description: What's the specific version of Go?
placeholder: "Run `go version` command to get the info, for example: go1.20.5 linux/amd64"
validations:
required: true
- type: textarea
id: logs
attributes:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ on:
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/codeql.yml'
pull_request:
branches:
- master
- dev
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/codeql.yml'
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check pull request target
on:
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- master
jobs:
check-branches:
runs-on: ubuntu-latest
steps:
- name: Check target branch
run: |
if [ ${{ github.head_ref }} != "dev" ]; then
echo "Only pull requests from dev branch are only allowed to be merged into master branch."
exit 1
fi
File renamed without changes.
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ on:
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/test.yml'
pull_request:
branches:
- master
- dev
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/test.yml'

env:
GO111MODULE: on
Expand Down Expand Up @@ -49,7 +55,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.18', '1.19', '1.20']
go: ['1.17', '1.21']
os:
- ubuntu-latest
- macos-latest
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test_gc_opt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ on:
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/test_gc_opt.yml'
pull_request:
branches:
- master
- dev
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/test_gc_opt.yml'

env:
GO111MODULE: on
Expand Down Expand Up @@ -49,7 +55,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.18', '1.19', '1.20']
go: ['1.17', '1.21']
os:
- ubuntu-latest
- macos-latest
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test_poll_opt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ on:
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/test_poll_opt.yml'
pull_request:
branches:
- master
- dev
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/test_poll_opt.yml'

env:
GO111MODULE: on
Expand Down Expand Up @@ -48,7 +54,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.18', '1.19', '1.20']
go: ['1.17', '1.21']
os: [ubuntu-latest, macos-latest]
name: Go ${{ matrix.go }} @ ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test_poll_opt_gc_opt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ on:
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/test_poll_opt_gc_opt.yml'
pull_request:
branches:
- master
- dev
- 1.x
paths-ignore:
- '**.md'
- '**.yml'
- '**.yaml'
- '!.github/workflows/test_poll_opt_gc_opt.yml'

env:
GO111MODULE: on
Expand Down Expand Up @@ -48,7 +54,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.18', '1.19', '1.20']
go: ['1.17', '1.21']
os: [ubuntu-latest, macos-latest]
name: Go ${{ matrix.go }} @ ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<br />
<a title="Build Status" target="_blank" href="https://github.com/panjf2000/gnet/actions?query=workflow%3ATests"><img src="https://img.shields.io/github/actions/workflow/status/panjf2000/gnet/test.yml?branch=dev&style=flat-square&logo=github-actions" /></a>
<a title="Codecov" target="_blank" href="https://codecov.io/gh/panjf2000/gnet"><img src="https://img.shields.io/codecov/c/github/panjf2000/gnet?style=flat-square&logo=codecov" /></a>
<a title="Supported Platforms" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/platform-Linux%20%7C%20FreeBSD%20%7C%20DragonFly%20%7C%20Darwin%20%7C%20Windows-549688?style=flat-square&logo=launchpad" /></a>
<a title="Supported Platforms" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/platform-Linux%20%7C%20FreeBSD%20%7C%20DragonFly%20%7C%20NetBSD%20%7C%20OpenBSD%20%7C%20Darwin%20%7C%20Windows-549688?style=flat-square&logo=launchpad" /></a>
<a title="Require Go Version" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/go-%3E%3D1.17-30dff3?style=flat-square&logo=go" /></a>
<br />
<a title="Chat Room" target="_blank" href="https://gitter.im/gnet-io/gnet?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/gnet-io/gnet.svg" /></a>
Expand All @@ -28,17 +28,18 @@ English | [中文](README_ZH.md)

# 🚀 Features

- [x] [High-performance](#-performance) event-loop under networking model of multiple threads/goroutines
- [x] [High-performance](#-performance) event-driven looping based on a networking model of multiple threads/goroutines
- [x] Built-in goroutine pool powered by the library [ants](https://github.com/panjf2000/ants)
- [x] Lock-free during the entire runtime
- [x] Concise and easy-to-use APIs
- [x] Efficient, reusable, and elastic memory buffer: (Elastic-)Ring-Buffer, Linked-List-Buffer and Elastic-Mixed-Buffer
- [x] Supporting multiple protocols/IPC mechanisms: `TCP`, `UDP`, and `Unix Domain Socket`
- [x] Supporting multiple load-balancing algorithms: `Round-Robin`, `Source-Addr-Hash`, and `Least-Connections`
- [x] Supporting two event-driven mechanisms: `epoll` on **Linux** and `kqueue` on **FreeBSD/DragonFly/Darwin**
- [x] Multiple protocols/IPC mechanisms: `TCP`, `UDP`, and `Unix Domain Socket`
- [x] Multiple load-balancing algorithms: `Round-Robin`, `Source-Addr-Hash`, and `Least-Connections`
- [x] Two event-driven mechanisms: `epoll` on **Linux** and `kqueue` on **FreeBSD/DragonFly/Darwin**
- [x] Flexible ticker event
- [x] Implementation of `gnet` Client
- [x] **Windows** platform support (For compatibility in development only, do not use it in production)
- [ ] Multiple network addresses binding
- [ ] **TLS** support
- [ ] [io_uring](https://kernel.dk/io_uring.pdf) support

Expand Down
11 changes: 6 additions & 5 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<br />
<a title="Build Status" target="_blank" href="https://github.com/panjf2000/gnet/actions?query=workflow%3ATests"><img src="https://img.shields.io/github/actions/workflow/status/panjf2000/gnet/test.yml?branch=dev&style=flat-square&logo=github-actions" /></a>
<a title="Codecov" target="_blank" href="https://codecov.io/gh/panjf2000/gnet"><img src="https://img.shields.io/codecov/c/github/panjf2000/gnet?style=flat-square&logo=codecov" /></a>
<a title="Supported Platforms" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/platform-Linux%20%7C%20FreeBSD%20%7C%20DragonFly%20%7C%20Darwin%20%7C%20Windows-549688?style=flat-square&logo=launchpad" /></a>
<a title="Supported Platforms" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/platform-Linux%20%7C%20FreeBSD%20%7C%20DragonFly%20%7C%20NetBSD%20%7C%20OpenBSD%20%7C%20Darwin%20%7C%20Windows-549688?style=flat-square&logo=launchpad" /></a>
<a title="Require Go Version" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/go-%3E%3D1.17-30dff3?style=flat-square&logo=go" /></a>
<br />
<a title="Chat Room" target="_blank" href="https://gitter.im/gnet-io/gnet?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/gnet-io/gnet.svg" /></a>
Expand All @@ -28,17 +28,18 @@

# 🚀 功能

- [x] [高性能](#-性能测试) 的基于多线程/Go程网络模型的 event-loop 事件驱动
- [x] 基于多线程/协程网络模型的[高性能](#-性能测试)事件驱动循环
- [x] 内置 goroutine 池,由开源库 [ants](https://github.com/panjf2000/ants) 提供支持
- [x] 整个生命周期是无锁的
- [x] 简单易用的 APIs
- [x] 高效、可重用而且自动伸缩的内存 buffer:(Elastic-)Ring-Buffer, Linked-List-Buffer and Elastic-Mixed-Buffer
- [x] 支持多种网络协议/IPC 机制:`TCP``UDP``Unix Domain Socket`
- [x] 支持多种负载均衡算法`Round-Robin(轮询)``Source-Addr-Hash(源地址哈希)``Least-Connections(最少连接数)`
- [x] 支持两种事件驱动机制**Linux** 里的 `epoll` 以及 **FreeBSD/DragonFly/Darwin** 里的 `kqueue`
- [x] 多种网络协议/IPC 机制:`TCP``UDP``Unix Domain Socket`
- [x] 多种负载均衡算法`Round-Robin(轮询)``Source-Addr-Hash(源地址哈希)``Least-Connections(最少连接数)`
- [x] 两种事件驱动机制**Linux** 里的 `epoll` 以及 **FreeBSD/DragonFly/Darwin** 里的 `kqueue`
- [x] 灵活的事件定时器
- [x] 实现 `gnet` 客户端
- [x] 支持 **Windows** 平台 (仅用于开发环境的兼容性,不要在生产环境中使用)
- [ ] 多网络地址绑定
- [ ] 支持 **TLS**
- [ ] 支持 [io_uring](https://kernel.dk/io_uring.pdf)

Expand Down
25 changes: 25 additions & 0 deletions acceptor_bsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2023 The Gnet Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build freebsd || dragonfly || netbsd || openbsd || darwin
// +build freebsd dragonfly netbsd openbsd darwin

package gnet

// The canonical BSD sockets implementation will inherit file status flags
// from the listening socket, so we don't need to set the non-blocking flag
// for the accepted sockets explicitly.
func setNonBlock(_ int, _ bool) error {
return nil
}
24 changes: 24 additions & 0 deletions acceptor_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2023 The Gnet Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package gnet

import "golang.org/x/sys/unix"

func setNonBlock(fd int, nonBlocking bool) error {
return unix.SetNonblock(fd, nonBlocking)
}
10 changes: 5 additions & 5 deletions acceptor_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux || freebsd || dragonfly || darwin
// +build linux freebsd dragonfly darwin
//go:build linux || freebsd || dragonfly || netbsd || openbsd || darwin
// +build linux freebsd dragonfly netbsd openbsd darwin

package gnet

Expand Down Expand Up @@ -44,7 +44,7 @@ func (eng *engine) accept(fd int, _ netpoll.IOEvent) error {
}
}

if err = os.NewSyscallError("fcntl nonblock", unix.SetNonblock(nfd, true)); err != nil {
if err = os.NewSyscallError("fcntl nonblock", setNonBlock(nfd, true)); err != nil {
return err
}
remoteAddr := socket.SockaddrToTCPOrUnixAddr(sa)
Expand All @@ -53,7 +53,7 @@ func (eng *engine) accept(fd int, _ netpoll.IOEvent) error {
logging.Error(err)
}

el := eng.lb.next(remoteAddr)
el := eng.eventLoops.next(remoteAddr)
c := newTCPConn(nfd, el, sa, el.ln.addr, remoteAddr)
err = el.poller.UrgentTrigger(el.register, c)
if err != nil {
Expand Down Expand Up @@ -83,7 +83,7 @@ func (el *eventloop) accept(fd int, ev netpoll.IOEvent) error {
}
}

if err = os.NewSyscallError("fcntl nonblock", unix.SetNonblock(nfd, true)); err != nil {
if err = os.NewSyscallError("fcntl nonblock", setNonBlock(nfd, true)); err != nil {
return err
}
remoteAddr := socket.SockaddrToTCPOrUnixAddr(sa)
Expand Down
4 changes: 2 additions & 2 deletions acceptor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (eng *engine) listen() (err error) {
return
}

el := eng.lb.next(addr)
el := eng.eventLoops.next(addr)
c := newUDPConn(el, eng.ln.addr, addr)
el.ch <- packUDPConn(c, buffer[:n])
} else {
Expand All @@ -49,7 +49,7 @@ func (eng *engine) listen() (err error) {
eng.opts.Logger.Errorf("Accept() fails due to error: %v", err)
return
}
el := eng.lb.next(tc.RemoteAddr())
el := eng.eventLoops.next(tc.RemoteAddr())
c := newTCPConn(tc, el)
el.ch <- c
go func(c *conn, tc net.Conn, el *eventloop) {
Expand Down
Loading

0 comments on commit 395ff02

Please sign in to comment.