traffic

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

README

traffic

描述:io 通信控制模块

  • 管理所有的需要热重启的监听管理(端口监听)
  • 只允许master执行新增,序列化成描述信息+文件描述符列表
  • 在fork worker时传递给worker
  • worker只允许使用传入进来的端口

用法

// master
// 首次启动
tf, err := traffic.ReadController(os.stdint, &net.TCPAddr{
IP:   "0.0.0.0",
Port: 8080,
})
// 导出
traffics, files := tf.Export(3)
trafficsData, err := proto.Marshal(&traffic.PbTraffics{Traffic: traffics})
// 新进程
cmd := exec.Command(path)
cmd.Stdin = bytes.NewReader(data)
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}
cmd.ExtraFiles = files


// 热重启,新进程,会在复用的前提下监听新的tcpAddr列表,并关闭不再使用的listener
traffic, err := traffic.ReadController(os.stdint, &net.TCPAddr{
IP:   "0.0.0.0",
Port: 8080,
},
&net.TCPAddr{ // 新增端口
IP:   "0.0.0.0",
Port: 9090,
})

//worker 中
trafficConfigs = read from os.Stdin
tf:=traffic.NewTraffic(tfConf)

// 启用服务

l := tf.ListenTcp(port, traffic.Http1)
if l == nil {
    panic(fmt.SprintF("port:%s is not listener",port))
}

err:=http.Serve(l,handler)


Documentation

Overview

  • Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
  • Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
  • Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
  • Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
  • Vestibulum commodo. Ut rhoncus gravida arcu. *

io 通信控制模块 管理所有的需要热重启的监听管理(端口监听), 只允许master执行新增, 序列化成描述信息+文件描述符列表,在fork worker时传递给worker, worker只允许使用传入进来的端口

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidListener = errors.New("invalid port-reqiure")
)

Functions

This section is empty.

Types

type EmptyTraffic added in v0.5.0

type EmptyTraffic struct {
}

func (*EmptyTraffic) Close added in v0.5.0

func (e *EmptyTraffic) Close()

func (*EmptyTraffic) IsStop added in v0.5.0

func (e *EmptyTraffic) IsStop() bool

func (*EmptyTraffic) Listen added in v0.8.1

func (e *EmptyTraffic) Listen(addrs ...string) (tcp []net.Listener, ssl []net.Listener)

type ITraffic

type ITraffic interface {
	Listen(addrs ...string) (tcp []net.Listener, ssl []net.Listener)
	IsStop() bool
	Close()
}

func FromArg added in v0.8.1

func FromArg(traffics []*PbTraffic) ITraffic

func NewEmptyTraffic added in v0.5.0

func NewEmptyTraffic() ITraffic

func NewTraffic

func NewTraffic(trafficData *TrafficData) ITraffic

type PbTraffic

type PbTraffic struct {
	FD      uint64 `json:"FD,omitempty"`
	Addr    string `json:"Addr,omitempty"`
	Network string `json:"Network,omitempty"`
}

func Export added in v0.8.1

func Export(data *TrafficData, startIndex int) ([]*PbTraffic, []*os.File)

type PbTraffics

type PbTraffics struct {
	Traffic []*PbTraffic `json:"traffic,omitempty"`
}

type Traffic

type Traffic struct {
	*TrafficData
}

func (*Traffic) Listen added in v0.8.1

func (t *Traffic) Listen(addrs ...string) (tcp []net.Listener, ssl []net.Listener)

type TrafficData added in v0.8.1

type TrafficData struct {
	// contains filtered or unexported fields
}

func NewTrafficData added in v0.8.1

func NewTrafficData(data map[string]*net.TCPListener) *TrafficData

func ReadTraffic added in v0.8.1

func ReadTraffic(r io.Reader, addrs ...string) (*TrafficData, error)

func (*TrafficData) All added in v0.8.1

func (t *TrafficData) All() map[string]*net.TCPListener

func (*TrafficData) Close added in v0.8.1

func (t *TrafficData) Close()

func (*TrafficData) IsStop added in v0.8.1

func (t *TrafficData) IsStop() bool

func (*TrafficData) Shutdown added in v0.8.1

func (t *TrafficData) Shutdown()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL