epoll

package module
v0.0.0-...-b85d43a Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2019 License: BSD-2-Clause Imports: 2 Imported by: 0

README

epoll

Golang Epoll Support - Linux

Getting the library: go get -u github.com/bzip2-9/epoll


Usage:

import (
  "net"
  "bzip2-9/epoll"
  )


func handleConnection (conn *net.Conn, userData interface{}) {

}

func newConnection (conn *net.Conn, userData interface{}) {

    client, _ := conn.AcceptTCP()


}

func main () {
  sockserver, _ := ListenTCP("127.0.0.1:8080",nil)

  ep := epoll.Create(1)

  ep.Add(sockserver,newConnection)

  ....
}

Documentation

Index

Constants

View Source
const (
	// EPOLLIN - data available to read
	EPOLLIN int = unix.EPOLLIN
	// EPOLLOUT - writing is possible
	EPOLLOUT int = unix.EPOLLOUT
	// EPOLLET - Edge Triggered Event
	EPOLLET int = unix.EPOLLET
	// EPOLLPRI - Priority Event
	EPOLLPRI int = unix.EPOLLPRI
	// EPOLLHUP - fd was closed by the other side
	EPOLLHUP int = unix.EPOLLHUP
	// EPOLLONESHOT	- fd is removed from the epoll set after first event is triggered
	EPOLLONESHOT int = unix.EPOLLONESHOT
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Epoll

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

Epoll represents an epoll set

func Create

func Create(nthreads uint) (*Epoll, error)

Create creates new epoll set 0 threads => calling thread will take care of the event loop, no threads, no locks 1 thread => 1 thread is created to handle the event loop > 1 (N) threads => 1 thread is created to handle the event loop, N threads are

will be created to handle events in parallel  (TODO)

func (*Epoll) Add

func (me *Epoll) Add(obj *UserObject, events int)

Add new connection to the epoll set - net.TCPConn

func (*Epoll) Del

func (me *Epoll) Del(obj *UserObject)

Del removes connection (net.TCPConn) from the epoll set

func (*Epoll) Destroy

func (me *Epoll) Destroy()

Destroy the epoll set

func (*Epoll) EventLoopNoThread

func (me *Epoll) EventLoopNoThread()

EventLoopNoThread - event loop used directly by library user to handle events, no threads

type FuncAction

type FuncAction int

FuncAction - value returned by event callback

const (
	// CONTINUE - fd will remain in management
	OK FuncAction = 1
	// STOP - fd should be removed from management
	EXIT FuncAction = 2
)

type UserObject

type UserObject interface {
	GetFD() int
	GetFD0() int
	GetFD1() int
	Ptr() uintptr
	Close()
	Event(uo *UserObject, events uint32) FuncAction // same constants EPOLL*, ORed
}

UserObject - Interface Objects from User must obey

Jump to

Keyboard shortcuts

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