Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/fnet/ftcp

ftcp

go
import "gitlab.soludian.com/soludian/fountain/libs/fnet/ftcp"

Index

Constants

go
const KMaxConcurrentConnection = 10000000

PackageName package name

go
const KPackageName = "ftcp_server"

Variables

go
var GetFountainInstance = Lib.GetFountainInstance

go
var GetFountainManager = Lib.GetFountainManager

Sử dụng khi config instance ở dạng key:value; Nếu config instance ở dạng key:array thì sử dụng hàm InstallFountainInstances Nếu config ở dạng key:array thì sẽ chỉ install config phần tử đầu tiên mà thôi

Install with config format <key>:<value>; eg: ftcp:<value>

Usage:

config.yaml:

	ftcp:
	  name: default_name
	  ...

	code.go

	ftcp.InstallFountainInstance()

 ftcp.WithConfigKey("ftcp").InstallFountainInstance()
go
var InstallFountainInstance = Lib.InstallFountainInstance

Sử dụng khi config instance ở dạng key:array<value>; Sẽ luôn cố gắng khởi tạo kể cả khi config ở dạng key:value

Install with config format <key>:array<value>; eg: ftcp:array<value>

Usage:

config.yaml:

ftcp:
  - name: default_name
    ...

code.go

ftcp.InstallFountainInstances()

ftcp.WithConfigKey("ftcp").InstallFountainInstances()
go
var InstallFountainInstances = Lib.InstallFountainInstances

go
var KDefaultServerName = env.GetFullAppService(KPackageName)

Truy cập thẳng tới bộ quản lý thư viện

go
var Lib = lib_3rd.NewLib(newServer, lib_3rd.WithDefaultConfigFunc[config, Server](DefaultConfig))

go
var WithConfigKey = Lib.WithConfigKey

func Accept

go
func Accept(listener net.Listener) (net.Conn, error)

Accept func. Server accept a connection.

func RegisterServiceHandler

go
func RegisterServiceHandler(x proto.Message, handler Handle)

RegisterServiceHandler func;

func RegisterType

go
func RegisterType(x proto.Message, name string)

RegisterType func; Register a type of object that can send or receive over ftcp;

func WithAddr

go
func WithAddr(addr string) lib_3rd.Option[config]

func WithConfig

go
func WithConfig(conf *config) lib_3rd.Option[config]

WithConfig

func WithConnectionMaxIdleTime

go
func WithConnectionMaxIdleTime(duration time.Duration) lib_3rd.Option[config]

func WithDisableHeartbeat

go
func WithDisableHeartbeat(disable ...bool) lib_3rd.Option[config]

func WithDisableTraceMiddleware

go
func WithDisableTraceMiddleware(disable ...bool) lib_3rd.Option[config]

func WithHeartbeatInterval

go
func WithHeartbeatInterval(interval time.Duration) lib_3rd.Option[config]

func WithMaxConcurrentConnection

go
func WithMaxConcurrentConnection(maxConcurrentConnection int) lib_3rd.Option[config]

func WithName

go
func WithName(name string) lib_3rd.Option[config]

func WithProtoName

go
func WithProtoName(protoName string) lib_3rd.Option[config]

func WithSendChanSize

go
func WithSendChanSize(sendChanSize int) lib_3rd.Option[config]

func WithServerCallbackInstance

go
func WithServerCallbackInstance(instance ServerCallback) lib_3rd.Option[config]

func WithVacuumInterval

go
func WithVacuumInterval(interval time.Duration) lib_3rd.Option[config]

type Handle

go
type Handle func(*connect.Connection, *codec.MessageController, proto.Message) error

func FindHandler

go
func FindHandler(msg proto.Message) Handle

FindHandler func;

type Server

go
type Server struct {
    *runnable.ServerInstance
    // contains filtered or unexported fields
}

func (*Server) Destroy

go
func (s *Server) Destroy() error

Destroy func

func (*Server) GetConnection

go
func (s *Server) GetConnection(connID uint64) *connect.Connection

GetConnection func

func (*Server) GracefulStop

go
func (s *Server) GracefulStop(ctx context.Context) error

GracefulStop implements Runnable interface it will stop echo server gracefully

func (*Server) IsRunning

go
func (s *Server) IsRunning() bool

IsRunning func

func (*Server) OnTCPConnectionClosed

go
func (s *Server) OnTCPConnectionClosed(conn *connect.Connection)

OnTCPConnectionClosed func to implement connect.ConnectionClosedCallback interface

func (*Server) PackageName

go
func (s *Server) PackageName() string

PackageName package name

func (*Server) Pause

go
func (s *Server) Pause()

Pause func

func (*Server) SendBroadcastMessage

go
func (s *Server) SendBroadcastMessage(msg any) error

SendBroadcastMessage func; Send msg to all connection that was connected msg can be either *codec.Message or proto.Message or []byte

func (*Server) SendMessageByConn

go
func (s *Server) SendMessageByConn(conn *connect.Connection, msg any) error

func (*Server) SendMessageByConnID

go
func (s *Server) SendMessageByConnID(connID uint64, msg any) error

SendMessageByConnID func; Send data according to ConnID

func (*Server) SendMessageProtoByConn

go
func (s *Server) SendMessageProtoByConn(conn *connect.Connection, cntl *codec.MessageController, msg proto.Message) error

SendMessageProtoByConn func; Find client by addr and send msg to all connection that was connected

func (*Server) Serving

go
func (s *Server) Serving()

Serve func need run in a goroutine

func (*Server) Serving2

go
func (s *Server) Serving2()

Serve2 func; Using connect.NewBufferedConn, not comparable with codec interface TODO(@Kim Ericko): A tricky way

type ServerCallback

go
type ServerCallback interface {
    OnNewTCPClient(conn *connect.Connection)
    OnTCPClientDataArrived(conn *connect.Connection, msg any) error
    OnTCPClientClosed(conn *connect.Connection)
}

Generated by gomarkdoc