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

[Question]: gnet engine is stopping with error: kevent add|clear:function not implemented #552

Open
3 tasks done
dul666888 opened this issue Mar 19, 2024 · 7 comments
Open
3 tasks done
Labels
help wanted Extra attention is needed needs investigation needs more info OS-FreeBSD question Further information is requested
Milestone

Comments

@dul666888
Copy link

Actions I've taken before I'm here

  • I've thoroughly read the documentations about this problem but still have no answer.
  • I've searched the Github Issues/Discussions but didn't find any similar problems that have been solved.
  • I've searched the internet for this problem but didn't find anything helpful.

Questions with details

gnet跑一个基于tcp的socket服务端.目标系统freebsd11.2
实现了onboot,onopen,onclose,onshutdown,ontraffic 接口.
启动时提示错误:
[gnet] 2024-03-19T20:45:28.808010602+08:00 ERROR v2@v2.3.5/engine_unix.go:282 gnet engine is stopping with error: kevent add|clear: function not implemented
github.com/panjf2000/gnet/v2.run
/root/go/pkg/mod/github.com/panjf2000/gnet/v2@v2.3.5/engine_unix.go:282
github.com/panjf2000/gnet/v2.Run
/root/go/pkg/mod/github.com/panjf2000/gnet/v2@v2.3.5/gnet.go:495
mt_server/Client.InitMtServer
/usr/zz/server1/game1/Client/Server.go:71

Code snippets (optional)

package Client

import (
	"context"
	"fmt"
	"mt_server/Common"
	"mt_server/Game"
	"mt_server/Logs"
	"sync/atomic"
	"time"

	"github.com/panjf2000/gnet/v2"
)

var (
	MtServerListener *MTServer
)

type MTServer struct {
	gnet.BuiltinEventEngine
	eng          gnet.Engine
	protoAddr    string
	multicore    bool
	connected    int32
	disconnected int32
}

func (s *MTServer) OnBoot(eng gnet.Engine) (action gnet.Action) {
	Logs.InfoF("BINDING PORT [%d]", Game.ConfigObj.Port)
	s.eng = eng
	return
}

func (s *MTServer) OnOpen(c gnet.Conn) (out []byte, action gnet.Action) {
	atomic.AddInt32(&s.connected, 1)
	atomic.AddInt32(&Common.SocketConnectPlayer, 1)
	Game.InitDescriptor(c)
	return
}

func (s *MTServer) OnClose(c gnet.Conn, err error) (action gnet.Action) {
	atomic.AddInt32(&s.disconnected, 1)
	atomic.AddInt32(&s.connected, -1)
	atomic.AddInt32(&Common.SocketConnectPlayer, -1)
	c.Flush()
	SocketClose(c)
	return
}

func (s *MTServer) OnTraffic(c gnet.Conn) (action gnet.Action) {
	l := c.InboundBuffered()
	data, _ := c.Peek(l)
	RecvBroadcast <- Common.MsgID{Conn: c, Packet: data}
	return
}

func (s *MTServer) OnShutdown(eng gnet.Engine) {
	Game.CloseAllDescriptor()
}

func InitMtServer() {
	multicore := true
	MtServerListener = &MTServer{
		protoAddr: fmt.Sprintf("tcp://:%d", Game.ConfigObj.Port),
		multicore: multicore,
	}

	err := gnet.Run(MtServerListener, MtServerListener.protoAddr, gnet.WithMulticore(multicore))
	if err != nil {
		Logs.ErrorF("server exits with error: %v", err)
	}
}

func ListenClose() {
	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
	gnet.Stop(ctx, MtServerListener.protoAddr)
	cancel()
}
@dul666888 dul666888 added help wanted Extra attention is needed question Further information is requested labels Mar 19, 2024
@panjf2000
Copy link
Owner

怎么还是用的这个模板。。。算了,看起来相关的信息应该够了。

@panjf2000
Copy link
Owner

panjf2000 commented Mar 19, 2024

看起来像是你的 freebsd 系统没有 kqueue, 但是你的系统版本又是 11.2,按道理应该是有的。你的 freebsd 是安装在物理机还是虚拟机上的?

运行一下 man 2 kevent 命令看看你的系统里有没有这个系统调用。

@dul666888
Copy link
Author

虚拟机里的。
运行man 2 kevent 命令截图:
QQ图片20240319213245

@panjf2000
Copy link
Owner

你是在服务器上进行虚拟化还是桌面电脑的虚拟机软件?这个问题比较奇怪,可能是虚拟机的问题,我以前在 freebsd 云服务器上测试过是没问题的。

@dul666888
Copy link
Author

在我个人电脑上运行的虚拟机VMware® Workstation 17.0.0 build-20800274
freebsd装的11.2 amd64版本,go是用的1.19.1

Copy link

This issue is marked as stale because it has been open for 30 days with no activity.

You should take one of the following actions:

  • Manually close this issue if it is no longer relevant
  • Comment if you have more information to share

This issue will be automatically closed in 7 days if no further activity occurs.

@github-actions github-actions bot added the stale label Sep 26, 2024
@panjf2000 panjf2000 removed the stale label Sep 26, 2024
Copy link

This issue is marked as stale because it has been open for 30 days with no activity.

You should take one of the following actions:

  • Manually close this issue if it is no longer relevant
  • Comment if you have more information to share

This issue will be automatically closed in 7 days if no further activity occurs.

@github-actions github-actions bot added the stale label Oct 27, 2024
@panjf2000 panjf2000 removed the stale label Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed needs investigation needs more info OS-FreeBSD question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants