evnet

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: MIT Imports: 9 Imported by: 0

README

evnet

a go net.Conn net.Listener implement base on epoll, and thanks @tidwall, evio give me more inspire

Demo

package main

import (
	"context"
	"fmt"
	"net/http"
	"os"
	"os/signal"
	"syscall"

	"github.com/RyouZhang/evnet"
)

type MyHandler struct {
}

func (h *MyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	w.WriteHeader(200)
	w.Write([]byte("hello world"))
}

func main() {
	ctx := context.Background()

	ln, err := evnet.NewTransport(evnet.DefaultOptions()).Listen("tcp", "0.0.0.0:7689")
	if err != nil {
		fmt.Println(err)
		return
	}

	srv := &http.Server{Handler: &MyHandler{}}
	srv.SetKeepAlivesEnabled(true)

	go func() {
		fmt.Println(srv.Serve(ln))
	}()

	shutdown := make(chan os.Signal, 1)
	defer close(shutdown)
	signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)

	<-shutdown
	srv.Shutdown(ctx)
	fmt.Println("finish")
}

And you can use it with Gin... so enjoy it.

Documentation

Index

Constants

View Source
const ET_MODE uint32 = 1 << 31

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Nodelay             bool
	KeepAlive           bool
	KeepAliveInterval   int //sec
	IdleTimeout         int //sec
	GracetAcceptTimeout int //sec
	GraceTimeout        int //sec
	RunloopNum          int
}

func DefaultOptions

func DefaultOptions() Options

type Transport

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

func NewTransport

func NewTransport(opts Options) *Transport

func (*Transport) Listen

func (t *Transport) Listen(network string, addr string) (net.Listener, error)

Jump to

Keyboard shortcuts

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