Giter Site home page Giter Site logo

linecode / event.lua Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 5.79 MB

lua rpc module base on libev,support mongo,redis,lua debugger,it aim to build game server easily

Makefile 2.30% Shell 10.44% C 31.78% Roff 3.95% C++ 33.62% M4 0.82% HTML 6.64% CSS 0.11% Objective-C 0.26% Perl 2.46% Assembly 0.05% Python 0.04% Lua 7.47% CMake 0.04% Vim Script 0.03%

event.lua's Introduction

lua rpc module base on libev

a tiny,lightweight rpc module for lua base on libev,easy to use,easy to learn.

listener

see master.lua

connector,coroutine,channel,rpc

see console.lua

mongo

see mongo.lua

redis

see redis.lua

http

see http.lua

udp

see test_kcp_client.lua

kcp

see test_kcp_client.lua

lua script reload

see import

lua debugger

see debugger.lua

async wait for popen process exit

see event.run_process

how to use

listener

  • event.listen

    ip,port,accept_callback,channel_class or nil

    when a new connection coming,accept_callback will be invoke,with arg 1 is listener userdata,arg 2 is the channel obj create by channel_class

connector

  • event.connect

    ip,port,channel_class or nil

    this api must be run in a fork,cause connect op is a call, when connect done,if u specify the channel_class,it will create a channel object by the specify channel_class,otherwise,it will create by default channel class

bind fd

  • event.bind

    fd,channel_class or nil

    bind a exist fd with the channel class,if the channel_class is nil, it will bind by default channel class

dns

  • event.dns

    host

    resove host

httpd

  • http.listen

    ip,port,callback

    start a http server,when a request coming,it will invoke callback with arg 1 is httpd self userdata,arg 2 is request,arg 3 method("POST","GET" and so on),arg 4 url,arg 5 is headers,last is body

request

  • request.reply_header

    key,value

    set reply headers with key and value

  • request.reply

    statu code,reason,body

    reply a httpd request

create timer

  • event.timer

    ti,callback

    create a timer,it will return a timer object,u can cancel with the function timer:cancel

sleep

  • event.sleep

    ti

    this api must run in a fork,cause it is a call.it will wakeup after ti second

create a new coroutine

  • event.fork

    func,...

    the func will run in a new coroutine after a loop with the args ...

channel

lua bind libevent bufferevent

  • channel.read

    num

    read the specify num in bufferevent,if no enough,it will return nil

  • channel.read_line

    read line data in bufferevent,if no line,it will return nil

  • channel.close

    it will close the bufferevent,make sure the buffervent data send out, and the channel.disconnect will be invoke

  • channel.close_immediately

    close the bufferevent immediately ignore the data in buffervent whether send out, the channel.disconnect will not invoke

  • channel.send

    send data to remote,u can inherit channel class and rewrite the send behaviour

  • channel.call

    call data to remote,u can inherit channel class and rewrite the call behaviour

import

lua script reload operation

  • import

    file

    the script can reload after import

  • reload

    file

    reload the specity lua script

  • auto_reload

    it will reload all script which modify after last reload

run httpd server sample

git clone and make,then ./event_tc master to run a simple httpd server

local master_channel = channel:inherit()

function master_channel:disconnect()
    handler.leave(self)
end

local function accept(_,channel)
    handler.enter(channel)
end

local ok = event.listen("0.0.0.0",env.master,accept,master_channel)
if not ok then
    event.error("listen error")
end

event.error(string.format("master listen on:%s",env.master))

for i = 1,env.httpd_max do
  event.fork(function ()
    while true do
      event.run_process("./event_tc httpd")
      event.error("httpd down,try again")
      event.sleep(1)
    end
  end)
end

some useful tool

gdb like lua debugger

only debug script load by import.lua

to do:trigger lua debugger in gdb

debugger(func,file,line)

start a debugger while breakpoint in file@line

show help

image

list source

image

add a breakpoint and delete a break point

image

show traceback and switch frame

image

lua call frame profiler

see profiler.c

image

lua.bt

u can use gdb script lua.bt to print call stack in gdb

image

image

breakout lua dead loop

when a dead loop running,u can kill -10 pid to breakout the deadloop

image

event.lua's People

Contributors

ball32109 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.