Ai
4 Star 18 Fork 9

NightTC/Gobige

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
init.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
buguang 提交于 2025-08-21 10:15 +08:00 . feat(sess): 增加会话层超时和心跳配置
package sess
import (
"fmt"
"net"
"gitee.com/night-tc/gobige/global"
"github.com/xtaci/kcp-go"
"golang.org/x/net/netutil"
)
/*
实现连接逻辑的包
*/
func GetListener(protocal string, info *global.ListenCfg) (result net.Listener, port int) {
var err error
for port = info.PortMin; port <= info.PortMax; port++ {
switch protocal {
case "tcp":
result, err = net.Listen("tcp",
fmt.Sprintf("%s:%d", info.Listen, port))
case "kcp":
result, err = kcp.Listen(fmt.Sprintf("%s:%d", info.Listen, port))
default:
panic("WRONG PROTOCAL")
}
if err == nil {
break
}
}
if err != nil {
panic(err)
}
if info.MaxConn > 0 {
result = netutil.LimitListener(result, info.MaxConn)
}
return
}
type IkcpSession interface {
// SetStreamMode toggles the stream mode on/off
SetStreamMode(enable bool)
// SetWindowSize set maximum window size
SetWindowSize(sndwnd, rcvwnd int)
// SetNoDelay calls nodelay() of kcp
// https://github.com/skywind3000/kcp/blob/master/README.en.md#protocol-configuration
SetNoDelay(nodelay, interval, resend, nc int)
// SetDSCP sets the 6bit DSCP field in IPv4 header, or 8bit Traffic Class in IPv6 header.
//
// if the underlying connection has implemented `func SetDSCP(int) error`, SetDSCP() will invoke
// this function instead.
//
// It has no effect if it's accepted from Listener.
SetDSCP(dscp int) error
// SetMtu sets the maximum transmission unit(not including UDP header)
SetMtu(mtu int) bool
// SetACKNoDelay changes ack flush option, set true to flush ack immediately,
SetACKNoDelay(nodelay bool)
}
const (
// 压缩标记
SessFlag_Compress = 1 << iota
// 加密标记
SessFlag_Encrypt
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/night-tc/gobige.git
git@gitee.com:night-tc/gobige.git
night-tc
gobige
Gobige
3e11984fb1ba

搜索帮助