evio

package
Version: v6.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

evio

A fast event-loop networking framework that uses the teleport API layer. (From evio)

It makes direct epoll and kqueue syscalls rather than using the standard Go net package, and works in a similar manner as libuv and libevent.

Feature

  • Fast single-threaded or multithreaded event loop
  • Built-in load balancing options
  • Teleport API
  • Low memory usage
  • Fallback for non-epoll/kqueue operating systems by simulating events with the net package
  • SO_REUSEPORT socket option
  • Support TLS
  • (TODO) Support set connection deadline

Usage

import "github.com/henrylee2cn/teleport/v6/mixer/evio"

Test
package evio_test

import (
	"testing"
	"time"

	tp "github.com/henrylee2cn/teleport/v6"
	"github.com/henrylee2cn/teleport/v6/mixer/evio"
)

func Test(t *testing.T) {
	// server
	srv := evio.NewServer(1, tp.PeerConfig{ListenPort: 9090})
	// use TLS
	srv.SetTLSConfig(tp.GenerateTLSConfigForServer())
	srv.RouteCall(new(Home))
	go srv.ListenAndServe()
	time.Sleep(1e9)

	// client
	cli := evio.NewClient(tp.PeerConfig{})
	// use TLS
	cli.SetTLSConfig(tp.GenerateTLSConfigForClient())
	cli.RoutePush(new(Push))
	sess, stat := cli.Dial(":9090")
	if !stat.OK() {
		t.Fatal(stat)
	}
	var result interface{}
	stat = sess.Call("/home/test",
		map[string]string{
			"author": "henrylee2cn",
		},
		&result,
		tp.WithAddMeta("peer_id", "110"),
	).Status()
	if !stat.OK() {
		t.Fatal(stat)
	}
	t.Logf("result:%v", result)
	time.Sleep(2e9)
}

type Home struct {
	tp.CallCtx
}

func (h *Home) Test(arg *map[string]string) (map[string]interface{}, *tp.Status) {
	h.Session().Push("/push/test", map[string]string{
		"your_id": string(h.PeekMeta("peer_id")),
	})
	return map[string]interface{}{
		"arg": *arg,
	}, nil
}

type Push struct {
	tp.PushCtx
}

func (p *Push) Test(arg *map[string]string) *tp.Status {
	tp.Infof("receive push(%s):\narg: %#v\n", p.IP(), arg)
	return nil
}

test command:

go test -v -run=Test

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(cfg tp.PeerConfig, globalLeftPlugin ...tp.Plugin) tp.Peer

NewClient creates a evio client, equivalent to tp.NewPeer.

Types

type Server

type Server struct {
	tp.Peer
	// contains filtered or unexported fields
}

Server a evio server

func NewServer

func NewServer(loops int, cfg tp.PeerConfig, globalLeftPlugin ...tp.Plugin) *Server

NewServer creates a evio server.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe(protoFunc ...tp.ProtoFunc) error

ListenAndServe turns on the listening service.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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