nps_mux

package module
v0.0.0-...-4afa0c1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: GPL-3.0 Imports: 17 Imported by: 2

README

nps-mux

A net connection multiplexing implementation base on golang

Key feature:

  • Code division
  • Conn interface implements
  • Lock free queue
  • Slide window
  • Tcp like reliable stream connection based on

Usage

  1. Dial or Accept a net.Conn

    • client: c_client := net.Dial("tcp", "127.0.0.1:8024")
    • server: listener, err := net.Listen("tcp", "127.0.0.1:8024") c_server, err := listener.Accept()
  2. Make connection to mux connection

    • client: mux_client := nps_mux.NewMux(c_client, "tcp", 60)
    • server: mux_server := nps_mux.NewMux(c_server, "tcp", 60)
  3. You can handle new connections both side, like this

    • client: newConn, err := mux_client.Accept()
    • server: clientConn, err := mux_server.NewConn()

newConn and clientConn are transfer data though mux connection

You can use Read Write method to transfer your own data

More

See mux_test.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ips

func Ips() (map[string]string, error)

func NewBandwidth

func NewBandwidth(fd *os.File) *bandwidth

func NewConn

func NewConn(connId int32, mux *Mux) *conn

func NewConnMap

func NewConnMap() *connMap

Types

type Conn

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

func NewRateConn

func NewRateConn(rate *Rate, conn net.Conn) *Conn

func (*Conn) Close

func (conn *Conn) Close() error

func (*Conn) LocalAddr

func (conn *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (conn *Conn) Read(b []byte) (n int, err error)

func (*Conn) RemoteAddr

func (conn *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (conn *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (conn *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (conn *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (conn *Conn) Write(b []byte) (n int, err error)

type Eth

type Eth struct {
	EthName string
	EthAddr string
}

func GetEthByIp

func GetEthByIp(ipAddr string) (eth *Eth, err error)

get ip and Eth information by Eth name

type Mux

type Mux struct {
	net.Listener

	IsClose bool
	// contains filtered or unexported fields
}

func NewMux

func NewMux(c net.Conn, connType string, pingCheckThreshold int) *Mux

func (*Mux) Accept

func (s *Mux) Accept() (net.Conn, error)

func (*Mux) Addr

func (s *Mux) Addr() net.Addr

func (*Mux) Close

func (s *Mux) Close() (err error)

func (*Mux) NewConn

func (s *Mux) NewConn() (*conn, error)

type Rate

type Rate struct {
	NowRate int64
	// contains filtered or unexported fields
}

func NewRate

func NewRate(addSize int64) *Rate

func (*Rate) Get

func (s *Rate) Get(size int64)

func (*Rate) ReturnBucket

func (s *Rate) ReturnBucket(size int64)

回桶

func (*Rate) Start

func (s *Rate) Start()

func (*Rate) Stop

func (s *Rate) Stop()

停止

type TrafficControl

type TrafficControl struct {
	Eth *Eth
	// contains filtered or unexported fields
}

func NewTrafficControl

func NewTrafficControl(ipAddr string) (*TrafficControl, error)

func (*TrafficControl) Run

func (tc *TrafficControl) Run() error

func (*TrafficControl) RunNetRangeTest

func (tc *TrafficControl) RunNetRangeTest(f func()) error

test the network randomly

Jump to

Keyboard shortcuts

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