This commit is contained in:
esrrhs 2019-11-01 20:52:18 +08:00
parent 1657f46784
commit 5c0c08b7f3
2 changed files with 27 additions and 4 deletions

View File

@ -74,6 +74,12 @@ Usage:
-maxconn 最大连接数默认1000 -maxconn 最大连接数默认1000
the max num of connections, default 1000 the max num of connections, default 1000
-maxprt server最大处理线程数默认100
max process thread in server, default 100
-maxprb server最大处理线程buffer数默认1000
max process thread's buffer in server, default 1000
` `
func main() { func main() {
@ -94,6 +100,8 @@ func main() {
loglevel := flag.String("loglevel", "info", "log level") loglevel := flag.String("loglevel", "info", "log level")
open_sock5 := flag.Int("sock5", 0, "sock5 mode") open_sock5 := flag.Int("sock5", 0, "sock5 mode")
maxconn := flag.Int("maxconn", 0, "max num of connections") maxconn := flag.Int("maxconn", 0, "max num of connections")
max_process_thread := flag.Int("maxprt", 0, "max process thread in server")
max_process_buffer := flag.Int("maxprb", 0, "max process thread's buffer in server")
flag.Usage = func() { flag.Usage = func() {
fmt.Printf(usage) fmt.Printf(usage)
} }
@ -136,7 +144,7 @@ func main() {
loggo.Info("key %d", *key) loggo.Info("key %d", *key)
if *t == "server" { if *t == "server" {
s, err := pingtunnel.NewServer(*key, *maxconn) s, err := pingtunnel.NewServer(*key, *maxconn, *max_process_thread, *max_process_buffer)
if err != nil { if err != nil {
loggo.Error("ERROR: %s", err.Error()) loggo.Error("ERROR: %s", err.Error())
return return

View File

@ -3,6 +3,7 @@ package pingtunnel
import ( import (
"github.com/esrrhs/go-engine/src/common" "github.com/esrrhs/go-engine/src/common"
"github.com/esrrhs/go-engine/src/loggo" "github.com/esrrhs/go-engine/src/loggo"
"github.com/esrrhs/go-engine/src/threadpool"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"golang.org/x/net/icmp" "golang.org/x/net/icmp"
"net" "net"
@ -10,12 +11,19 @@ import (
"time" "time"
) )
func NewServer(key int, maxconn int) (*Server, error) { func NewServer(key int, maxconn int, maxprocessthread int, maxprocessbuffer int) (*Server, error) {
return &Server{ s := &Server{
exit: false, exit: false,
key: key, key: key,
maxconn: maxconn, maxconn: maxconn,
}, nil }
s.processtp = threadpool.NewThreadPool(maxprocessthread, maxprocessbuffer, func(v interface{}) {
packet := v.(*Packet)
s.processDataPacket(packet)
})
return s, nil
} }
type Server struct { type Server struct {
@ -38,6 +46,8 @@ type Server struct {
echoId int echoId int
echoSeq int echoSeq int
processtp *threadpool.ThreadPool
} }
type ServerConn struct { type ServerConn struct {
@ -124,6 +134,11 @@ func (p *Server) processPacket(packet *Packet) {
return return
} }
p.processtp.AddJob((int)(common.HashString(packet.my.Id)), packet)
}
func (p *Server) processDataPacket(packet *Packet) {
loggo.Debug("processPacket %s %s %d", packet.my.Id, packet.src.String(), len(packet.my.Data)) loggo.Debug("processPacket %s %s %d", packet.my.Id, packet.src.String(), len(packet.my.Data))
now := time.Now() now := time.Now()