Skip to content

Commit

Permalink
升级 gtcp,gudp 组件
Browse files Browse the repository at this point in the history
  • Loading branch information
camry committed Nov 21, 2022
1 parent 1d090b2 commit bd60664
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/camry/dove
go 1.18

require (
github.com/camry/g v1.2.2
github.com/camry/g v1.2.4
github.com/google/uuid v1.3.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
google.golang.org/grpc v1.46.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/camry/g v1.2.2 h1:p/Q0AHpWcxTkxiJS2AAMmc1qJNUbdStMzHssV9Y8YOA=
github.com/camry/g v1.2.2/go.mod h1:oHGlPoCKs7aJ6zeT2SfIpUfPE+jhAjnCRxXmknpSK5o=
github.com/camry/g v1.2.4 h1:MFgNpjI4lPrd1Tlb4DxcI9aFgJYni4YKs65eA0dJaJo=
github.com/camry/g v1.2.4/go.mod h1:oHGlPoCKs7aJ6zeT2SfIpUfPE+jhAjnCRxXmknpSK5o=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
Expand Down
7 changes: 5 additions & 2 deletions server/gtcp/gtcp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gtcp
import (
"context"
"crypto/tls"

"github.com/camry/g/glog"
"github.com/camry/g/gnet/gtcp"
)
Expand Down Expand Up @@ -43,7 +44,9 @@ type Server struct {
// NewServer 新建 TCP 服务器。
func NewServer(opts ...ServerOption) *Server {
srv := &Server{
log: glog.NewHelper(glog.GetLogger()),
address: ":0",
handler: func(conn *gtcp.Conn) {},
log: glog.NewHelper(glog.GetLogger()),
}
for _, opt := range opts {
opt(srv)
Expand All @@ -54,7 +57,7 @@ func NewServer(opts ...ServerOption) *Server {

// Start 启动 TCP 服务器。
func (s *Server) Start(ctx context.Context) (err error) {
s.log.Infof("[TCP] server listening on: %s", s.Listener().Addr().String())
s.log.Infof("[TCP] server listening on %s", s.GetListenedAddress())
return s.Run(ctx)
}

Expand Down
5 changes: 2 additions & 3 deletions server/gudp/gudp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gudp

import (
"context"

"github.com/camry/g/glog"
"github.com/camry/g/gnet/gudp"
)
Expand All @@ -28,7 +29,6 @@ func Handler(handler func(*gudp.Conn)) ServerOption {
type Server struct {
*gudp.Server

network string // UDP 服务器网络协议。
address string // UDP 服务器监听地址。
handler func(*gudp.Conn) // UDP 连接的处理程序。
log *glog.Helper // 日志助手。
Expand All @@ -37,7 +37,6 @@ type Server struct {
// NewServer 新建 UDP 服务器。
func NewServer(opts ...ServerOption) *Server {
srv := &Server{
network: "udp",
address: ":0",
handler: func(conn *gudp.Conn) {},
log: glog.NewHelper(glog.GetLogger()),
Expand All @@ -51,7 +50,7 @@ func NewServer(opts ...ServerOption) *Server {

// Start 启动 UDP 服务器。
func (s *Server) Start(ctx context.Context) error {
s.log.Infof("[UDP] server listening on: %s", s.Conn().LocalAddr().String())
s.log.Infof("[UDP] server listening on %s", s.GetListenedAddress())
return s.Run(ctx)
}

Expand Down

0 comments on commit bd60664

Please sign in to comment.