goepoll

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2022 License: MIT Imports: 13 Imported by: 0

README

Go-Epoll!

A libuv-like epoll wrapper.

Inspired by Issue #15735

It's a pity that the issue #15735 was denied.

So I make this.

Example

It's very easy to use it.

tcpConn, err := net.Dial("tcp", "go.dev:80")
onread := func (c *goepoll.Conn) {
    buf := make([]byte, 100)
    n, err := c.Read(buf)
    buf = buf[0:n]
    fmt.Println(string(buf))
}
c := goepoll.NewConn(tcpConn, onread, nil, nil)
events, err := goepoll.New() 
c, err := events.Add(c, goepoll.EVENT_READABLE)
c.Write([]byte("Hello"))

Why?

Because this can avoid the time of awoking a goroutine.

The futex/awoke is slow.

Documentation

Index

Constants

View Source
const (
	DEFAULT_EVENTS_SIZE = 1024
	EPOLLET             = 0x80000000
)

Variables

View Source
var (
	ErrEvents         = fmt.Errorf("invald events")
	ErrConn           = fmt.Errorf("invalid net.conn")
	ErrEventsExist    = fmt.Errorf("the event existed")
	ErrEventsNonExist = fmt.Errorf("the event doesn't exist")
	ErrEpollAdd       = fmt.Errorf("epoll_ctl_add fail")
	ErrEpollMod       = fmt.Errorf("epoll_ctl_mod fail")
	ErrEpollDel       = fmt.Errorf("epoll_ctl_del fail")
)

Functions

This section is empty.

Types

type Conn

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

func NewConn

func NewConn(c net.Conn, onread func(c *Conn), onwrite func(c *Conn), ondisconnect func(c *Conn)) *Conn

func NewConnWithFd added in v0.0.2

func NewConnWithFd(c net.Conn, fd int, onread func(c *Conn), onwrite func(c *Conn), ondisconnect func(c *Conn)) *Conn

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) CouldBeDisconnected added in v0.0.3

func (c *Conn) CouldBeDisconnected() bool

func (*Conn) CouldBeReadable added in v0.0.3

func (c *Conn) CouldBeReadable() bool

protect each R/W goroutine A goroutine is still reading, don't interrupt It happens that a goroutine try to read many times. However, the event will be triggered twice.

func (*Conn) CouldBeWritable added in v0.0.3

func (c *Conn) CouldBeWritable() bool

func (*Conn) Fd

func (c *Conn) Fd() int

func (*Conn) LocalAddr

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

func (*Conn) OnDisconnected

func (c *Conn) OnDisconnected()

func (*Conn) OnReadable

func (c *Conn) OnReadable()

func (*Conn) OnWritable

func (c *Conn) OnWritable()

func (*Conn) Read

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

func (*Conn) RemoteAddr

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

func (*Conn) SetDeadline

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

func (*Conn) SetReadDeadline

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

func (*Conn) SetWriteDeadline

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

func (*Conn) WithOnDisconnected

func (c *Conn) WithOnDisconnected(ondisconnect func(c *Conn))

func (*Conn) WithOnReadable

func (c *Conn) WithOnReadable(onread func(c *Conn))

func (*Conn) WithOnWritable

func (c *Conn) WithOnWritable(onwrite func(c *Conn))

func (*Conn) Write

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

type Epoll

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

func New

func New(events_num ...int) (*Epoll, error)

func (*Epoll) Add

func (e *Epoll) Add(c net.Conn, ev ...EpollEvent) (*Conn, error)

func (*Epoll) Close

func (e *Epoll) Close()

func (*Epoll) Del

func (e *Epoll) Del(c net.Conn) error

func (*Epoll) Mod

func (e *Epoll) Mod(c net.Conn, ev ...EpollEvent) (*Conn, error)

type EpollEvent

type EpollEvent int
const (
	EVENT_READABLE EpollEvent = iota
	EVENT_WRITABLE
	EVENT_DISCONNECTED
	EVENT_EDGE_TRIGGERED
)

type Queue added in v0.0.6

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

func NewQueue added in v0.0.6

func NewQueue(size int) *Queue

func (*Queue) Close added in v0.0.6

func (q *Queue) Close()

func (*Queue) DisconnectSchedule added in v0.0.6

func (q *Queue) DisconnectSchedule(f func())

func (*Queue) ReadSchedule added in v0.0.6

func (q *Queue) ReadSchedule(f func())

func (*Queue) WriteSchedule added in v0.0.6

func (q *Queue) WriteSchedule(f func())

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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