netreactors

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 15 Imported by: 0

Documentation ¶

Index ¶

Constants ¶

View Source
const (
	PrependSize    = 8
	BufferInitSize = 1024
)
View Source
const (
	MaxRetryTime  = 30 * time.Second
	InitRetryTime = 500 * time.Millisecond
)
View Source
const (
	InitEventListSize = 16
)

Variables ¶

View Source
var AtomicNumber int64 = 0
View Source
var Dlog = &Log{
	IsOpenDebugLog: false,
}

Functions ¶

This section is empty.

Types ¶

type Acceptor ¶

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

func NewAcceptor ¶

func NewAcceptor(loop *EventLoop, listenAddr *netip.AddrPort, reusePort bool) (ac *Acceptor)

func (*Acceptor) Listen ¶

func (a *Acceptor) Listen()

func (*Acceptor) Listening ¶

func (a *Acceptor) Listening() bool

func (*Acceptor) SetAcceptorNewConnectionCallback ¶

func (a *Acceptor) SetAcceptorNewConnectionCallback(cb AcceptorNewConnectionCallback)

type AcceptorNewConnectionCallback ¶

type AcceptorNewConnectionCallback func(int, *netip.AddrPort)

type Buffer ¶

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

func NewBuffer ¶

func NewBuffer() *Buffer

func (*Buffer) Append ¶

func (b *Buffer) Append(data []byte)

func (*Buffer) Peek ¶

func (b *Buffer) Peek() *byte

func (*Buffer) Prepend ¶

func (b *Buffer) Prepend(data []byte)

func (*Buffer) PrependBytes ¶

func (b *Buffer) PrependBytes() int

func (*Buffer) ReadFd ¶

func (b *Buffer) ReadFd(fd int, saveErrno *error) int

func (*Buffer) ReadableBytes ¶

func (b *Buffer) ReadableBytes() int

func (*Buffer) Retrieve ¶

func (b *Buffer) Retrieve(size int)

func (*Buffer) RetrieveAll ¶

func (b *Buffer) RetrieveAll()

func (*Buffer) RetrieveAllString ¶

func (b *Buffer) RetrieveAllString() []byte

func (*Buffer) RetrieveAsString ¶

func (b *Buffer) RetrieveAsString(size int) []byte

func (*Buffer) WriteableBytes ¶

func (b *Buffer) WriteableBytes() int

type Channel ¶

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

func NewChannel ¶

func NewChannel(loop *EventLoop, fdArg int32) *Channel

func (*Channel) DisableAll ¶

func (c *Channel) DisableAll()

func (*Channel) DisableReading ¶

func (c *Channel) DisableReading()

func (*Channel) DisableWriting ¶

func (c *Channel) DisableWriting()

func (*Channel) EnableReading ¶

func (c *Channel) EnableReading()

func (*Channel) EnableWriting ¶

func (c *Channel) EnableWriting()

func (*Channel) Events ¶

func (c *Channel) Events() int16

func (*Channel) Fd ¶

func (c *Channel) Fd() int32

func (*Channel) HandleEvent ¶

func (c *Channel) HandleEvent(time time.Time)

func (*Channel) Index ¶

func (c *Channel) Index() int

func (*Channel) IsNoneEvent ¶

func (c *Channel) IsNoneEvent() bool

func (*Channel) IsReading ¶

func (c *Channel) IsReading() bool

func (*Channel) IsWriting ¶

func (c *Channel) IsWriting() bool

func (*Channel) OwnerLoop ¶

func (c *Channel) OwnerLoop() *EventLoop

func (*Channel) Remove ¶

func (c *Channel) Remove()

func (*Channel) SetCloseCallback ¶

func (c *Channel) SetCloseCallback(cb EventCallback)

func (*Channel) SetErrorCallback ¶

func (c *Channel) SetErrorCallback(cb EventCallback)

func (*Channel) SetIndex ¶

func (c *Channel) SetIndex(idx int)

func (*Channel) SetReadCallback ¶

func (c *Channel) SetReadCallback(cb ReadEventCallback)

func (*Channel) SetRevents ¶

func (c *Channel) SetRevents(revt int16)

func (*Channel) SetWriteCallback ¶

func (c *Channel) SetWriteCallback(cb EventCallback)

type CloseCallback ¶

type CloseCallback func(*TcpConnection)

type ConnectionCallback ¶

type ConnectionCallback func(*TcpConnection)

TcpConnection

type Connector ¶

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

func NewConnector ¶

func NewConnector(loop *EventLoop, addr *netip.AddrPort) *Connector

func (*Connector) Restart ¶

func (c *Connector) Restart()

func (*Connector) SetConnectorNewConnectionCallback ¶

func (c *Connector) SetConnectorNewConnectionCallback(cb ConnectorNewConnectionCallback)

func (*Connector) Start ¶

func (c *Connector) Start()

func (*Connector) Stop ¶

func (c *Connector) Stop()

type ConnectorNewConnectionCallback ¶

type ConnectorNewConnectionCallback func(int)

type EpollPoller ¶

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

func NewEpollPoller ¶

func NewEpollPoller(loop *EventLoop) (ep *EpollPoller)

func (*EpollPoller) AssertInLoopGoroutine ¶

func (e *EpollPoller) AssertInLoopGoroutine()

func (*EpollPoller) Poll ¶

func (e *EpollPoller) Poll(timeoutMs int, activeChannels *[]*Channel) time.Time

func (*EpollPoller) RemoveChannel ¶

func (e *EpollPoller) RemoveChannel(channel *Channel)

func (*EpollPoller) UpdateChannel ¶

func (e *EpollPoller) UpdateChannel(channel *Channel)

type EventCallback ¶

type EventCallback func()

type EventLoop ¶

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

func NewEventLoop ¶

func NewEventLoop() (el *EventLoop)

func (*EventLoop) AssertInLoopGoroutine ¶

func (loop *EventLoop) AssertInLoopGoroutine()

func (*EventLoop) Cancel ¶

func (loop *EventLoop) Cancel(timerid TimerId)

func (*EventLoop) DoPendingFunctors ¶

func (loop *EventLoop) DoPendingFunctors()

execute callback in queue

func (*EventLoop) HandleRead ¶

func (loop *EventLoop) HandleRead(t time.Time)

wake up

func (*EventLoop) IsInLoopGoroutine ¶

func (loop *EventLoop) IsInLoopGoroutine() bool

func (*EventLoop) Loop ¶

func (loop *EventLoop) Loop()

Loop

func (*EventLoop) QueueInLoop ¶

func (loop *EventLoop) QueueInLoop(cb Functor)

functor queue

func (*EventLoop) Quit ¶

func (loop *EventLoop) Quit()

func (*EventLoop) RemoveChannel ¶

func (loop *EventLoop) RemoveChannel(c *Channel)

func (*EventLoop) RunAfter ¶

func (loop *EventLoop) RunAfter(duration time.Duration, cb TimerCallback) TimerId

callback run 'delay' from now

func (*EventLoop) RunAt ¶

func (loop *EventLoop) RunAt(t time.Time, cb TimerCallback) TimerId

callback run at 't'

func (*EventLoop) RunEvery ¶

func (loop *EventLoop) RunEvery(interval float64, cb TimerCallback) TimerId

callback run every 'interval'

func (*EventLoop) RunInLoop ¶

func (loop *EventLoop) RunInLoop(cb Functor)

make sure run in loop

func (*EventLoop) UpdateChannel ¶

func (loop *EventLoop) UpdateChannel(c *Channel)

func (*EventLoop) Wakeup ¶

func (loop *EventLoop) Wakeup()

type EventLoopGoroutine ¶

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

func NewEventLoopGoroutine ¶

func NewEventLoopGoroutine(cb GoroutineCallback) (elg *EventLoopGoroutine)

func (*EventLoopGoroutine) StartLoop ¶

func (elg *EventLoopGoroutine) StartLoop() *EventLoop

type EventLoopGoroutinePool ¶

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

func NewEventLoopGoroutinePool ¶

func NewEventLoopGoroutinePool(baseLoop *EventLoop) *EventLoopGoroutinePool

func (*EventLoopGoroutinePool) GetNextLoop ¶

func (ep *EventLoopGoroutinePool) GetNextLoop() (loop *EventLoop)

func (*EventLoopGoroutinePool) IsStarted ¶

func (ep *EventLoopGoroutinePool) IsStarted() bool

func (*EventLoopGoroutinePool) SetGoroutineNum ¶

func (ep *EventLoopGoroutinePool) SetGoroutineNum(num int)

func (*EventLoopGoroutinePool) Start ¶

type Functor ¶

type Functor func()

type GoroutineCallback ¶

type GoroutineCallback func(*EventLoop)

type HighWaterMarkCallback ¶

type HighWaterMarkCallback func(*TcpConnection, int)

type Log ¶

type Log struct {
	IsOpenDebugLog bool
}

func (*Log) Printf ¶

func (d *Log) Printf(format string, v ...any)

func (*Log) TurnOffLog ¶

func (d *Log) TurnOffLog()

func (*Log) TurnOnLog ¶

func (d *Log) TurnOnLog()

type MessageCallback ¶

type MessageCallback func(*TcpConnection, *Buffer, time.Time)

type PollPoller ¶

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

func NewPollPoller ¶

func NewPollPoller(loop *EventLoop) *PollPoller

func (*PollPoller) AssertInLoopGoroutine ¶

func (p *PollPoller) AssertInLoopGoroutine()

func (*PollPoller) Poll ¶

func (p *PollPoller) Poll(timeoutMs int, activeChannels *[]*Channel) time.Time

func (*PollPoller) RemoveChannel ¶

func (p *PollPoller) RemoveChannel(channel *Channel)

func (*PollPoller) UpdateChannel ¶

func (p *PollPoller) UpdateChannel(channel *Channel)

type Poller ¶

type Poller interface {
	Poll(timeoutMs int, activeChannels *[]*Channel) time.Time
	UpdateChannel(channel *Channel)
	RemoveChannel(channel *Channel)
	// contains filtered or unexported methods
}

func NewDefaultPoller ¶

func NewDefaultPoller(loop *EventLoop) Poller

type ReadEventCallback ¶

type ReadEventCallback func(time.Time)

type TcpClient ¶

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

func NewTcpClient ¶

func NewTcpClient(loop *EventLoop, serverAddr *netip.AddrPort, name string) (client *TcpClient)

func (*TcpClient) Connect ¶

func (tc *TcpClient) Connect()

func (*TcpClient) Disconnect ¶

func (tc *TcpClient) Disconnect()

func (*TcpClient) EnableRetry ¶

func (tc *TcpClient) EnableRetry()

func (*TcpClient) GetLoop ¶

func (tc *TcpClient) GetLoop() *EventLoop

func (*TcpClient) IsRetry ¶

func (tc *TcpClient) IsRetry() bool

func (*TcpClient) Name ¶

func (tc *TcpClient) Name() string

func (*TcpClient) SetConnectionCallback ¶

func (tc *TcpClient) SetConnectionCallback(cb ConnectionCallback)

func (*TcpClient) SetMessageCallback ¶

func (tc *TcpClient) SetMessageCallback(cb MessageCallback)

func (*TcpClient) SetWriteCompleteCallback ¶

func (tc *TcpClient) SetWriteCompleteCallback(cb WriteCompleteCallback)

func (*TcpClient) Stop ¶

func (tc *TcpClient) Stop()

type TcpConnection ¶

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

func NewTcpConnection ¶

func NewTcpConnection(loop *EventLoop, name string, fd int, localAddr *netip.AddrPort, peerAddr *netip.AddrPort) (conn *TcpConnection)

************************* public: *************************

func (*TcpConnection) BindWriteCompleteCallback ¶

func (tc *TcpConnection) BindWriteCompleteCallback() func()

func (*TcpConnection) ConnectDestroyed ¶

func (tc *TcpConnection) ConnectDestroyed()

called when TcpServer has removed me from it's map

func (*TcpConnection) ConnectEstablished ¶

func (tc *TcpConnection) ConnectEstablished()

called when TcpServer accepts a new connection

func (*TcpConnection) Connected ¶

func (tc *TcpConnection) Connected() bool

func (*TcpConnection) ForceClose ¶ added in v1.0.1

func (tc *TcpConnection) ForceClose()

ForceClose: force close connetion

func (*TcpConnection) GetLoop ¶

func (tc *TcpConnection) GetLoop() *EventLoop

func (*TcpConnection) InBuffer ¶

func (tc *TcpConnection) InBuffer() *Buffer

func (*TcpConnection) LocalAddr ¶

func (tc *TcpConnection) LocalAddr() *netip.AddrPort

func (*TcpConnection) Name ¶

func (tc *TcpConnection) Name() string

func (*TcpConnection) OutBuffer ¶

func (tc *TcpConnection) OutBuffer() *Buffer

func (*TcpConnection) PeerAddr ¶

func (tc *TcpConnection) PeerAddr() *netip.AddrPort

func (*TcpConnection) Send ¶

func (tc *TcpConnection) Send(message []byte)

send the 'message'

func (*TcpConnection) SendFromBuffer ¶

func (tc *TcpConnection) SendFromBuffer(buf *Buffer)

send the data from 'buf'

func (*TcpConnection) SetCloseCallback ¶

func (tc *TcpConnection) SetCloseCallback(cb CloseCallback)

func (*TcpConnection) SetConnectionCallback ¶

func (tc *TcpConnection) SetConnectionCallback(cb ConnectionCallback)

set callback

func (*TcpConnection) SetHighWaterMarkCallback ¶

func (tc *TcpConnection) SetHighWaterMarkCallback(cb HighWaterMarkCallback)

func (*TcpConnection) SetMessageCallback ¶

func (tc *TcpConnection) SetMessageCallback(cb MessageCallback)

func (*TcpConnection) SetTcpNoDelay ¶

func (tc *TcpConnection) SetTcpNoDelay(on bool)

func (*TcpConnection) SetWriteCompleteCallback ¶

func (tc *TcpConnection) SetWriteCompleteCallback(cb WriteCompleteCallback)

func (*TcpConnection) Shutdown ¶

func (tc *TcpConnection) Shutdown()

Shutdown: shutDown write side

type TcpServer ¶

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

func NewTcpServer ¶

func NewTcpServer(loop *EventLoop, addr *netip.AddrPort, name string) (server *TcpServer)

func (*TcpServer) SetConnectionCallback ¶

func (t *TcpServer) SetConnectionCallback(cb ConnectionCallback)

func (*TcpServer) SetGoroutineCallback ¶

func (t *TcpServer) SetGoroutineCallback(cb GoroutineCallback)

func (*TcpServer) SetGoroutineNum ¶

func (t *TcpServer) SetGoroutineNum(num int)

func (*TcpServer) SetMessageCallback ¶

func (t *TcpServer) SetMessageCallback(cb MessageCallback)

func (*TcpServer) SetWriteCompleteCallback ¶

func (t *TcpServer) SetWriteCompleteCallback(cb WriteCompleteCallback)

func (*TcpServer) Start ¶

func (t *TcpServer) Start()

type TimeEntry ¶

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

type Timer ¶

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

func NewTimer ¶

func NewTimer(cb TimerCallback, when time.Time, interval float64) *Timer

func (*Timer) Expiration ¶

func (t *Timer) Expiration() time.Time

func (*Timer) Repeat ¶

func (t *Timer) Repeat() bool

func (*Timer) Restart ¶

func (t *Timer) Restart(now time.Time)

func (*Timer) Run ¶

func (t *Timer) Run()

func (*Timer) Sequence ¶

func (t *Timer) Sequence() int64

type TimerCallback ¶

type TimerCallback func()

type TimerId ¶

type TimerId struct {
	Timer_    *Timer
	Sequence_ int64
}

func NewTimerId ¶

func NewTimerId(timer *Timer, seq int64) TimerId

type TimerList ¶

type TimerList []TimeEntry

func (TimerList) Len ¶

func (t TimerList) Len() int

implement the heap.Interface: implement the sort.Interface

func (TimerList) Less ¶

func (t TimerList) Less(i, j int) bool

func (*TimerList) Pop ¶

func (t *TimerList) Pop() any

func (*TimerList) Push ¶

func (t *TimerList) Push(x any)

implement Push and Pop

func (TimerList) Swap ¶

func (t TimerList) Swap(i, j int)

type TimerQueue ¶

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

fix: more high performance

func NewTimerQueue ¶

func NewTimerQueue(loop *EventLoop) (tq *TimerQueue)

func (*TimerQueue) AddTimer ¶

func (tq *TimerQueue) AddTimer(cb TimerCallback, when time.Time, interval float64) TimerId

func (*TimerQueue) Cancel ¶

func (tq *TimerQueue) Cancel(timerid TimerId)

func (*TimerQueue) HandleRead ¶

func (tq *TimerQueue) HandleRead(t time.Time)

called when timer alarms

type WriteCompleteCallback ¶

type WriteCompleteCallback func(*TcpConnection)

Directories ¶

Path Synopsis
base
benchmark

Jump to

Keyboard shortcuts

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