gev: github.com/Allenxuxu/gev Index | Examples | Files | Directories

package gev

import "github.com/Allenxuxu/gev"

Index

Examples

Package Files

everyscheduler.go options.go server.go

type Handler Uses

❖
type Handler interface {
    OnConnect(c *connection.Connection)
    OnMessage(c *connection.Connection, ctx interface{}, data []byte) []byte
    OnClose(c *connection.Connection)
}

Handler Server 注册接口

type Option Uses

❖
type Option func(*Options)

Option ...

func Address Uses

❖
func Address(a string) Option

Address server 监听地址

func IdleTime Uses

❖
func IdleTime(t time.Duration) Option

IdleTime 最大空闲时间(秒)

func Network Uses

❖
func Network(n string) Option

Network [tcp] 暂时只支持tcp

func NumLoops Uses

❖
func NumLoops(n int) Option

NumLoops work eventloop 的数量

func Protocol Uses

❖
func Protocol(p connection.Protocol) Option

Protocol 数据包处理

func ReusePort Uses

❖
func ReusePort(reusePort bool) Option

ReusePort 设置 SO_REUSEPORT

type Options Uses

❖
type Options struct {
    Network   string
    Address   string
    NumLoops  int
    ReusePort bool

    IdleTime time.Duration
    Protocol connection.Protocol
    // contains filtered or unexported fields
}

Options 服务配置

type Server Uses

❖
type Server struct {
    // contains filtered or unexported fields
}

Server gev Server

func NewServer Uses

❖
func NewServer(handler Handler, opts ...Option) (server *Server, err error)

NewServer 创建 Server

func (*Server) Options Uses

❖
func (s *Server) Options() Options

Options 返回 options

func (*Server) RunAfter Uses

❖
func (s *Server) RunAfter(d time.Duration, f func()) *timingwheel.Timer

RunAfter 延时任务

Code:

handler := new(example)

s, err := NewServer(handler,
    Network("tcp"),
    Address(":1833"),
    NumLoops(8),
    ReusePort(true))
if err != nil {
    panic(err)
}

go s.Start()
defer s.Stop()

s.RunAfter(time.Second, func() {
    fmt.Println("RunAfter")
})

time.Sleep(2500 * time.Millisecond)

Output:

RunAfter

func (*Server) RunEvery Uses

❖
func (s *Server) RunEvery(d time.Duration, f func()) *timingwheel.Timer

RunEvery 定时任务

Code:

handler := new(example)

s, err := NewServer(handler,
    Network("tcp"),
    Address(":1833"),
    NumLoops(8),
    ReusePort(true))
if err != nil {
    panic(err)
}

go s.Start()
defer s.Stop()

t := s.RunEvery(time.Second, func() {
    fmt.Println("EveryFunc")
})

time.Sleep(4500 * time.Millisecond)
t.Stop()
time.Sleep(4500 * time.Millisecond)

Output:

EveryFunc
EveryFunc
EveryFunc
EveryFunc

func (*Server) Start Uses

❖
func (s *Server) Start()

Start 启动 Server

func (*Server) Stop Uses

❖
func (s *Server) Stop()

Stop 关闭 Server

Directories

PathSynopsis
benchmarks/client
benchmarks/evio-echo-server
benchmarks/eviop-echo-server
benchmarks/gnet-echo-server
benchmarks/net-echo-server
connection
eventloop
listener
logPackage log is from https://github.com/micro/go-micro/blob/master/util/log/log.go
poller

Package gev imports 10 packages (graph). Updated 2020-04-01. Refresh now. Tools for package owners.