├── README.md ├── config └── gs_config.lua ├── daobiao └── gamedata │ └── data.lua ├── gs_run.sh ├── log └── gs.log ├── lualib └── base │ ├── argparse.lua │ ├── baseobj.lua │ ├── defines.lua │ ├── hook.lua │ ├── interactive.lua │ ├── loadshare.lua │ ├── net.lua │ ├── netfind.lua │ ├── preload.lua │ ├── protobuf.lua │ ├── reload.lua │ ├── savemgr.lua │ ├── share.lua │ ├── stringop.lua │ ├── tableop.lua │ ├── texthandle.lua │ ├── timeop.lua │ └── timer.lua ├── proto ├── base.proto ├── client │ ├── item.proto │ └── login.proto ├── netdefines.lua ├── proto.pb └── server │ ├── iteam.proto │ ├── login.proto │ └── player.proto ├── service ├── dictator │ ├── dictatorcmd.lua │ ├── dictatorobj.lua │ ├── global.lua │ ├── logiccmd │ │ ├── common.lua │ │ └── init.lua │ └── main.lua ├── gamedb │ ├── gamedbobj.lua │ ├── global.lua │ ├── logiccmd │ │ ├── accountdb.lua │ │ ├── idsupplydb.lua │ │ ├── init.lua │ │ ├── playerdb.lua │ │ └── testdb.lua │ └── main.lua ├── gs_launcher.lua ├── idsupply │ ├── global.lua │ ├── idmgr.lua │ ├── logiccmd │ │ ├── common.lua │ │ └── init.lua │ └── main.lua ├── login │ ├── defines.lua │ ├── gateobj.lua │ ├── global.lua │ ├── logiccmd │ │ ├── common.lua │ │ └── init.lua │ ├── main.lua │ ├── netcmd │ │ ├── init.lua │ │ └── login.lua │ └── textcmd │ │ └── init.lua ├── share │ ├── logiccmd │ │ ├── common.lua │ │ └── init.lua │ └── main.lua ├── war │ ├── actionmgr.lua │ ├── campobj.lua │ ├── global.lua │ ├── logiccmd │ │ ├── init.lua │ │ └── war.lua │ ├── main.lua │ ├── perform │ │ ├── pfmgr.lua │ │ └── pfobj.lua │ ├── warmgr.lua │ ├── warobj.lua │ └── warrior │ │ ├── npcwarrior.lua │ │ ├── playerwarrior.lua │ │ ├── summonwarrior.lua │ │ └── warrior.lua └── world │ ├── attrblock.lua │ ├── connection.lua │ ├── global.lua │ ├── item │ ├── itembase.lua │ ├── itemmgr.lua │ ├── other │ │ └── i10001.lua │ └── virtual │ │ ├── i1001.lua │ │ └── virtualbase.lua │ ├── logiccmd │ ├── common.lua │ ├── init.lua │ ├── login.lua │ └── war.lua │ ├── main.lua │ ├── netcmd │ ├── init.lua │ ├── item.lua │ └── war.lua │ ├── npc │ └── npcmgr.lua │ ├── player │ ├── ctrl │ │ ├── active.lua │ │ ├── base.lua │ │ ├── init.lua │ │ ├── item.lua │ │ ├── skill.lua │ │ └── time.lua │ └── playerobj.lua │ ├── skill │ ├── passive │ │ └── passivebase.lua │ ├── positive │ │ └── positivebase.lua │ ├── skillbase.lua │ └── skillmgr.lua │ ├── timeblock.lua │ ├── war │ ├── warmgr.lua │ └── warobj.lua │ └── world.lua ├── shell ├── format_proto.py ├── gs_kill.sh ├── gs_run.sh └── make_proto.sh ├── skynet ├── .gitignore ├── .gitmodules ├── 3rd │ ├── jemalloc │ │ ├── .appveyor.yml │ │ ├── .autom4te.cfg │ │ ├── .gitattributes │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── COPYING │ │ ├── ChangeLog │ │ ├── INSTALL.md │ │ ├── Makefile.in │ │ ├── README │ │ ├── autogen.sh │ │ ├── bin │ │ │ ├── jemalloc-config.in │ │ │ ├── jemalloc.sh.in │ │ │ └── jeprof.in │ │ ├── build-aux │ │ │ ├── config.guess │ │ │ ├── config.sub │ │ │ └── install-sh │ │ ├── config.stamp.in │ │ ├── configure.ac │ │ ├── doc │ │ │ ├── html.xsl.in │ │ │ ├── jemalloc.xml.in │ │ │ ├── manpages.xsl.in │ │ │ └── stylesheet.xsl │ │ ├── include │ │ │ ├── jemalloc │ │ │ │ ├── internal │ │ │ │ │ ├── arena_externs.h │ │ │ │ │ ├── arena_inlines_a.h │ │ │ │ │ ├── arena_inlines_b.h │ │ │ │ │ ├── arena_stats.h │ │ │ │ │ ├── arena_structs_a.h │ │ │ │ │ ├── arena_structs_b.h │ │ │ │ │ ├── arena_types.h │ │ │ │ │ ├── assert.h │ │ │ │ │ ├── atomic.h │ │ │ │ │ ├── atomic_c11.h │ │ │ │ │ ├── atomic_gcc_atomic.h │ │ │ │ │ ├── atomic_gcc_sync.h │ │ │ │ │ ├── atomic_msvc.h │ │ │ │ │ ├── background_thread_externs.h │ │ │ │ │ ├── background_thread_inlines.h │ │ │ │ │ ├── background_thread_structs.h │ │ │ │ │ ├── base_externs.h │ │ │ │ │ ├── base_inlines.h │ │ │ │ │ ├── base_structs.h │ │ │ │ │ ├── base_types.h │ │ │ │ │ ├── bin.h │ │ │ │ │ ├── bin_stats.h │ │ │ │ │ ├── bit_util.h │ │ │ │ │ ├── bitmap.h │ │ │ │ │ ├── cache_bin.h │ │ │ │ │ ├── ckh.h │ │ │ │ │ ├── ctl.h │ │ │ │ │ ├── div.h │ │ │ │ │ ├── extent_dss.h │ │ │ │ │ ├── extent_externs.h │ │ │ │ │ ├── extent_inlines.h │ │ │ │ │ ├── extent_mmap.h │ │ │ │ │ ├── extent_structs.h │ │ │ │ │ ├── extent_types.h │ │ │ │ │ ├── hash.h │ │ │ │ │ ├── hooks.h │ │ │ │ │ ├── jemalloc_internal_decls.h │ │ │ │ │ ├── jemalloc_internal_defs.h.in │ │ │ │ │ ├── jemalloc_internal_externs.h │ │ │ │ │ ├── jemalloc_internal_includes.h │ │ │ │ │ ├── jemalloc_internal_inlines_a.h │ │ │ │ │ ├── jemalloc_internal_inlines_b.h │ │ │ │ │ ├── jemalloc_internal_inlines_c.h │ │ │ │ │ ├── jemalloc_internal_macros.h │ │ │ │ │ ├── jemalloc_internal_types.h │ │ │ │ │ ├── jemalloc_preamble.h.in │ │ │ │ │ ├── large_externs.h │ │ │ │ │ ├── log.h │ │ │ │ │ ├── malloc_io.h │ │ │ │ │ ├── mutex.h │ │ │ │ │ ├── mutex_pool.h │ │ │ │ │ ├── mutex_prof.h │ │ │ │ │ ├── nstime.h │ │ │ │ │ ├── pages.h │ │ │ │ │ ├── ph.h │ │ │ │ │ ├── private_namespace.sh │ │ │ │ │ ├── private_symbols.sh │ │ │ │ │ ├── prng.h │ │ │ │ │ ├── prof_externs.h │ │ │ │ │ ├── prof_inlines_a.h │ │ │ │ │ ├── prof_inlines_b.h │ │ │ │ │ ├── prof_structs.h │ │ │ │ │ ├── prof_types.h │ │ │ │ │ ├── public_namespace.sh │ │ │ │ │ ├── public_unnamespace.sh │ │ │ │ │ ├── ql.h │ │ │ │ │ ├── qr.h │ │ │ │ │ ├── rb.h │ │ │ │ │ ├── rtree.h │ │ │ │ │ ├── rtree_tsd.h │ │ │ │ │ ├── size_classes.sh │ │ │ │ │ ├── smoothstep.h │ │ │ │ │ ├── smoothstep.sh │ │ │ │ │ ├── spin.h │ │ │ │ │ ├── stats.h │ │ │ │ │ ├── sz.h │ │ │ │ │ ├── tcache_externs.h │ │ │ │ │ ├── tcache_inlines.h │ │ │ │ │ ├── tcache_structs.h │ │ │ │ │ ├── tcache_types.h │ │ │ │ │ ├── ticker.h │ │ │ │ │ ├── tsd.h │ │ │ │ │ ├── tsd_generic.h │ │ │ │ │ ├── tsd_malloc_thread_cleanup.h │ │ │ │ │ ├── tsd_tls.h │ │ │ │ │ ├── tsd_types.h │ │ │ │ │ ├── tsd_win.h │ │ │ │ │ ├── util.h │ │ │ │ │ └── witness.h │ │ │ │ ├── jemalloc.sh │ │ │ │ ├── jemalloc_defs.h.in │ │ │ │ ├── jemalloc_macros.h.in │ │ │ │ ├── jemalloc_mangle.sh │ │ │ │ ├── jemalloc_protos.h.in │ │ │ │ ├── jemalloc_rename.sh │ │ │ │ └── jemalloc_typedefs.h.in │ │ │ └── msvc_compat │ │ │ │ ├── C99 │ │ │ │ ├── stdbool.h │ │ │ │ └── stdint.h │ │ │ │ ├── strings.h │ │ │ │ └── windows_extra.h │ │ ├── jemalloc.pc.in │ │ ├── m4 │ │ │ └── ax_cxx_compile_stdcxx.m4 │ │ ├── msvc │ │ │ ├── ReadMe.txt │ │ │ ├── jemalloc_vc2015.sln │ │ │ ├── jemalloc_vc2017.sln │ │ │ ├── projects │ │ │ │ ├── vc2015 │ │ │ │ │ ├── jemalloc │ │ │ │ │ │ ├── jemalloc.vcxproj │ │ │ │ │ │ └── jemalloc.vcxproj.filters │ │ │ │ │ └── test_threads │ │ │ │ │ │ ├── test_threads.vcxproj │ │ │ │ │ │ └── test_threads.vcxproj.filters │ │ │ │ └── vc2017 │ │ │ │ │ ├── jemalloc │ │ │ │ │ ├── jemalloc.vcxproj │ │ │ │ │ └── jemalloc.vcxproj.filters │ │ │ │ │ └── test_threads │ │ │ │ │ ├── test_threads.vcxproj │ │ │ │ │ └── test_threads.vcxproj.filters │ │ │ └── test_threads │ │ │ │ ├── test_threads.cpp │ │ │ │ ├── test_threads.h │ │ │ │ └── test_threads_main.cpp │ │ ├── run_tests.sh │ │ ├── scripts │ │ │ ├── gen_run_tests.py │ │ │ └── gen_travis.py │ │ ├── src │ │ │ ├── arena.c │ │ │ ├── background_thread.c │ │ │ ├── base.c │ │ │ ├── bin.c │ │ │ ├── bitmap.c │ │ │ ├── ckh.c │ │ │ ├── ctl.c │ │ │ ├── div.c │ │ │ ├── extent.c │ │ │ ├── extent_dss.c │ │ │ ├── extent_mmap.c │ │ │ ├── hash.c │ │ │ ├── hooks.c │ │ │ ├── jemalloc.c │ │ │ ├── jemalloc_cpp.cpp │ │ │ ├── large.c │ │ │ ├── log.c │ │ │ ├── malloc_io.c │ │ │ ├── mutex.c │ │ │ ├── mutex_pool.c │ │ │ ├── nstime.c │ │ │ ├── pages.c │ │ │ ├── prng.c │ │ │ ├── prof.c │ │ │ ├── rtree.c │ │ │ ├── stats.c │ │ │ ├── sz.c │ │ │ ├── tcache.c │ │ │ ├── ticker.c │ │ │ ├── tsd.c │ │ │ ├── witness.c │ │ │ └── zone.c │ │ └── test │ │ │ ├── include │ │ │ └── test │ │ │ │ ├── SFMT-alti.h │ │ │ │ ├── SFMT-params.h │ │ │ │ ├── SFMT-params11213.h │ │ │ │ ├── SFMT-params1279.h │ │ │ │ ├── SFMT-params132049.h │ │ │ │ ├── SFMT-params19937.h │ │ │ │ ├── SFMT-params216091.h │ │ │ │ ├── SFMT-params2281.h │ │ │ │ ├── SFMT-params4253.h │ │ │ │ ├── SFMT-params44497.h │ │ │ │ ├── SFMT-params607.h │ │ │ │ ├── SFMT-params86243.h │ │ │ │ ├── SFMT-sse2.h │ │ │ │ ├── SFMT.h │ │ │ │ ├── btalloc.h │ │ │ │ ├── extent_hooks.h │ │ │ │ ├── jemalloc_test.h.in │ │ │ │ ├── jemalloc_test_defs.h.in │ │ │ │ ├── math.h │ │ │ │ ├── mq.h │ │ │ │ ├── mtx.h │ │ │ │ ├── test.h │ │ │ │ ├── thd.h │ │ │ │ └── timer.h │ │ │ ├── integration │ │ │ ├── MALLOCX_ARENA.c │ │ │ ├── aligned_alloc.c │ │ │ ├── allocated.c │ │ │ ├── extent.c │ │ │ ├── extent.sh │ │ │ ├── mallocx.c │ │ │ ├── mallocx.sh │ │ │ ├── overflow.c │ │ │ ├── posix_memalign.c │ │ │ ├── rallocx.c │ │ │ ├── sdallocx.c │ │ │ ├── thread_arena.c │ │ │ ├── thread_tcache_enabled.c │ │ │ ├── xallocx.c │ │ │ └── xallocx.sh │ │ │ ├── src │ │ │ ├── SFMT.c │ │ │ ├── btalloc.c │ │ │ ├── btalloc_0.c │ │ │ ├── btalloc_1.c │ │ │ ├── math.c │ │ │ ├── mq.c │ │ │ ├── mtx.c │ │ │ ├── test.c │ │ │ ├── thd.c │ │ │ └── timer.c │ │ │ ├── stress │ │ │ └── microbench.c │ │ │ ├── test.sh.in │ │ │ └── unit │ │ │ ├── SFMT.c │ │ │ ├── a0.c │ │ │ ├── arena_reset.c │ │ │ ├── arena_reset_prof.c │ │ │ ├── arena_reset_prof.sh │ │ │ ├── atomic.c │ │ │ ├── background_thread.c │ │ │ ├── background_thread_enable.c │ │ │ ├── base.c │ │ │ ├── bit_util.c │ │ │ ├── bitmap.c │ │ │ ├── ckh.c │ │ │ ├── decay.c │ │ │ ├── decay.sh │ │ │ ├── div.c │ │ │ ├── extent_quantize.c │ │ │ ├── fork.c │ │ │ ├── hash.c │ │ │ ├── hooks.c │ │ │ ├── junk.c │ │ │ ├── junk.sh │ │ │ ├── junk_alloc.c │ │ │ ├── junk_alloc.sh │ │ │ ├── junk_free.c │ │ │ ├── junk_free.sh │ │ │ ├── log.c │ │ │ ├── mallctl.c │ │ │ ├── malloc_io.c │ │ │ ├── math.c │ │ │ ├── mq.c │ │ │ ├── mtx.c │ │ │ ├── nstime.c │ │ │ ├── pack.c │ │ │ ├── pack.sh │ │ │ ├── pages.c │ │ │ ├── ph.c │ │ │ ├── prng.c │ │ │ ├── prof_accum.c │ │ │ ├── prof_accum.sh │ │ │ ├── prof_active.c │ │ │ ├── prof_active.sh │ │ │ ├── prof_gdump.c │ │ │ ├── prof_gdump.sh │ │ │ ├── prof_idump.c │ │ │ ├── prof_idump.sh │ │ │ ├── prof_reset.c │ │ │ ├── prof_reset.sh │ │ │ ├── prof_tctx.c │ │ │ ├── prof_tctx.sh │ │ │ ├── prof_thread_name.c │ │ │ ├── prof_thread_name.sh │ │ │ ├── ql.c │ │ │ ├── qr.c │ │ │ ├── rb.c │ │ │ ├── retained.c │ │ │ ├── rtree.c │ │ │ ├── size_classes.c │ │ │ ├── slab.c │ │ │ ├── smoothstep.c │ │ │ ├── spin.c │ │ │ ├── stats.c │ │ │ ├── stats_print.c │ │ │ ├── ticker.c │ │ │ ├── tsd.c │ │ │ ├── witness.c │ │ │ ├── zero.c │ │ │ └── zero.sh │ ├── lpeg │ │ ├── HISTORY │ │ ├── lpcap.c │ │ ├── lpcap.h │ │ ├── lpcode.c │ │ ├── lpcode.h │ │ ├── lpeg-128.gif │ │ ├── lpeg.html │ │ ├── lpprint.c │ │ ├── lpprint.h │ │ ├── lptree.c │ │ ├── lptree.h │ │ ├── lptypes.h │ │ ├── lpvm.c │ │ ├── lpvm.h │ │ ├── makefile │ │ ├── re.html │ │ ├── re.lua │ │ └── test.lua │ ├── lua-md5 │ │ ├── README │ │ ├── compat-5.2.c │ │ ├── compat-5.2.h │ │ ├── md5.c │ │ ├── md5.h │ │ └── md5lib.c │ └── lua │ │ ├── Makefile │ │ ├── README │ │ ├── lapi.c │ │ ├── lapi.h │ │ ├── lauxlib.c │ │ ├── lauxlib.h │ │ ├── lbaselib.c │ │ ├── lbitlib.c │ │ ├── lcode.c │ │ ├── lcode.h │ │ ├── lcorolib.c │ │ ├── lctype.c │ │ ├── lctype.h │ │ ├── ldblib.c │ │ ├── ldebug.c │ │ ├── ldebug.h │ │ ├── ldo.c │ │ ├── ldo.h │ │ ├── ldump.c │ │ ├── lfunc.c │ │ ├── lfunc.h │ │ ├── lgc.c │ │ ├── lgc.h │ │ ├── linit.c │ │ ├── liolib.c │ │ ├── llex.c │ │ ├── llex.h │ │ ├── llimits.h │ │ ├── lmathlib.c │ │ ├── lmem.c │ │ ├── lmem.h │ │ ├── loadlib.c │ │ ├── lobject.c │ │ ├── lobject.h │ │ ├── lopcodes.c │ │ ├── lopcodes.h │ │ ├── loslib.c │ │ ├── lparser.c │ │ ├── lparser.h │ │ ├── lprefix.h │ │ ├── lstate.c │ │ ├── lstate.h │ │ ├── lstring.c │ │ ├── lstring.h │ │ ├── lstrlib.c │ │ ├── ltable.c │ │ ├── ltable.h │ │ ├── ltablib.c │ │ ├── ltm.c │ │ ├── ltm.h │ │ ├── lua.c │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luac.c │ │ ├── luaconf.h │ │ ├── lualib.h │ │ ├── lundump.c │ │ ├── lundump.h │ │ ├── lutf8lib.c │ │ ├── lvm.c │ │ ├── lvm.h │ │ ├── lzio.c │ │ └── lzio.h ├── HISTORY.md ├── LICENSE ├── Makefile ├── README.md ├── examples │ ├── abort.lua │ ├── agent.lua │ ├── checkdeadloop.lua │ ├── client.lua │ ├── cluster1.lua │ ├── cluster2.lua │ ├── clustername.lua │ ├── config │ ├── config.c1 │ ├── config.c2 │ ├── config.login │ ├── config.mc │ ├── config.mysql │ ├── config.userlog │ ├── config_log │ ├── globallog.lua │ ├── injectlaunch.lua │ ├── login │ │ ├── client.lua │ │ ├── gated.lua │ │ ├── logind.lua │ │ ├── main.lua │ │ └── msgagent.lua │ ├── main.lua │ ├── main_log.lua │ ├── main_mysql.lua │ ├── preload.lua │ ├── proto.lua │ ├── protoloader.lua │ ├── share.lua │ ├── simpledb.lua │ ├── simplemonitor.lua │ ├── simpleweb.lua │ ├── userlog.lua │ └── watchdog.lua ├── lualib-src │ ├── lsha1.c │ ├── lua-bson.c │ ├── lua-clientsocket.c │ ├── lua-cluster.c │ ├── lua-crypt.c │ ├── lua-debugchannel.c │ ├── lua-memory.c │ ├── lua-mongo.c │ ├── lua-multicast.c │ ├── lua-mysqlaux.c │ ├── lua-netpack.c │ ├── lua-profile.c │ ├── lua-seri.c │ ├── lua-seri.h │ ├── lua-sharedata.c │ ├── lua-skynet.c │ ├── lua-socket.c │ ├── lua-stm.c │ ├── sproto │ │ ├── README │ │ ├── README.md │ │ ├── lsproto.c │ │ ├── msvcint.h │ │ ├── sproto.c │ │ └── sproto.h │ └── timingwheel │ │ ├── lua-twheel.c │ │ ├── twheel.c │ │ └── twheel.h ├── lualib │ ├── cluster.lua │ ├── datacenter.lua │ ├── dns.lua │ ├── http │ │ ├── httpc.lua │ │ ├── httpd.lua │ │ ├── internal.lua │ │ ├── sockethelper.lua │ │ └── url.lua │ ├── loader.lua │ ├── md5.lua │ ├── mongo.lua │ ├── mqueue.lua │ ├── multicast.lua │ ├── mysql.lua │ ├── redis.lua │ ├── sharedata.lua │ ├── sharedata │ │ └── corelib.lua │ ├── sharemap.lua │ ├── skynet.lua │ ├── skynet │ │ ├── coroutine.lua │ │ ├── debug.lua │ │ ├── harbor.lua │ │ ├── inject.lua │ │ ├── injectcode.lua │ │ ├── manager.lua │ │ ├── queue.lua │ │ └── remotedebug.lua │ ├── snax.lua │ ├── snax │ │ ├── gateserver.lua │ │ ├── hotfix.lua │ │ ├── interface.lua │ │ ├── loginserver.lua │ │ └── msgserver.lua │ ├── socket.lua │ ├── socketchannel.lua │ ├── sproto.lua │ ├── sprotoloader.lua │ └── sprotoparser.lua ├── pbc │ ├── Makefile │ ├── README.md │ ├── alloc.c │ ├── alloc.h │ ├── array.c │ ├── array.h │ ├── binding │ │ ├── lua │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── build_ios.sh │ │ │ ├── parser.lua │ │ │ ├── pbc-lua.c │ │ │ ├── protobuf.lua │ │ │ ├── test.lua │ │ │ ├── test2.lua │ │ │ └── testparser.lua │ │ └── lua53 │ │ │ ├── Makefile │ │ │ ├── build_ios.sh │ │ │ ├── pbc-lua53.c │ │ │ ├── protobuf.lua │ │ │ └── test.lua │ ├── bootstrap.c │ ├── bootstrap.h │ ├── build │ │ └── o │ │ │ ├── alloc.d │ │ │ ├── array.d │ │ │ ├── bootstrap.d │ │ │ ├── context.d │ │ │ ├── decode.d │ │ │ ├── map.d │ │ │ ├── pattern.d │ │ │ ├── proto.d │ │ │ ├── register.d │ │ │ ├── rmessage.d │ │ │ ├── stringpool.d │ │ │ ├── varint.d │ │ │ └── wmessage.d │ ├── context.c │ ├── context.h │ ├── decode.c │ ├── descriptor.pbc.h │ ├── map.c │ ├── map.h │ ├── pattern.c │ ├── pattern.h │ ├── pbc-lua53.c │ ├── pbc.h │ ├── proto.c │ ├── proto.h │ ├── register.c │ ├── rmessage.c │ ├── stringpool.c │ ├── stringpool.h │ ├── varint.c │ ├── varint.h │ └── wmessage.c ├── platform.mk ├── service-src │ ├── databuffer.h │ ├── hashid.h │ ├── service_gate.c │ ├── service_harbor.c │ ├── service_logger.c │ └── service_snlua.c ├── service │ ├── bootstrap.lua │ ├── cdummy.lua │ ├── clusterd.lua │ ├── clusterproxy.lua │ ├── cmaster.lua │ ├── cmemory.lua │ ├── console.lua │ ├── cslave.lua │ ├── datacenterd.lua │ ├── dbg.lua │ ├── debug_agent.lua │ ├── debug_console.lua │ ├── gate.lua │ ├── launcher.lua │ ├── multicastd.lua │ ├── service_mgr.lua │ ├── sharedatad.lua │ └── snaxd.lua ├── skynet-src │ ├── atomic.h │ ├── luashrtbl.h │ ├── malloc_hook.c │ ├── malloc_hook.h │ ├── rwlock.h │ ├── skynet.h │ ├── skynet_daemon.c │ ├── skynet_daemon.h │ ├── skynet_env.c │ ├── skynet_env.h │ ├── skynet_error.c │ ├── skynet_handle.c │ ├── skynet_handle.h │ ├── skynet_harbor.c │ ├── skynet_harbor.h │ ├── skynet_imp.h │ ├── skynet_log.c │ ├── skynet_log.h │ ├── skynet_main.c │ ├── skynet_malloc.h │ ├── skynet_module.c │ ├── skynet_module.h │ ├── skynet_monitor.c │ ├── skynet_monitor.h │ ├── skynet_mq.c │ ├── skynet_mq.h │ ├── skynet_server.c │ ├── skynet_server.h │ ├── skynet_socket.c │ ├── skynet_socket.h │ ├── skynet_start.c │ ├── skynet_timer.c │ ├── skynet_timer.h │ ├── socket_epoll.h │ ├── socket_kqueue.h │ ├── socket_poll.h │ ├── socket_server.c │ ├── socket_server.h │ └── spinlock.h └── test │ ├── pingserver.lua │ ├── sharemap.sp │ ├── testbson.lua │ ├── testcoroutine.lua │ ├── testdatacenter.lua │ ├── testdeadcall.lua │ ├── testdeadloop.lua │ ├── testdns.lua │ ├── testecho.lua │ ├── testharborlink.lua │ ├── testhttp.lua │ ├── testmemlimit.lua │ ├── testmongodb.lua │ ├── testmulticast.lua │ ├── testmulticast2.lua │ ├── testmysql.lua │ ├── testoverload.lua │ ├── testping.lua │ ├── testpipeline.lua │ ├── testqueue.lua │ ├── testredis.lua │ ├── testredis2.lua │ ├── testresponse.lua │ ├── testsha.lua │ ├── testsm.lua │ ├── testsocket.lua │ ├── teststm.lua │ ├── testterm.lua │ ├── testtimer.lua │ ├── testudp.lua │ └── time.lua └── tools ├── client.lua ├── client.sh ├── client_script └── login.lua ├── common └── login.lua └── robot.lua /config/gs_config.lua: -------------------------------------------------------------------------------- 1 | root = "./" 2 | thread = 8 3 | --logger = "log/gs.log" 4 | harbor = 0 5 | start = "gs_launcher" 6 | bootstrap = "snlua bootstrap" -- The service for bootstrap 7 | 8 | dictator_port = 7002 9 | sharedata_file = root.."lualib/base/loadshare.lua" 10 | gate_port = 8102 11 | 12 | ------------------路径配置------------------------------ 13 | luaservice = root.."service/?.lua;"..root.."service/?/main.lua;"..root.."skynet/service/?.lua;"..root.."skynet/service/?/main.lua" 14 | lua_path = root.."lualib/?.lua;"..root.."skynet/lualib/?.lua" 15 | lua_cpath = root.."skynet/luaclib/?.so" 16 | cpath = root.."skynet/cservice/?.so" 17 | lualoader = root.."skynet/lualib/loader.lua" 18 | preload = root.."lualib/base/preload.lua" 19 | ------------------路径配置------------------------------- 20 | -------------------------------------------------------------------------------- /daobiao/gamedata/data.lua: -------------------------------------------------------------------------------- 1 | return { 2 | grade2exp = { 3 | --等级, 经验 4 | [1] = 100, 5 | [2] = 230, 6 | [3] = 400, 7 | [4] = 700, 8 | [5] = 1000, 9 | }, 10 | item = { 11 | [1001] = { 12 | sid = 1001, 13 | belong = "virturl", 14 | name = "道具名-虚拟金币", 15 | cost_amount = 1, 16 | max_amount = 99, 17 | }, 18 | [10001] = { 19 | sid = 10001, 20 | belong = "other", 21 | name = "道具名-经验丹", 22 | cost_amount = 1, 23 | max_amount = 99, 24 | }, 25 | }, 26 | skill = { 27 | [1001] = { 28 | skill_id = 1001, 29 | skill_name = "万剑归一", 30 | belong = "positive", 31 | perform_id = 1001, 32 | }, 33 | [1002] = { 34 | skill_id = 1001, 35 | skill_name = "强身", 36 | belong = "passive", 37 | skill_effect = {phy_attack="10", max_hp="100*lv"}, 38 | skill_effect_ratio = {} 39 | }, 40 | }, 41 | } 42 | -------------------------------------------------------------------------------- /gs_run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./shell/gs_kill.sh 3 | ./skynet/skynet ./config/gs_config.lua & 4 | -------------------------------------------------------------------------------- /lualib/base/defines.lua: -------------------------------------------------------------------------------- 1 | SEX = { 2 | FEMALE = 1, 3 | MALE = 2, 4 | } 5 | 6 | WAR_TYPE = { 7 | WAR_PVE = 1, 8 | WAR_PVP = 2, 9 | } 10 | 11 | WARRIOR_TYPE = { 12 | PLAYER = 1, 13 | SUMMON = 2, 14 | NPC = 3, 15 | } 16 | 17 | WAR_STATUS = { 18 | OPERATOR = 1, --操作时间,播放倒计时 19 | ANIMATION = 2, --动画播放 20 | } 21 | 22 | PERFORM_TARGET_TYPE = { 23 | FRIEND = 1, 24 | ENEMY = 2, 25 | } 26 | 27 | PERFORM_TYPE = { 28 | PHY_ATTACK = 1, 29 | } 30 | -------------------------------------------------------------------------------- /lualib/base/hook.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | local logic_func = nil 4 | 5 | function M.finish_hook() 6 | if logic_func then 7 | safe_call(logic_func) 8 | end 9 | end 10 | 11 | function M.set_logic_func(func) 12 | logic_func = func 13 | end 14 | 15 | return M 16 | -------------------------------------------------------------------------------- /lualib/base/loadshare.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | function Require(sPath) 4 | local f = loadfile_ex(sPath) 5 | return f() 6 | end 7 | 8 | M.daobiao = Require("daobiao/gamedata/data.lua") 9 | 10 | return M 11 | -------------------------------------------------------------------------------- /lualib/base/netfind.lua: -------------------------------------------------------------------------------- 1 | local protobuf = require "base.protobuf" 2 | 3 | 4 | local M = {} 5 | local netdefines = {} 6 | 7 | function M.Init() 8 | local fp = io.open("./proto/proto.pb", "rb") 9 | local data = fp:read("a") 10 | fp:close() 11 | protobuf.register(data) 12 | 13 | local env = setmetatable({}, {__index = _G}) 14 | local fp = io.open("proto/netdefines.lua", "rb") 15 | local data = fp:read("a") 16 | fp:close() 17 | local f, s = load(data, "netdefines", "bt", env) 18 | assert(f, s) 19 | netdefines = f() 20 | end 21 | 22 | function M.FindC2GSProtoByName(sMessage) 23 | return netdefines.C2GSProto2Index[sMessage] 24 | end 25 | 26 | function M.FindC2GSProtoByIndex(iProto) 27 | return netdefines.C2GSIndex2Proto[iProto] 28 | end 29 | 30 | function M.FindGS2CProtoByName(sMessage) 31 | return netdefines.GS2CProto2Index[sMessage] 32 | end 33 | 34 | function M.FindGS2CProtoByIndex(iProto) 35 | return netdefines.GS2CIndex2Proto[iProto] 36 | end 37 | 38 | return M 39 | 40 | -------------------------------------------------------------------------------- /lualib/base/share.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local sharedata = require "sharedata" 3 | 4 | local M = {} 5 | 6 | skynet.init(function() 7 | --避免每次query创建一个table,一个服务只创建一个table 8 | --此种写法有一个要求就是需要每个server启动的时候,require "base.share" 进行一次初始化 9 | local box = sharedata.query("share") 10 | setmetatable(M, {__index = box}) 11 | end, "share") 12 | 13 | return M 14 | -------------------------------------------------------------------------------- /lualib/base/stringop.lua: -------------------------------------------------------------------------------- 1 | local fm = {} 2 | function formula_string(msg, env) 3 | if fm[msg] then 4 | return fm[msg]() 5 | end 6 | fm[msg] = load(string.format([[ 7 | for k, v in pairs(env) do 8 | _ENV[k] = v 9 | end 10 | return (%s) 11 | ]], msg), msg, "bt", {env=env, math=math, pairs=pairs}) 12 | return fm[msg]() 13 | end 14 | 15 | function split(str, sep, plain) 16 | local b, res = 0, {} 17 | sep = sep or "%s+" 18 | 19 | if #sep == 0 then 20 | for i = 1, #str do 21 | res[#res + 1] = string.sub(str, i, i) 22 | end 23 | return res 24 | end 25 | 26 | while b <= #str do 27 | local e, e2 = string.find(str, sep, b, plain) 28 | if e then 29 | res[#res+1] = string.sub(str, b, e-1) 30 | b = e2 + 1 31 | if b > #str then res[#res+1] = "" end 32 | else 33 | res[#res+1] = string.sub(str, b) 34 | break 35 | end 36 | end 37 | 38 | return res 39 | end 40 | 41 | function trim(s) 42 | return s:match'^%s*(.*%S)%s*$' or '' 43 | end 44 | 45 | function replace_vars(str, vars) 46 | --replace_var("hello {name}", {name="world"}) 47 | if not vars then 48 | vars = str 49 | str = vars[1] 50 | end 51 | return (string_gsub(str, "({([^}]+)})", 52 | function(whole,i) 53 | return vars[i] or whole 54 | end)) 55 | end 56 | 57 | -------------------------------------------------------------------------------- /lualib/base/texthandle.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local M = {} 4 | local textcmd = {} 5 | 6 | function M.init(m) 7 | textcmd = m 8 | 9 | skynet.register_protocol( 10 | { 11 | name = "text", 12 | id = skynet.PTYPE_TEXT, 13 | pack = function(...) 14 | return table.concat({...}, " ") 15 | end, 16 | unpack = function(...) return ... end, 17 | } 18 | ) 19 | skynet.dispatch("text", function(...) 20 | textcmd.Invoke(...) 21 | end) 22 | end 23 | 24 | return M 25 | -------------------------------------------------------------------------------- /lualib/base/timeop.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | function get_time(bFloat) 4 | if bFloat then 5 | return skynet.time() 6 | else 7 | return math.floor(skynet.time()) 8 | end 9 | end 10 | 11 | --2018-01-01 00:00:00 12 | local standard_time = 1514736000 13 | function get_dayno(sec) 14 | sec = sec or get_time() 15 | return math.floor((sec-standard_time) // (24*3600)) 16 | end 17 | 18 | function get_weekno(sec) 19 | sec = sec or get_time() 20 | return math.floor((sec-standard_time) // (7*24*3600)) 21 | end 22 | 23 | function get_monthno(sec) 24 | sec = sec or get_time() 25 | date = os.date("*t", get_time()) 26 | return date.year*100 + date.month 27 | end 28 | -------------------------------------------------------------------------------- /proto/base.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message GS2CSendMessage { 4 | optional string msg = 1; 5 | } 6 | 7 | message PlayerProp { 8 | optional string mask = 1; //标记哪些字段是有更新 9 | optional uint32 pid = 2; //玩家id 10 | optional string name = 3; //玩家名字 11 | optional uint32 exp = 4; //经验 12 | optional uint32 grade = 5; //等级 13 | optional uint32 school = 6; //门派 14 | optional uint32 sex = 7; //性别 15 | optional uint32 icon = 8; //头像图标 16 | optional uint32 phy_attack = 9; //物理攻击 17 | optional uint32 phy_defense = 10; //物理防御 18 | optional uint32 mag_attack = 11; //法术攻击 19 | optional uint32 mag_defense = 12; //法术防御 20 | optional uint32 cure_power = 13; //治疗强度 21 | optional uint32 speed = 14; //出手速度 22 | optional uint32 seal_hit_ratio = 15; //封印命中 23 | optional uint32 res_seal_hit_ratio = 16;//封印抗性 24 | optional uint32 phy_critical_ratio = 17;//物理暴击 25 | optional uint32 res_phy_critical_ratio = 18; //物理抗暴 26 | optional uint32 mag_critical_ratio = 19;//法术暴击 27 | optional uint32 res_mag_critical_ratio = 20; //法术抗暴 28 | optional uint32 hp = 21; //当前气血 29 | optional uint32 max_hp = 22; //最大气血 30 | optional uint32 mp = 23; //当前魔法 31 | optional uint32 max_mp = 24; //最大魔法 32 | } 33 | -------------------------------------------------------------------------------- /proto/client/item.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message C2GSItemUse { 4 | optional uint32 item_id = 1; //道具唯一id 5 | optional uint32 target = 2; //道具使用目标 6 | optional uint32 amount = 3; //使用数量 7 | } 8 | -------------------------------------------------------------------------------- /proto/client/login.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message C2GSLoginAccount { //使用账号登陆 4 | optional string account = 1; //账号 5 | optional string pwd = 2; //密码 6 | } 7 | 8 | message C2GSCreateRole { //创建角色 9 | optional string account = 1; //账号 10 | optional string name = 2; //名字 11 | optional uint32 icon = 3; //头像(待定) 12 | } 13 | 14 | message C2GSSelectRole { //选择角色登陆 15 | optional string account = 1; //账号 16 | optional uint32 pid = 2; //玩家id 17 | } 18 | -------------------------------------------------------------------------------- /proto/netdefines.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | local C2GSProto2Index = {} 4 | local C2GSIndex2Proto = {} 5 | local GS2CProto2Index = {} 6 | local GS2CIndex2Proto = {} 7 | 8 | 9 | -------------------- 10 | local C2GSDefines = {} 11 | 12 | --C2GSStart-- 13 | C2GSDefines.login = { 14 | C2GSSelectRole = 1001, 15 | C2GSCreateRole = 1000, 16 | C2GSLoginAccount = 1002, 17 | } 18 | --C2GSEnd-- 19 | 20 | 21 | local GS2CDefines = {} 22 | 23 | --GS2CStart-- 24 | GS2CDefines.login = { 25 | GS2CSelectRole = 1000, 26 | GS2CHello = 1001, 27 | GS2CLoginError = 1002, 28 | } 29 | 30 | GS2CDefines.player = { 31 | GS2CLoginFinish = 2000, 32 | GS2CRefreshPlayerProp = 2001, 33 | } 34 | 35 | GS2CDefines.iteam = { 36 | GS2CItemList = 3000, 37 | } 38 | --GS2CEnd-- 39 | --------------------- 40 | 41 | 42 | for sModule, mDefines in pairs(C2GSDefines) do 43 | for sMessage, iProto in pairs(mDefines) do 44 | C2GSProto2Index[sMessage] = iProto 45 | C2GSIndex2Proto[iProto] = {sModule, sMessage} 46 | end 47 | end 48 | 49 | for sModule, mDefines in pairs(GS2CDefines) do 50 | for sMessage, iProto in pairs(mDefines) do 51 | GS2CProto2Index[sMessage] = iProto 52 | GS2CIndex2Proto[iProto] = {sModule, sMessage} 53 | end 54 | end 55 | 56 | 57 | M.C2GSProto2Index = C2GSProto2Index 58 | M.C2GSIndex2Proto = C2GSIndex2Proto 59 | M.GS2CProto2Index = GS2CProto2Index 60 | M.GS2CIndex2Proto = GS2CIndex2Proto 61 | 62 | return M 63 | -------------------------------------------------------------------------------- /proto/proto.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/snowolder/RoundGameServer/8c1141c58f388ab7431aad1e8c5ef70715b98803/proto/proto.pb -------------------------------------------------------------------------------- /proto/server/iteam.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message ItemUnit { 4 | optional uint32 sid = 1; //道具造型id 5 | optional uint32 item_id = 2; //道具唯一id 6 | optional uint32 amount = 3; //道具数量 7 | optional uint32 pos = 4; //所在道具栏位置 8 | } 9 | 10 | message GS2CItemList { 11 | repeated ItemUnit item_list = 1; //道具列表 12 | } 13 | -------------------------------------------------------------------------------- /proto/server/login.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message GS2CHello { 4 | optional uint32 timestamp = 1; 5 | } 6 | 7 | message GS2CLoginError { //登陆提示 8 | optional uint32 errcode = 1; //错误码 9 | } 10 | 11 | message RoleInfo { 12 | optional uint32 pid = 1; //玩家id 13 | optional string name = 2; //玩家名字 14 | optional string icon = 3; //玩家头像 15 | } 16 | 17 | message GS2CSelectRole { //显示可使用玩家列表 18 | repeated RoleInfo role_list = 1; //玩家列表 19 | } 20 | -------------------------------------------------------------------------------- /proto/server/player.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import "base.proto"; 3 | 4 | message GS2CRefreshPlayerProp { 5 | optional PlayerProp prop = 1; //玩家属性表 6 | } 7 | 8 | message GS2CLoginFinish { 9 | } 10 | -------------------------------------------------------------------------------- /service/dictator/dictatorcmd.lua: -------------------------------------------------------------------------------- 1 | ------------------------------ 2 | --此模块主要用于实现后台指令 3 | ------------------------------ 4 | 5 | local global = require "global" 6 | local interactive = require "base.interactive" 7 | 8 | function update_code(stdin, print_back, file) 9 | --热更代码 10 | local dotfile = string.gsub(file, "%/", ".") 11 | global.oDictatorObj:UpdateCode(dotfile) 12 | end 13 | 14 | function uc(stdin, print_back, file) 15 | update_code(stdin, print_back, file) 16 | end 17 | 18 | function update_share(stdin, print_back) 19 | --更新sharedata 共享数据块 20 | interactive.send(".share", "common", "UpdateShareData") 21 | end 22 | 23 | function inter(stdin, print_back) 24 | local skynet = require "skynet" 25 | local interactive = require "base.interactive" 26 | --interactive.send(".world", "module", "function", "args") 27 | interactive.send(".gamedb", "testdb", "SaveInfo2TestDb") 28 | end 29 | 30 | function runtest(stdin, print_back) 31 | local skynet = require "skynet" 32 | local interactive = require "base.interactive" 33 | interactive.send(".world", "common", "RunTest") 34 | end 35 | -------------------------------------------------------------------------------- /service/dictator/dictatorobj.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local interactive = require "base.interactive" 3 | local baseobj = import(lualib_path("base.baseobj")) 4 | 5 | function NewDictatorObj(...) 6 | return CDictator:New(...) 7 | end 8 | 9 | 10 | CDictator = {} 11 | CDictator.__index = CDictator 12 | inherit(CDictator, baseobj.CBaseObj) 13 | 14 | function CDictator:New(...) 15 | local o = super(CDictator).New(self) 16 | o.m_mService = {} 17 | return o 18 | end 19 | 20 | function CDictator:RegisterService(sAddr, iInst) 21 | if not self.m_mService[sAddr] then 22 | self.m_mService[sAddr] = {} 23 | end 24 | self.m_mService[sAddr][iInst] = true 25 | end 26 | 27 | function CDictator:UpdateCode(dotfile) 28 | local sExecute = string.format([[ 29 | reload("%s") 30 | ]], dotfile) 31 | for sAddr, mInst in pairs(self.m_mService) do 32 | for iInst, _ in pairs(mInst) do 33 | interactive.send(iInst, "default", "ExecuteString", sExecute) 34 | end 35 | end 36 | end 37 | 38 | -------------------------------------------------------------------------------- /service/dictator/global.lua: -------------------------------------------------------------------------------- 1 | M = {} 2 | 3 | M.oDictatorObj = nil 4 | 5 | return M 6 | -------------------------------------------------------------------------------- /service/dictator/logiccmd/common.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | 3 | function RegisterService(mRecord, mArgs) 4 | local iInst = mArgs.inst 5 | local sAddr = mArgs.addr 6 | global.oDictatorObj:RegisterService(sAddr, iInst) 7 | end 8 | -------------------------------------------------------------------------------- /service/dictator/logiccmd/init.lua: -------------------------------------------------------------------------------- 1 | 2 | local mCmd = {} 3 | 4 | mCmd.common = import(service_path("logiccmd.common")) 5 | 6 | 7 | function Invoke(sModule, sFunc, ...) 8 | if not mCmd[sModule] then 9 | print("err: there is not invoke module:"..sModule..", check please") 10 | return 11 | end 12 | if not mCmd[sModule][sFunc] then 13 | print("err: there is not invoke func:"..sFunc..", check please") 14 | return 15 | end 16 | 17 | mCmd[sModule][sFunc](...) 18 | end 19 | -------------------------------------------------------------------------------- /service/gamedb/global.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.oGameDb = nil 4 | 5 | return M 6 | -------------------------------------------------------------------------------- /service/gamedb/logiccmd/accountdb.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local global = require "global" 3 | local interactive = require "base.interactive" 4 | 5 | local sTable = "account" 6 | 7 | function GetRoleList(mRecord, mData) 8 | local mCond = { 9 | account = mData.account, 10 | } 11 | local mQuery = { 12 | roleinfo = 1, 13 | } 14 | local mResult = global.oGameDb:FindOne(sTable, mCond, mQuery) 15 | interactive.respond(mRecord.source, mRecord.session, mResult) 16 | end 17 | 18 | function SaveRoleList(mRecord, mData) 19 | local mCond = { 20 | account = mData.account, 21 | } 22 | local mUpdate = { 23 | ["$set"] = { 24 | roleinfo = mData.roleinfo, 25 | }, 26 | } 27 | local bUpsert = true 28 | global.oGameDb:Update(sTable, mCond, mUpdate, bUpsert) 29 | end 30 | -------------------------------------------------------------------------------- /service/gamedb/logiccmd/idsupplydb.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local interactive = require "base.interactive" 3 | 4 | local sTable = "idsupply" 5 | 6 | function LoadAllId(mRecord, mData) 7 | local mCond = { 8 | id_info = {["$exists"] = true,}, 9 | } 10 | local mQuery = { 11 | id_info = 1, 12 | } 13 | local mResult = global.oGameDb:FindOne(sTable, mCond, mQuery) or {} 14 | interactive.respond(mRecord.source, mRecord.session, {data=mResult.id_info}) 15 | end 16 | 17 | function SaveAllId(mRecord, mData) 18 | local mCond = { 19 | id_info = {["$exists"] = true,}, 20 | } 21 | local mUpdate = { 22 | ["$set"] = {id_info = mData,}, 23 | } 24 | local bUpsert = true 25 | global.oGameDb:Update(sTable, mCond, mUpdate, bUpsert) 26 | end 27 | -------------------------------------------------------------------------------- /service/gamedb/logiccmd/init.lua: -------------------------------------------------------------------------------- 1 | 2 | local mCmd = {} 3 | 4 | mCmd.testdb = import(service_path("logiccmd.testdb")) 5 | mCmd.accountdb = import(service_path("logiccmd.accountdb")) 6 | mCmd.idsupplydb = import(service_path("logiccmd.idsupplydb")) 7 | mCmd.playerdb = import(service_path("logiccmd.playerdb")) 8 | 9 | function Invoke(sModule, sFunc, ...) 10 | if not mCmd[sModule] then 11 | print("err: there is not invoke module:"..sModule..", check please") 12 | return 13 | end 14 | if not mCmd[sModule][sFunc] then 15 | print("err: there is not invoke func:"..sFunc..", check please") 16 | return 17 | end 18 | 19 | mCmd[sModule][sFunc](...) 20 | end 21 | -------------------------------------------------------------------------------- /service/gamedb/logiccmd/playerdb.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local interactive = require "base.interactive" 3 | 4 | local sTable = "player" 5 | 6 | function InsertPlayerNameAndPid(mRecord, mData) 7 | local mInsert = { 8 | name = mData.name, 9 | pid = mData.pid, 10 | } 11 | local bSuccess = global.oGameDb:Insert(sTable, mInsert) 12 | interactive.respond(mRecord.source, mRecord.session, {success=bSuccess}) 13 | end 14 | 15 | --玩家在线时候才能加载这些模块 16 | function LoadOnlineCtrl(mRecord, mData) 17 | local mCond = { 18 | pid = mData.pid, 19 | } 20 | local mQuery = { 21 | basectrl = 1, 22 | activectrl = 1, 23 | itemctrl = 1, 24 | taskctrl = 1, 25 | summctrl = 1, 26 | skillctrl = 1, 27 | wieldctrl = 1, 28 | timectrl = 1, 29 | name = 1, 30 | } 31 | local m = global.oGameDb:FindOne(sTable, mCond, mQuery) 32 | interactive.respond(mRecord.source, mRecord.session, {data=m}) 33 | end 34 | 35 | function SaveOnlineCtrl(mRecord, mData) 36 | local mCond = { 37 | pid = mData.pid, 38 | } 39 | local mUpdate = { 40 | ["$set"] = { 41 | [mData.name] = mData.data, 42 | } 43 | } 44 | local bUpsert = true 45 | global.oGameDb:Update(sTable, mCond, mUpdate, bUpsert) 46 | end 47 | 48 | -------------------------------------------------------------------------------- /service/gamedb/logiccmd/testdb.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | 3 | local sTableName = "test" 4 | 5 | function SaveInfo2TestDb(...) 6 | --global.oGameDb:EnsureIndex(sTableName, {pid=1}, {unique=true}) 7 | --global.oGameDb:Insert(sTableName, {pid=11001, base={name="testdata", count=90909}}) 8 | --global.oGameDb:Insert(sTableName, {pid=10002, base={name="testdata", count=90909}}) 9 | --global.oGameDb:Insert(sTableName, {pid=10003, base={name="testdata", count=90909}}) 10 | --global.oGameDb:Update(sTableName, {pid=10003}, {["$set"] = {base={name="testdata", count=90919}}}) 11 | --global.oGameDb:Find(sTableName, {pid=10004}) --need use next func to get useful data 12 | --global.oGameDb:FindOne(sTableName, {pid=10004}) 13 | -- global.oGameDb:Update("account", {account="test2"}, {["$set"] = { 14 | -- roleinfo = { 15 | -- { 16 | -- pid = 10002, 17 | -- name = "pid1", 18 | -- icon = 1, 19 | -- }, 20 | -- } 21 | -- }}, true) 22 | end 23 | -------------------------------------------------------------------------------- /service/gamedb/main.lua: -------------------------------------------------------------------------------- 1 | 2 | local skynet = require "skynet.manager" 3 | local global = require "global" 4 | local interactive = require "base.interactive" 5 | local share = require "base.share" 6 | local gamedb = import(service_path("gamedbobj")) 7 | local logiccmd = import(service_path("logiccmd.init")) 8 | 9 | 10 | skynet.start(function() 11 | interactive.dispatch_logic(logiccmd) 12 | 13 | local mConfig = {host="127.0.0.1", port="27017"} 14 | global.oGameDb = gamedb.NewGameDbObj(mConfig, "game") 15 | 16 | --TODO ensure index 17 | global.oGameDb:EnsureIndex("account", {account=1}, {unique=true, name="account_index"}) 18 | global.oGameDb:EnsureIndex("player", {pid=1}, {unique=true, name="pid_index"}) 19 | global.oGameDb:EnsureIndex("player", {name=1}, {unique=true, name="name_index"}) 20 | 21 | skynet.register(".gamedb") 22 | interactive.send(".dictator", "common", "RegisterService", { 23 | addr = "."..MY_ADDR, 24 | inst = skynet.self(), 25 | }) 26 | skynet.error("gamedb service booted") 27 | end) 28 | -------------------------------------------------------------------------------- /service/gs_launcher.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | skynet.start(function() 4 | skynet.newservice("share") --各服务共享数据,可用于策划配表数据 5 | skynet.newservice("debug_console", 7001) 6 | skynet.newservice("dictator") --程序控制后台 7 | skynet.newservice("gamedb") --数据存储服务 8 | skynet.newservice("idsupply") --id分配中心;玩家id/帮派id等 9 | skynet.newservice("login") --登陆服务 10 | skynet.newservice("world") --玩法中心 11 | skynet.exit() 12 | end) 13 | -------------------------------------------------------------------------------- /service/idsupply/global.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.oIdMgr = nil 4 | 5 | return M 6 | -------------------------------------------------------------------------------- /service/idsupply/idmgr.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local interactive = require "base.interactive" 3 | local baseobj = import(lualib_path("base.baseobj")) 4 | 5 | function NewIdMgr(...) 6 | return CIdMgr:New(...) 7 | end 8 | 9 | CIdMgr = {} 10 | CIdMgr.__index = CIdMgr 11 | inherit(CIdMgr, baseobj.CBaseObj) 12 | 13 | function CIdMgr:New() 14 | local o = super(CIdMgr).New(self) 15 | o.m_iPlayerId = 1000 16 | o.m_bLoading = true 17 | return o 18 | end 19 | 20 | function CIdMgr:SaveDb() 21 | assert(not self.m_bLoading) 22 | local mData = { 23 | player_id = self.m_iPlayerId 24 | } 25 | interactive.send(".gamedb", "idsupplydb", "SaveAllId", mData) 26 | end 27 | 28 | function CIdMgr:LoadDb() 29 | assert(self.m_bLoading) 30 | interactive.request(".gamedb", "idsupplydb", "LoadAllId", {}, 31 | function(mRecord, mData) 32 | global.oIdMgr:Load(mData.data) 33 | global.oIdMgr:LoadFinish() 34 | end) 35 | end 36 | 37 | function CIdMgr:Load(mData) 38 | if not mData then return end 39 | self.m_iPlayerId = mData.player_id or self.m_iPlayerId 40 | end 41 | 42 | function CIdMgr:LoadFinish() 43 | self.m_bLoading = false 44 | end 45 | 46 | function CIdMgr:IsLoading() 47 | return self.m_bLoading 48 | end 49 | 50 | function CIdMgr:GenPlayerId() 51 | self.m_iPlayerId = self.m_iPlayerId + 1 52 | self:SaveDb() 53 | return self.m_iPlayerId 54 | end 55 | 56 | -------------------------------------------------------------------------------- /service/idsupply/logiccmd/common.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local interactive = require "base.interactive" 3 | 4 | function GenPlayerId(mRecord, mData) 5 | local oIdMgr = global.oIdMgr 6 | assert(not oIdMgr:IsLoading()) 7 | 8 | local iNewId = oIdMgr:GenPlayerId() 9 | interactive.respond(mRecord.source, mRecord.session, {id = iNewId}) 10 | end 11 | -------------------------------------------------------------------------------- /service/idsupply/logiccmd/init.lua: -------------------------------------------------------------------------------- 1 | 2 | local mCmd = {} 3 | 4 | mCmd.common = import(service_path("logiccmd.common")) 5 | 6 | 7 | function Invoke(sModule, sFunc, ...) 8 | if not mCmd[sModule] then 9 | print("err: there is not invoke module:"..sModule..", check please") 10 | return 11 | end 12 | if not mCmd[sModule][sFunc] then 13 | print("err: there is not invoke func:"..sFunc..", check please") 14 | return 15 | end 16 | 17 | mCmd[sModule][sFunc](...) 18 | end 19 | -------------------------------------------------------------------------------- /service/idsupply/main.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet.manager" 2 | local interactive = require "base.interactive" 3 | local net = require "base.net" 4 | local global = require "global" 5 | local logiccmd = import(service_path("logiccmd.init")) 6 | local idmgr = import(service_path("idmgr")) 7 | 8 | skynet.start(function() 9 | interactive.dispatch_logic(logiccmd) 10 | 11 | skynet.register(".idsupply") 12 | 13 | global.oIdMgr = idmgr.NewIdMgr() 14 | global.oIdMgr:LoadDb() 15 | 16 | interactive.send(".dictator", "common", "RegisterService", { 17 | addr = "."..MY_ADDR, 18 | inst = skynet.self(), 19 | }) 20 | skynet.error("idsupply service booted") 21 | end) 22 | -------------------------------------------------------------------------------- /service/login/defines.lua: -------------------------------------------------------------------------------- 1 | 2 | LOGIN_CODE = { 3 | LOGIN_OK = 1, 4 | LOGIN_WRONG_PWD = 2, 5 | LOGIN_ACCOUNT_UNEXIST = 3, 6 | LOGIN_SERVER_UNOPEN = 4, 7 | LOGIN_NAME_DUPLICATE = 5, 8 | LOGIN_PID_UNEXIST = 6, 9 | LOGIN_UNLOAD_ROLE = 7, 10 | LOGIN_ROLE_LIMIT = 8, 11 | } 12 | 13 | STATUS_LOGIN = { 14 | STATUS_INIT = 0, 15 | STATUS_ROLE = 1, 16 | } 17 | 18 | MAX_ROLE_LIMIT = 3 19 | -------------------------------------------------------------------------------- /service/login/global.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.oGateMgr = nil 4 | 5 | return M 6 | -------------------------------------------------------------------------------- /service/login/logiccmd/common.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local global = require "global" 3 | 4 | function KickConnection(mRecord, mData) 5 | local iFd = mData.fd 6 | global.oGateMgr:RemoveConnection(iFd) 7 | end 8 | -------------------------------------------------------------------------------- /service/login/logiccmd/init.lua: -------------------------------------------------------------------------------- 1 | 2 | local mCmd = {} 3 | 4 | mCmd.common = import(service_path("logiccmd.common")) 5 | 6 | 7 | function Invoke(sModule, sFunc, ...) 8 | if not mCmd[sModule] then 9 | print("err: there is not invoke module:"..sModule..", check please") 10 | return 11 | end 12 | if not mCmd[sModule][sFunc] then 13 | print("err: there is not invoke func:"..sFunc..", check please") 14 | return 15 | end 16 | 17 | mCmd[sModule][sFunc](...) 18 | end 19 | -------------------------------------------------------------------------------- /service/login/main.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet.manager" 2 | local interactive = require "base.interactive" 3 | local net = require "base.net" 4 | local global = require "global" 5 | local texthandle = require "base.texthandle" 6 | local logiccmd = import(service_path("logiccmd.init")) 7 | local netcmd = import(service_path("netcmd.init")) 8 | local textcmd = import(service_path("textcmd.init")) 9 | local gateobj = import(service_path("gateobj")) 10 | 11 | 12 | skynet.start(function() 13 | interactive.dispatch_logic(logiccmd) 14 | net.dispatch_net(netcmd) 15 | texthandle.init(textcmd) 16 | 17 | skynet.register(".login") 18 | 19 | global.oGateMgr = gateobj:NewGateMgr() 20 | global.oGateMgr:InitAllGateObj() 21 | 22 | interactive.send(".dictator", "common", "RegisterService", { 23 | addr = "."..MY_ADDR, 24 | inst = skynet.self(), 25 | }) 26 | skynet.error("login service booted") 27 | end) 28 | -------------------------------------------------------------------------------- /service/login/netcmd/init.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local global = require "global" 3 | 4 | local mCmd = {} 5 | mCmd.login = import(service_path("netcmd.login")) 6 | 7 | function Invoke(sMod, sMsg, fd, mData) 8 | local oConn = global.oGateMgr:GetConnection(fd) 9 | if oConn then 10 | safe_call(mCmd[sMod][sMsg], oConn, mData) 11 | else 12 | skynet.error("not connection fd:" .. fd) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /service/login/netcmd/login.lua: -------------------------------------------------------------------------------- 1 | 2 | function C2GSLoginAccount(oConn, mData) 3 | local sAccount = mData.account 4 | local sPwd = mData.pwd 5 | oConn:LoginAccount(sAccount, sPwd) 6 | end 7 | 8 | function C2GSCreateRole(oConn, mData) 9 | local sAccount = mData.account 10 | local sName = mData.name 11 | local iIcon = mData.icon 12 | oConn:CreateRole(sAccount, sName, iIcon) 13 | end 14 | 15 | function C2GSSelectRole(oConn, mData) 16 | local sAccount = mData.account 17 | local iPid = mData.pid 18 | oConn:SelectRole(sAccount, iPid) 19 | end 20 | -------------------------------------------------------------------------------- /service/login/textcmd/init.lua: -------------------------------------------------------------------------------- 1 | local netpack = require "netpack" 2 | local global = require "global" 3 | local gateobj = import(service_path("gateobj")) 4 | 5 | local M = {} 6 | 7 | function M.open(iAddr, iFd, sData) 8 | local sIp, sPort = string.match(sData, "(%d+.%d+.%d+.%d+):(%d+)") 9 | local iPort = tonumber(sPort) 10 | 11 | local oConn = gateobj.NewConnection(iAddr, iFd, iPort) 12 | global.oGateMgr:AddConnection(oConn) 13 | end 14 | 15 | function M.close(iAddr, iFd) 16 | global.oGateMgr:RemoveConnection(iFd) 17 | end 18 | 19 | 20 | function Invoke(session, source, msg, sz) 21 | --format: 5 open 5 127.0.0.1:57628:0 22 | local iAddr = source 23 | local sData = netpack.tostring2(msg, sz) 24 | local sFd, sCmd = string.match(sData, "(%d+) (%a+)") 25 | 26 | if M[sCmd] then 27 | safe_call(M[sCmd], iAddr, tonumber(sFd), sData) 28 | end 29 | end 30 | 31 | -------------------------------------------------------------------------------- /service/share/logiccmd/common.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local sharedata = require "sharedata" 3 | 4 | function UpdateShareData(mRecord, mArgs) 5 | local fp = io.open(skynet.getenv("sharedata_file")) 6 | local data = fp:read("a") 7 | fp:close() 8 | 9 | sharedata.update("share", data) 10 | end 11 | -------------------------------------------------------------------------------- /service/share/logiccmd/init.lua: -------------------------------------------------------------------------------- 1 | 2 | local mCmd = {} 3 | 4 | mCmd.common = import(service_path("logiccmd.common")) 5 | 6 | 7 | function Invoke(sModule, sFunc, ...) 8 | if not mCmd[sModule] then 9 | print("err: there is not invoke module:"..sModule..", check please") 10 | return 11 | end 12 | if not mCmd[sModule][sFunc] then 13 | print("err: there is not invoke func:"..sFunc..", check please") 14 | return 15 | end 16 | 17 | mCmd[sModule][sFunc](...) 18 | end 19 | -------------------------------------------------------------------------------- /service/share/main.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local manager = require "skynet.manager" 3 | local sharedata = require "sharedata" 4 | local interactive = require "base.interactive" 5 | local logiccmd = import(service_path("logiccmd.init")) 6 | 7 | skynet.start(function() 8 | interactive.dispatch_logic(logiccmd) 9 | 10 | local fp = io.open(skynet.getenv("sharedata_file")) 11 | local data = fp:read("a") 12 | fp:close() 13 | sharedata.new("share", data) 14 | 15 | manager.register ".share" 16 | skynet.error("share service booted") 17 | end) 18 | -------------------------------------------------------------------------------- /service/war/global.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.oWarMgr = nil 4 | M.oActionMgr = nil 5 | 6 | return M 7 | -------------------------------------------------------------------------------- /service/war/logiccmd/init.lua: -------------------------------------------------------------------------------- 1 | 2 | local mCmd = {} 3 | 4 | mCmd.war = import(service_path("logiccmd.war")) 5 | 6 | 7 | function Invoke(sModule, sFunc, ...) 8 | if not mCmd[sModule] then 9 | print("err: there is not invoke module:"..sModule..", check please") 10 | return 11 | end 12 | if not mCmd[sModule][sFunc] then 13 | print("err: there is not invoke func:"..sFunc..", check please") 14 | return 15 | end 16 | 17 | mCmd[sModule][sFunc](...) 18 | end 19 | -------------------------------------------------------------------------------- /service/war/main.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet.manager" 2 | local global = require "global" 3 | local interactive = require "base.interactive" 4 | local share = require "base.share" 5 | local logiccmd = import(service_path("logiccmd.init")) 6 | local warmgr = import(service_path("warmgr")) 7 | local actionmgr = import(service_path("actionmgr")) 8 | 9 | skynet.start(function() 10 | interactive.dispatch_logic(logiccmd) 11 | 12 | global.oWarMgr = warmgr.NewWarMgr() 13 | global.oActionMgr = actionmgr.NewActionMgr() 14 | 15 | interactive.send(".dictator", "common", "RegisterService", { 16 | addr = "."..MY_ADDR, 17 | inst = skynet.self(), 18 | }) 19 | skynet.error("war service booted") 20 | end) 21 | -------------------------------------------------------------------------------- /service/war/perform/pfmgr.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local global = require "global" 3 | local share = require "base.share" 4 | local baseobj = import(lualib_path("base.baseobj")) 5 | 6 | function NewPerformMgr() 7 | return CPerformMgr:New() 8 | end 9 | 10 | CPerformMgr = {} 11 | CPerformMgr.__index = CPerformMgr 12 | inherit(CPerformMgr, baseobj.CBaseObj) 13 | 14 | function CPerformMgr:New() 15 | local o = super(CPerformMgr).New(self) 16 | o.m_mPerform = {} 17 | return o 18 | end 19 | 20 | function CPerformMgr:AddPerform(iPerform, oPerform) 21 | self.m_mPerform[iPerform] = oPerform 22 | end 23 | 24 | function CPerformMgr:GetPerform(iPerform) 25 | return self.m_mPerform[iPerform] 26 | end 27 | 28 | -------------------------------------------------------------------------------- /service/war/warmgr.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local share = require "base.share" 3 | local baseobj = import(lualib_path("base.baseobj")) 4 | local warobj = import(service_path("warobj")) 5 | 6 | 7 | function NewWarMgr() 8 | return CWarMgr:New() 9 | end 10 | 11 | CWarMgr = {} 12 | CWarMgr.__index = CWarMgr 13 | inherit(CWarMgr, baseobj.CBaseObj) 14 | 15 | function CWarMgr:New() 16 | local o = super(CWarMgr).New(self) 17 | o.m_mWars = {} 18 | return o 19 | end 20 | 21 | function CWarMgr:Release() 22 | for iWar, oWar in pairs(self.m_mWars) do 23 | oWar:WarEnd(true) 24 | oWar:Release() 25 | end 26 | self.m_mWars = {} 27 | end 28 | 29 | function CWarMgr:GetWar(iWar) 30 | return self.m_mWars[iWar] 31 | end 32 | 33 | function CWarMgr:CreateWar(iWar, iType, iSubType, sName) 34 | --TODO 不同战斗类型使用不同的战斗模块创建战斗对象 35 | local oWar = warobj.NewWar(iWar, iType, iSubType, sName) 36 | self.m_mWars[iWar] = oWar 37 | end 38 | 39 | 40 | -------------------------------------------------------------------------------- /service/world/global.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | M.oWorldMgr = nil 4 | M.oConnMgr = nil 5 | M.oItemMgr = nil 6 | M.oNpcMgr = nil 7 | M.oSkillMgr = nil 8 | M.oWarMgr = nil 9 | 10 | return M 11 | -------------------------------------------------------------------------------- /service/world/item/other/i10001.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local skynet = require "skynet" 3 | local share = require "base.loadshare" 4 | local itembase = import(service_path("item.itembase")) 5 | 6 | CItem = {} 7 | CItem.__index = CItem 8 | CItem.m_sClassType = "item" 9 | CItem.m_sItemType = "other" 10 | inherit(CItem, itembase.CItem) 11 | 12 | function CItem:TrueUse(oPlayer, iTarget) 13 | local iCost = self:GetCostAmount() 14 | local sLogName = self:LogName() 15 | self:AddAmount(-iCost) 16 | local iAddExp = iCost * 1000 17 | oPlayer.m_oActiveCtrl:RewardExp(iAddExp, sLogName) 18 | end 19 | -------------------------------------------------------------------------------- /service/world/item/virtual/i1001.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local skynet = require "skynet" 3 | local share = require "base.loadshare" 4 | local itembase = import(service_path("item.virtual.virtualbase")) 5 | 6 | CItem = {} 7 | CItem.__index = CItem 8 | inherit(CItem, itembase.CItem) 9 | 10 | function CItem:Reward(oPlayer) 11 | local iCost = self:GetCostAmount() 12 | local sLogName = self:LogName() 13 | self:AddAmount(-iCost) 14 | 15 | local iVal = self:GetData("value") * iCost 16 | if iVal <= 0 then return end 17 | 18 | --oPlayer:RewardGold(iVal, sLogName) 19 | end 20 | -------------------------------------------------------------------------------- /service/world/item/virtual/virtualbase.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local skynet = require "skynet" 3 | local share = require "base.loadshare" 4 | local itembase = import(service_path("item.itembase")) 5 | 6 | CItem = {} 7 | CItem.__index = CItem 8 | CItem.m_sClassType = "item" 9 | CItem.m_sItemType = "virtual" 10 | inherit(CItem, itembase.CItem) 11 | 12 | function CItem:Reward(oPlayer) 13 | -- 14 | end 15 | -------------------------------------------------------------------------------- /service/world/logiccmd/common.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local protobuf = require "base.protobuf" 3 | 4 | function RunTest() 5 | local mIdField = protobuf.id_field("PlayerProp") 6 | print("PlayerProp", mIdField) 7 | end 8 | -------------------------------------------------------------------------------- /service/world/logiccmd/init.lua: -------------------------------------------------------------------------------- 1 | 2 | local mCmd = {} 3 | 4 | mCmd.login = import(service_path("logiccmd.login")) 5 | mCmd.common = import(service_path("logiccmd.common")) 6 | mCmd.war = import(service_path("logiccmd.war")) 7 | 8 | 9 | function Invoke(sModule, sFunc, ...) 10 | if not mCmd[sModule] then 11 | print("err: there is not invoke module:"..sModule..", check please") 12 | return 13 | end 14 | if not mCmd[sModule][sFunc] then 15 | print("err: there is not invoke func:"..sFunc..", check please") 16 | return 17 | end 18 | 19 | mCmd[sModule][sFunc](...) 20 | end 21 | -------------------------------------------------------------------------------- /service/world/logiccmd/login.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | 3 | function LoginPlayer(mRecord, mData) 4 | local iPid = mData.pid 5 | local mRole = mData.role 6 | global.oWorldMgr:LoginPlayer(iPid, mRole) 7 | end 8 | 9 | function KickConnection(mRecord, mData) 10 | local iFd = mData.fd 11 | global.oConnMgr:DelConnectionByFd(iFd) 12 | end 13 | -------------------------------------------------------------------------------- /service/world/logiccmd/war.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local global = require "global" 3 | 4 | function RemoteWarEnd(mRecord, mData) 5 | local iWarId = mData.war_id 6 | local mWarEnd = mData.war_end 7 | 8 | global.oWarMgr:WarEnd(iWarId, mWarEnd) 9 | end 10 | 11 | function RemoteLeavePlayer(mRecord, mData) 12 | local iWarId = mData.war_id 13 | local iPid = mData.pid 14 | local bEscape = mData.escape 15 | 16 | global.oWarMgr:RemoteLeavePlayer(iWarId, iPid, bEscape) 17 | end 18 | -------------------------------------------------------------------------------- /service/world/netcmd/init.lua: -------------------------------------------------------------------------------- 1 | local M = {} 2 | 3 | --M.test = import(service_path("netcmd.test")) 4 | M.item = import(service_path("netcmd.item")) 5 | M.war = import(service_path("netcmd.war")) 6 | 7 | function M.Invoke(sMod, sMsg, fd, mData) 8 | if not M[sMod] then 9 | skynet.error("uninit net module:"..sMod) 10 | return 11 | end 12 | 13 | local func = M[sMod][sMsg] 14 | if not func then 15 | skynet.error("uninit net func:"..sMod.."->"..sMsg) 16 | return 17 | end 18 | 19 | local oPlayer = global.oWorldMgr:GetOnlinePlayerByFd(fd) 20 | if oPlayer then 21 | safe_call(func, oPlayer, mData) 22 | end 23 | end 24 | 25 | return M 26 | -------------------------------------------------------------------------------- /service/world/netcmd/item.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | 3 | --使用道具 4 | function C2GSItemUse(oPlayer, mData) 5 | local iItem = mData.item_id 6 | local iTarget = mData.target 7 | local iAmount = mData.amount 8 | local oItem = oPlayer.m_oItemCtrl:GetItem(iItem) 9 | if oItem then 10 | oItem:Use(oPlayer, iTarget, iAmount) 11 | end 12 | end 13 | 14 | -------------------------------------------------------------------------------- /service/world/netcmd/war.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local global = require "global" 3 | 4 | function C2GSWarSkill(oPlayer, mData) 5 | local iWarId = oPlayer:GetWarId() 6 | if not iWarId then return end 7 | 8 | local iPid = oPlayer:GetPid() 9 | global.oWarMgr:WarSkill(iWar, iPid, mData) 10 | end 11 | 12 | function C2GSWarNormalAttack(oPlayer, mData) 13 | local iWarId = oPlayer:GetWarId() 14 | if not iWarId then return end 15 | 16 | local iPid = oPlayer:GetPid() 17 | global.oWarMgr:WarNormalAttack(iWarId, iPid, mData) 18 | end 19 | 20 | -------------------------------------------------------------------------------- /service/world/npc/npcmgr.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local global = require "global" 3 | local baseobj = import(lualib_path("base.baseobj")) 4 | 5 | function NewNpcMgr() 6 | return CNpcMgr:New() 7 | end 8 | 9 | CNpcMgr = {} 10 | CNpcMgr.__index = CNpcMgr 11 | inherit(CNpcMgr, baseobj.CBaseObj) 12 | 13 | function CNpcMgr:New() 14 | local o = super(CNpcMgr).New(self) 15 | o.m_iDispatchId = 1 16 | return o 17 | end 18 | 19 | -------------------------------------------------------------------------------- /service/world/player/ctrl/init.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local global = require "global" 3 | 4 | local basectrl = import(service_path("player.ctrl.base")) 5 | local activectrl = import(service_path("player.ctrl.active")) 6 | local itemctrl = import(service_path("player.ctrl.item")) 7 | local timeblock = import(service_path("timeblock")) 8 | local timectrl = import(service_path("player.ctrl.time")) 9 | 10 | function NewBaseCtrl(iPid, mRole) 11 | return basectrl.CBaseCtrl:New(iPid, mRole) 12 | end 13 | 14 | function NewActiveCtrl(iPid) 15 | return activectrl.CActiveCtrl:New(iPid) 16 | end 17 | 18 | function NewItemCtrl(iPid) 19 | return itemctrl.CItemCtrl:New(iPid) 20 | end 21 | 22 | function NewTaskCtrl(iPid) 23 | end 24 | 25 | function NewSummCtrl(iPid) 26 | end 27 | 28 | function NewSkillCtrl(iPid) 29 | end 30 | 31 | function NewWieldCtrl(iPid) 32 | end 33 | 34 | function NewTodayCtrl(iPid) 35 | return timeblock.NewToday(iPid) 36 | end 37 | 38 | function NewWeekCtrl(iPid) 39 | return timeblock.NewWeek(iPid) 40 | end 41 | 42 | function NewMonthCtrl(iPid) 43 | return timeblock.NewMonth(iPid) 44 | end 45 | 46 | function NewTempCtrl(iPid) 47 | return timeblock.NewTemp(iPid) 48 | end 49 | 50 | function NewTimeCtrl(iPid, mCtrl) 51 | return timectrl.CTimeCtrl:New(iPid, mCtrl) 52 | end 53 | -------------------------------------------------------------------------------- /service/world/skill/positive/positivebase.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------- 2 | --主动技能,携带战斗中使用的招式-- 3 | ---------------------------------- 4 | 5 | local baseobj = import(service_path("skill.skillbase")) 6 | 7 | CSkill = {} 8 | CSkill.__index = CSkill 9 | inherit(CSkill, baseobj.CSkill) 10 | 11 | function CSkill:GetWarPerform() 12 | local mSkill = self:GetSkillInfo() 13 | return mSkill.perform_id 14 | end 15 | 16 | -------------------------------------------------------------------------------- /service/world/skill/skillbase.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local share = require "base.share" 3 | local baseobj = import(lualib_path("base.baseobj")) 4 | 5 | CSkill = {} 6 | CSkill.__index = CSkill 7 | inherit(CSkill, baseobj.CBaseObj) 8 | 9 | function CSkill:New(iSkill) 10 | local o = super(CSkill).New(self) 11 | o.m_iSkill = iSkill 12 | o.m_iLevel = 1 13 | o.m_mApply = {} 14 | o.m_mApplyRatio = {} 15 | return o 16 | end 17 | 18 | function CSkill:Release() 19 | super(CSkill).Release(self) 20 | end 21 | 22 | function CSkill:Save() 23 | local mSave = {} 24 | mSave.level = self.m_iLevel 25 | return mSave 26 | end 27 | 28 | function CSkill:Load(m) 29 | if not m then return end 30 | 31 | self.m_iLevel = m.level 32 | end 33 | 34 | function CSkill:Level() 35 | return self.m_iLevel 36 | end 37 | 38 | function CSkill:SetLevel(iLevel) 39 | self.m_iLevel = iLevel 40 | self:Dirty() 41 | end 42 | 43 | function CSkill:SkillEffect(oPlayer) 44 | end 45 | 46 | function CSkill:SkillUnEffect(oPlayer) 47 | end 48 | 49 | function CSkill:GetWarPerform() 50 | end 51 | 52 | function CSkill:GetSkillInfo() 53 | return global.oSkillMgr:GetSkillConfig(self.m_iSkill) 54 | end 55 | 56 | -------------------------------------------------------------------------------- /service/world/skill/skillmgr.lua: -------------------------------------------------------------------------------- 1 | local global = require "global" 2 | local share = require "base.share" 3 | local baseobj = import(lualib_path("base.baseobj")) 4 | 5 | 6 | function NewSkillMgr() 7 | return CSkillMgr:New() 8 | end 9 | 10 | CSkillMgr = {} 11 | CSkillMgr.__index = CSkillMgr 12 | inherit(CSkillMgr, baseobj.CBaseObj) 13 | 14 | function CSkillMgr:New() 15 | local o = super(CSkillMgr).New(self) 16 | o.m_mSkillCache = {} 17 | return o 18 | end 19 | 20 | function CSkillMgr:GetSkill(iSkill) 21 | if self.m_mSkillCache[iSkill] then 22 | return self.m_mSkillCache[iSkill] 23 | end 24 | local oSkill = self:CreateSkill(iSkill) 25 | self.m_mSkillCache[iSkill] = oSkill 26 | return oSkill 27 | end 28 | 29 | function CSkillMgr:CreateSkill(iSkill) 30 | local mSkill = GetSkillConfig(iSkill) 31 | assert(mSkill, "unexist skill "..iSkill) 32 | 33 | local sPath = "skill/"..mSkill.belong.."/s"..iSkill 34 | if file_exists(sPath, ".lua") then 35 | local oModule = import(service_path(sPath)) 36 | return oModule:New(iSkill) 37 | else 38 | local sPath = string.format("skill.%s.%sbase", mSkill.belong, mSkill.belong) 39 | local oModule = import(service_path(sPath)) 40 | return oModule:New(iSkill) 41 | end 42 | end 43 | 44 | function CSkillMgr:GetSkillConfig(iSkill) 45 | return share["skill"][iSkill] 46 | end 47 | -------------------------------------------------------------------------------- /shell/gs_kill.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ps ux |grep skynet |grep config |awk '{print $2}' |xargs kill -9 3 | -------------------------------------------------------------------------------- /shell/gs_run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ./shell/gs_kill.sh 3 | ./skynet/skynet ./config/gs_config.lua & 4 | -------------------------------------------------------------------------------- /shell/make_proto.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python ./shell/format_proto.py 3 | protoc -I=./proto/ -o./proto/proto.pb `find ./ -name '*.proto'` 4 | -------------------------------------------------------------------------------- /skynet/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | /skynet 4 | /skynet.pid 5 | 3rd/lua/lua 6 | 3rd/lua/luac 7 | /cservice 8 | /luaclib 9 | *.so 10 | *.dSYM 11 | .DS_Store 12 | -------------------------------------------------------------------------------- /skynet/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rd/jemalloc"] 2 | path = 3rd/jemalloc 3 | url = https://github.com/jemalloc/jemalloc.git 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | 3 | environment: 4 | matrix: 5 | - MSYSTEM: MINGW64 6 | CPU: x86_64 7 | MSVC: amd64 8 | - MSYSTEM: MINGW32 9 | CPU: i686 10 | MSVC: x86 11 | - MSYSTEM: MINGW64 12 | CPU: x86_64 13 | - MSYSTEM: MINGW32 14 | CPU: i686 15 | - MSYSTEM: MINGW64 16 | CPU: x86_64 17 | MSVC: amd64 18 | CONFIG_FLAGS: --enable-debug 19 | - MSYSTEM: MINGW32 20 | CPU: i686 21 | MSVC: x86 22 | CONFIG_FLAGS: --enable-debug 23 | - MSYSTEM: MINGW64 24 | CPU: x86_64 25 | CONFIG_FLAGS: --enable-debug 26 | - MSYSTEM: MINGW32 27 | CPU: i686 28 | CONFIG_FLAGS: --enable-debug 29 | 30 | install: 31 | - set PATH=c:\msys64\%MSYSTEM%\bin;c:\msys64\usr\bin;%PATH% 32 | - if defined MSVC call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %MSVC% 33 | - if defined MSVC pacman --noconfirm -Rsc mingw-w64-%CPU%-gcc gcc 34 | - pacman --noconfirm -Rsc catgets 35 | - pacman --noconfirm -Suy mingw-w64-%CPU%-make 36 | 37 | build_script: 38 | - bash -c "autoconf" 39 | - bash -c "./configure $CONFIG_FLAGS" 40 | - mingw32-make 41 | - file lib/jemalloc.dll 42 | - mingw32-make tests 43 | - mingw32-make -k check 44 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/.autom4te.cfg: -------------------------------------------------------------------------------- 1 | begin-language: "Autoconf-without-aclocal-m4" 2 | args: --no-cache 3 | end-language: "Autoconf-without-aclocal-m4" 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/README: -------------------------------------------------------------------------------- 1 | jemalloc is a general purpose malloc(3) implementation that emphasizes 2 | fragmentation avoidance and scalable concurrency support. jemalloc first came 3 | into use as the FreeBSD libc allocator in 2005, and since then it has found its 4 | way into numerous applications that rely on its predictable behavior. In 2010 5 | jemalloc development efforts broadened to include developer support features 6 | such as heap profiling and extensive monitoring/tuning hooks. Modern jemalloc 7 | releases continue to be integrated back into FreeBSD, and therefore versatility 8 | remains critical. Ongoing development efforts trend toward making jemalloc 9 | among the best allocators for a broad range of demanding applications, and 10 | eliminating/mitigating weaknesses that have practical repercussions for real 11 | world applications. 12 | 13 | The COPYING file contains copyright and licensing information. 14 | 15 | The INSTALL file contains information on how to configure, build, and install 16 | jemalloc. 17 | 18 | The ChangeLog file contains a brief summary of changes for each release. 19 | 20 | URL: http://jemalloc.net/ 21 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for i in autoconf; do 4 | echo "$i" 5 | $i 6 | if [ $? -ne 0 ]; then 7 | echo "Error $? in $i" 8 | exit 1 9 | fi 10 | done 11 | 12 | echo "./configure --enable-autogen $@" 13 | ./configure --enable-autogen $@ 14 | if [ $? -ne 0 ]; then 15 | echo "Error $? in ./configure" 16 | exit 1 17 | fi 18 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/bin/jemalloc.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | 7 | @LD_PRELOAD_VAR@=${libdir}/libjemalloc.@SOREV@ 8 | export @LD_PRELOAD_VAR@ 9 | exec "$@" 10 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/config.stamp.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/snowolder/RoundGameServer/8c1141c58f388ab7431aad1e8c5ef70715b98803/skynet/3rd/jemalloc/config.stamp.in -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/doc/html.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/doc/manpages.xsl.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/doc/stylesheet.xsl: -------------------------------------------------------------------------------- 1 | 2 | ansi 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/arena_structs_a.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H 2 | #define JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H 3 | 4 | #include "jemalloc/internal/bitmap.h" 5 | 6 | struct arena_slab_data_s { 7 | /* Per region allocated/deallocated bitmap. */ 8 | bitmap_t bitmap[BITMAP_GROUPS_MAX]; 9 | }; 10 | 11 | #endif /* JEMALLOC_INTERNAL_ARENA_STRUCTS_A_H */ 12 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/background_thread_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_BACKGROUND_THREAD_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_BACKGROUND_THREAD_EXTERNS_H 3 | 4 | extern bool opt_background_thread; 5 | extern malloc_mutex_t background_thread_lock; 6 | extern atomic_b_t background_thread_enabled_state; 7 | extern size_t n_background_threads; 8 | extern background_thread_info_t *background_thread_info; 9 | extern bool can_enable_background_thread; 10 | 11 | bool background_thread_create(tsd_t *tsd, unsigned arena_ind); 12 | bool background_threads_enable(tsd_t *tsd); 13 | bool background_threads_disable(tsd_t *tsd); 14 | void background_thread_interval_check(tsdn_t *tsdn, arena_t *arena, 15 | arena_decay_t *decay, size_t npages_new); 16 | void background_thread_prefork0(tsdn_t *tsdn); 17 | void background_thread_prefork1(tsdn_t *tsdn); 18 | void background_thread_postfork_parent(tsdn_t *tsdn); 19 | void background_thread_postfork_child(tsdn_t *tsdn); 20 | bool background_thread_stats_read(tsdn_t *tsdn, 21 | background_thread_stats_t *stats); 22 | void background_thread_ctl_init(tsdn_t *tsdn); 23 | 24 | #ifdef JEMALLOC_PTHREAD_CREATE_WRAPPER 25 | extern int pthread_create_wrapper(pthread_t *__restrict, const pthread_attr_t *, 26 | void *(*)(void *), void *__restrict); 27 | #endif 28 | bool background_thread_boot0(void); 29 | bool background_thread_boot1(tsdn_t *tsdn); 30 | 31 | #endif /* JEMALLOC_INTERNAL_BACKGROUND_THREAD_EXTERNS_H */ 32 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/base_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_BASE_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_BASE_EXTERNS_H 3 | 4 | extern metadata_thp_mode_t opt_metadata_thp; 5 | extern const char *metadata_thp_mode_names[]; 6 | 7 | base_t *b0get(void); 8 | base_t *base_new(tsdn_t *tsdn, unsigned ind, extent_hooks_t *extent_hooks); 9 | void base_delete(tsdn_t *tsdn, base_t *base); 10 | extent_hooks_t *base_extent_hooks_get(base_t *base); 11 | extent_hooks_t *base_extent_hooks_set(base_t *base, 12 | extent_hooks_t *extent_hooks); 13 | void *base_alloc(tsdn_t *tsdn, base_t *base, size_t size, size_t alignment); 14 | extent_t *base_alloc_extent(tsdn_t *tsdn, base_t *base); 15 | void base_stats_get(tsdn_t *tsdn, base_t *base, size_t *allocated, 16 | size_t *resident, size_t *mapped, size_t *n_thp); 17 | void base_prefork(tsdn_t *tsdn, base_t *base); 18 | void base_postfork_parent(tsdn_t *tsdn, base_t *base); 19 | void base_postfork_child(tsdn_t *tsdn, base_t *base); 20 | bool base_boot(tsdn_t *tsdn); 21 | 22 | #endif /* JEMALLOC_INTERNAL_BASE_EXTERNS_H */ 23 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/base_inlines.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_BASE_INLINES_H 2 | #define JEMALLOC_INTERNAL_BASE_INLINES_H 3 | 4 | static inline unsigned 5 | base_ind_get(const base_t *base) { 6 | return base->ind; 7 | } 8 | 9 | static inline bool 10 | metadata_thp_enabled(void) { 11 | return (opt_metadata_thp != metadata_thp_disabled); 12 | } 13 | #endif /* JEMALLOC_INTERNAL_BASE_INLINES_H */ 14 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/base_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_BASE_TYPES_H 2 | #define JEMALLOC_INTERNAL_BASE_TYPES_H 3 | 4 | typedef struct base_block_s base_block_t; 5 | typedef struct base_s base_t; 6 | 7 | #define METADATA_THP_DEFAULT metadata_thp_disabled 8 | 9 | /* 10 | * In auto mode, arenas switch to huge pages for the base allocator on the 11 | * second base block. a0 switches to thp on the 5th block (after 20 megabytes 12 | * of metadata), since more metadata (e.g. rtree nodes) come from a0's base. 13 | */ 14 | 15 | #define BASE_AUTO_THP_THRESHOLD 2 16 | #define BASE_AUTO_THP_THRESHOLD_A0 5 17 | 18 | typedef enum { 19 | metadata_thp_disabled = 0, 20 | /* 21 | * Lazily enable hugepage for metadata. To avoid high RSS caused by THP 22 | * + low usage arena (i.e. THP becomes a significant percentage), the 23 | * "auto" option only starts using THP after a base allocator used up 24 | * the first THP region. Starting from the second hugepage (in a single 25 | * arena), "auto" behaves the same as "always", i.e. madvise hugepage 26 | * right away. 27 | */ 28 | metadata_thp_auto = 1, 29 | metadata_thp_always = 2, 30 | metadata_thp_mode_limit = 3 31 | } metadata_thp_mode_t; 32 | 33 | #endif /* JEMALLOC_INTERNAL_BASE_TYPES_H */ 34 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/div.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_DIV_H 2 | #define JEMALLOC_INTERNAL_DIV_H 3 | 4 | #include "jemalloc/internal/assert.h" 5 | 6 | /* 7 | * This module does the division that computes the index of a region in a slab, 8 | * given its offset relative to the base. 9 | * That is, given a divisor d, an n = i * d (all integers), we'll return i. 10 | * We do some pre-computation to do this more quickly than a CPU division 11 | * instruction. 12 | * We bound n < 2^32, and don't support dividing by one. 13 | */ 14 | 15 | typedef struct div_info_s div_info_t; 16 | struct div_info_s { 17 | uint32_t magic; 18 | #ifdef JEMALLOC_DEBUG 19 | size_t d; 20 | #endif 21 | }; 22 | 23 | void div_init(div_info_t *div_info, size_t divisor); 24 | 25 | static inline size_t 26 | div_compute(div_info_t *div_info, size_t n) { 27 | assert(n <= (uint32_t)-1); 28 | /* 29 | * This generates, e.g. mov; imul; shr on x86-64. On a 32-bit machine, 30 | * the compilers I tried were all smart enough to turn this into the 31 | * appropriate "get the high 32 bits of the result of a multiply" (e.g. 32 | * mul; mov edx eax; on x86, umull on arm, etc.). 33 | */ 34 | size_t i = ((uint64_t)n * (uint64_t)div_info->magic) >> 32; 35 | #ifdef JEMALLOC_DEBUG 36 | assert(i * div_info->d == n); 37 | #endif 38 | return i; 39 | } 40 | 41 | #endif /* JEMALLOC_INTERNAL_DIV_H */ 42 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/extent_dss.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_EXTENT_DSS_H 2 | #define JEMALLOC_INTERNAL_EXTENT_DSS_H 3 | 4 | typedef enum { 5 | dss_prec_disabled = 0, 6 | dss_prec_primary = 1, 7 | dss_prec_secondary = 2, 8 | 9 | dss_prec_limit = 3 10 | } dss_prec_t; 11 | #define DSS_PREC_DEFAULT dss_prec_secondary 12 | #define DSS_DEFAULT "secondary" 13 | 14 | extern const char *dss_prec_names[]; 15 | 16 | extern const char *opt_dss; 17 | 18 | dss_prec_t extent_dss_prec_get(void); 19 | bool extent_dss_prec_set(dss_prec_t dss_prec); 20 | void *extent_alloc_dss(tsdn_t *tsdn, arena_t *arena, void *new_addr, 21 | size_t size, size_t alignment, bool *zero, bool *commit); 22 | bool extent_in_dss(void *addr); 23 | bool extent_dss_mergeable(void *addr_a, void *addr_b); 24 | void extent_dss_boot(void); 25 | 26 | #endif /* JEMALLOC_INTERNAL_EXTENT_DSS_H */ 27 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/extent_mmap.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_EXTENT_MMAP_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_EXTENT_MMAP_EXTERNS_H 3 | 4 | extern bool opt_retain; 5 | 6 | void *extent_alloc_mmap(void *new_addr, size_t size, size_t alignment, 7 | bool *zero, bool *commit); 8 | bool extent_dalloc_mmap(void *addr, size_t size); 9 | 10 | #endif /* JEMALLOC_INTERNAL_EXTENT_MMAP_EXTERNS_H */ 11 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/extent_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_EXTENT_TYPES_H 2 | #define JEMALLOC_INTERNAL_EXTENT_TYPES_H 3 | 4 | typedef struct extent_s extent_t; 5 | typedef struct extents_s extents_t; 6 | 7 | #define EXTENT_HOOKS_INITIALIZER NULL 8 | 9 | #define EXTENT_GROW_MAX_PIND (NPSIZES - 1) 10 | 11 | /* 12 | * When reuse (and split) an active extent, (1U << opt_lg_extent_max_active_fit) 13 | * is the max ratio between the size of the active extent and the new extent. 14 | */ 15 | #define LG_EXTENT_MAX_ACTIVE_FIT_DEFAULT 6 16 | 17 | #endif /* JEMALLOC_INTERNAL_EXTENT_TYPES_H */ 18 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/hooks.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_HOOKS_H 2 | #define JEMALLOC_INTERNAL_HOOKS_H 3 | 4 | extern JEMALLOC_EXPORT void (*hooks_arena_new_hook)(); 5 | extern JEMALLOC_EXPORT void (*hooks_libc_hook)(); 6 | 7 | #define JEMALLOC_HOOK(fn, hook) ((void)(hook != NULL && (hook(), 0)), fn) 8 | 9 | #define open JEMALLOC_HOOK(open, hooks_libc_hook) 10 | #define read JEMALLOC_HOOK(read, hooks_libc_hook) 11 | #define write JEMALLOC_HOOK(write, hooks_libc_hook) 12 | #define readlink JEMALLOC_HOOK(readlink, hooks_libc_hook) 13 | #define close JEMALLOC_HOOK(close, hooks_libc_hook) 14 | #define creat JEMALLOC_HOOK(creat, hooks_libc_hook) 15 | #define secure_getenv JEMALLOC_HOOK(secure_getenv, hooks_libc_hook) 16 | /* Note that this is undef'd and re-define'd in src/prof.c. */ 17 | #define _Unwind_Backtrace JEMALLOC_HOOK(_Unwind_Backtrace, hooks_libc_hook) 18 | 19 | #endif /* JEMALLOC_INTERNAL_HOOKS_H */ 20 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/jemalloc_internal_macros.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_MACROS_H 2 | #define JEMALLOC_INTERNAL_MACROS_H 3 | 4 | #ifdef JEMALLOC_DEBUG 5 | # define JEMALLOC_ALWAYS_INLINE static inline 6 | #else 7 | # define JEMALLOC_ALWAYS_INLINE JEMALLOC_ATTR(always_inline) static inline 8 | #endif 9 | #ifdef _MSC_VER 10 | # define inline _inline 11 | #endif 12 | 13 | #define UNUSED JEMALLOC_ATTR(unused) 14 | 15 | #define ZU(z) ((size_t)z) 16 | #define ZD(z) ((ssize_t)z) 17 | #define QU(q) ((uint64_t)q) 18 | #define QD(q) ((int64_t)q) 19 | 20 | #define KZU(z) ZU(z##ULL) 21 | #define KZD(z) ZD(z##LL) 22 | #define KQU(q) QU(q##ULL) 23 | #define KQD(q) QI(q##LL) 24 | 25 | #ifndef __DECONST 26 | # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 27 | #endif 28 | 29 | #if !defined(JEMALLOC_HAS_RESTRICT) || defined(__cplusplus) 30 | # define restrict 31 | #endif 32 | 33 | /* Various function pointers are statick and immutable except during testing. */ 34 | #ifdef JEMALLOC_JET 35 | # define JET_MUTABLE 36 | #else 37 | # define JET_MUTABLE const 38 | #endif 39 | 40 | #define JEMALLOC_VA_ARGS_HEAD(head, ...) head 41 | #define JEMALLOC_VA_ARGS_TAIL(head, ...) __VA_ARGS__ 42 | 43 | #endif /* JEMALLOC_INTERNAL_MACROS_H */ 44 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/large_externs.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_LARGE_EXTERNS_H 2 | #define JEMALLOC_INTERNAL_LARGE_EXTERNS_H 3 | 4 | void *large_malloc(tsdn_t *tsdn, arena_t *arena, size_t usize, bool zero); 5 | void *large_palloc(tsdn_t *tsdn, arena_t *arena, size_t usize, size_t alignment, 6 | bool zero); 7 | bool large_ralloc_no_move(tsdn_t *tsdn, extent_t *extent, size_t usize_min, 8 | size_t usize_max, bool zero); 9 | void *large_ralloc(tsdn_t *tsdn, arena_t *arena, extent_t *extent, size_t usize, 10 | size_t alignment, bool zero, tcache_t *tcache); 11 | 12 | typedef void (large_dalloc_junk_t)(void *, size_t); 13 | extern large_dalloc_junk_t *JET_MUTABLE large_dalloc_junk; 14 | 15 | typedef void (large_dalloc_maybe_junk_t)(void *, size_t); 16 | extern large_dalloc_maybe_junk_t *JET_MUTABLE large_dalloc_maybe_junk; 17 | 18 | void large_dalloc_prep_junked_locked(tsdn_t *tsdn, extent_t *extent); 19 | void large_dalloc_finish(tsdn_t *tsdn, extent_t *extent); 20 | void large_dalloc(tsdn_t *tsdn, extent_t *extent); 21 | size_t large_salloc(tsdn_t *tsdn, const extent_t *extent); 22 | prof_tctx_t *large_prof_tctx_get(tsdn_t *tsdn, const extent_t *extent); 23 | void large_prof_tctx_set(tsdn_t *tsdn, extent_t *extent, prof_tctx_t *tctx); 24 | void large_prof_tctx_reset(tsdn_t *tsdn, extent_t *extent); 25 | 26 | #endif /* JEMALLOC_INTERNAL_LARGE_EXTERNS_H */ 27 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/nstime.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_NSTIME_H 2 | #define JEMALLOC_INTERNAL_NSTIME_H 3 | 4 | /* Maximum supported number of seconds (~584 years). */ 5 | #define NSTIME_SEC_MAX KQU(18446744072) 6 | #define NSTIME_ZERO_INITIALIZER {0} 7 | 8 | typedef struct { 9 | uint64_t ns; 10 | } nstime_t; 11 | 12 | void nstime_init(nstime_t *time, uint64_t ns); 13 | void nstime_init2(nstime_t *time, uint64_t sec, uint64_t nsec); 14 | uint64_t nstime_ns(const nstime_t *time); 15 | uint64_t nstime_sec(const nstime_t *time); 16 | uint64_t nstime_msec(const nstime_t *time); 17 | uint64_t nstime_nsec(const nstime_t *time); 18 | void nstime_copy(nstime_t *time, const nstime_t *source); 19 | int nstime_compare(const nstime_t *a, const nstime_t *b); 20 | void nstime_add(nstime_t *time, const nstime_t *addend); 21 | void nstime_iadd(nstime_t *time, uint64_t addend); 22 | void nstime_subtract(nstime_t *time, const nstime_t *subtrahend); 23 | void nstime_isubtract(nstime_t *time, uint64_t subtrahend); 24 | void nstime_imultiply(nstime_t *time, uint64_t multiplier); 25 | void nstime_idivide(nstime_t *time, uint64_t divisor); 26 | uint64_t nstime_divide(const nstime_t *time, const nstime_t *divisor); 27 | 28 | typedef bool (nstime_monotonic_t)(void); 29 | extern nstime_monotonic_t *JET_MUTABLE nstime_monotonic; 30 | 31 | typedef bool (nstime_update_t)(nstime_t *); 32 | extern nstime_update_t *JET_MUTABLE nstime_update; 33 | 34 | #endif /* JEMALLOC_INTERNAL_NSTIME_H */ 35 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/private_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for symbol in `cat "$@"` ; do 4 | echo "#define ${symbol} JEMALLOC_N(${symbol})" 5 | done 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/private_symbols.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Generate private_symbols[_jet].awk. 4 | # 5 | # Usage: private_symbols.sh * 6 | # 7 | # is typically "" or "_". 8 | 9 | sym_prefix=$1 10 | shift 11 | 12 | cat <' output. 35 | # 36 | # Handle lines like: 37 | # 0000000000000008 D opt_junk 38 | # 0000000000007574 T malloc_initialized 39 | (NF == 3 && $2 ~ /^[ABCDGRSTVW]$/ && !($3 in exported_symbols) && $3 ~ /^[A-Za-z0-9_]+$/) { 40 | print substr($3, 1+length(sym_prefix), length($3)-length(sym_prefix)) 41 | } 42 | 43 | # Process 'dumpbin /SYMBOLS ' output. 44 | # 45 | # Handle lines like: 46 | # 353 00008098 SECT4 notype External | opt_junk 47 | # 3F1 00000000 SECT7 notype () External | malloc_initialized 48 | ($3 ~ /^SECT[0-9]+/ && $(NF-2) == "External" && !($NF in exported_symbols)) { 49 | print $NF 50 | } 51 | EOF 52 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/public_namespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#define je_${n} JEMALLOC_N(${n})" 6 | done 7 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/public_unnamespace.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | for nm in `cat $1` ; do 4 | n=`echo ${nm} |tr ':' ' ' |awk '{print $1}'` 5 | echo "#undef je_${n}" 6 | done 7 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/spin.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_SPIN_H 2 | #define JEMALLOC_INTERNAL_SPIN_H 3 | 4 | #define SPIN_INITIALIZER {0U} 5 | 6 | typedef struct { 7 | unsigned iteration; 8 | } spin_t; 9 | 10 | static inline void 11 | spin_cpu_spinwait() { 12 | # if HAVE_CPU_SPINWAIT 13 | CPU_SPINWAIT; 14 | # else 15 | volatile int x = 0; 16 | x = x; 17 | # endif 18 | } 19 | 20 | static inline void 21 | spin_adaptive(spin_t *spin) { 22 | volatile uint32_t i; 23 | 24 | if (spin->iteration < 5) { 25 | for (i = 0; i < (1U << spin->iteration); i++) { 26 | spin_cpu_spinwait(); 27 | } 28 | spin->iteration++; 29 | } else { 30 | #ifdef _WIN32 31 | SwitchToThread(); 32 | #else 33 | sched_yield(); 34 | #endif 35 | } 36 | } 37 | 38 | #undef SPIN_INLINE 39 | 40 | #endif /* JEMALLOC_INTERNAL_SPIN_H */ 41 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/stats.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_STATS_H 2 | #define JEMALLOC_INTERNAL_STATS_H 3 | 4 | /* OPTION(opt, var_name, default, set_value_to) */ 5 | #define STATS_PRINT_OPTIONS \ 6 | OPTION('J', json, false, true) \ 7 | OPTION('g', general, true, false) \ 8 | OPTION('m', merged, config_stats, false) \ 9 | OPTION('d', destroyed, config_stats, false) \ 10 | OPTION('a', unmerged, config_stats, false) \ 11 | OPTION('b', bins, true, false) \ 12 | OPTION('l', large, true, false) \ 13 | OPTION('x', mutex, true, false) 14 | 15 | enum { 16 | #define OPTION(o, v, d, s) stats_print_option_num_##v, 17 | STATS_PRINT_OPTIONS 18 | #undef OPTION 19 | stats_print_tot_num_options 20 | }; 21 | 22 | /* Options for stats_print. */ 23 | extern bool opt_stats_print; 24 | extern char opt_stats_print_opts[stats_print_tot_num_options+1]; 25 | 26 | /* Implements je_malloc_stats_print. */ 27 | void stats_print(void (*write_cb)(void *, const char *), void *cbopaque, 28 | const char *opts); 29 | 30 | #endif /* JEMALLOC_INTERNAL_STATS_H */ 31 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/tsd_malloc_thread_cleanup.h: -------------------------------------------------------------------------------- 1 | #ifdef JEMALLOC_INTERNAL_TSD_MALLOC_THREAD_CLEANUP_H 2 | #error This file should be included only once, by tsd.h. 3 | #endif 4 | #define JEMALLOC_INTERNAL_TSD_MALLOC_THREAD_CLEANUP_H 5 | 6 | extern __thread tsd_t tsd_tls; 7 | extern __thread bool tsd_initialized; 8 | extern bool tsd_booted; 9 | 10 | /* Initialization/cleanup. */ 11 | JEMALLOC_ALWAYS_INLINE bool 12 | tsd_cleanup_wrapper(void) { 13 | if (tsd_initialized) { 14 | tsd_initialized = false; 15 | tsd_cleanup(&tsd_tls); 16 | } 17 | return tsd_initialized; 18 | } 19 | 20 | JEMALLOC_ALWAYS_INLINE bool 21 | tsd_boot0(void) { 22 | malloc_tsd_cleanup_register(&tsd_cleanup_wrapper); 23 | tsd_booted = true; 24 | return false; 25 | } 26 | 27 | JEMALLOC_ALWAYS_INLINE void 28 | tsd_boot1(void) { 29 | /* Do nothing. */ 30 | } 31 | 32 | JEMALLOC_ALWAYS_INLINE bool 33 | tsd_boot(void) { 34 | return tsd_boot0(); 35 | } 36 | 37 | JEMALLOC_ALWAYS_INLINE bool 38 | tsd_booted_get(void) { 39 | return tsd_booted; 40 | } 41 | 42 | JEMALLOC_ALWAYS_INLINE bool 43 | tsd_get_allocates(void) { 44 | return false; 45 | } 46 | 47 | /* Get/set. */ 48 | JEMALLOC_ALWAYS_INLINE tsd_t * 49 | tsd_get(bool init) { 50 | assert(tsd_booted); 51 | return &tsd_tls; 52 | } 53 | JEMALLOC_ALWAYS_INLINE void 54 | tsd_set(tsd_t *val) { 55 | assert(tsd_booted); 56 | if (likely(&tsd_tls != val)) { 57 | tsd_tls = (*val); 58 | } 59 | tsd_initialized = true; 60 | } 61 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/tsd_tls.h: -------------------------------------------------------------------------------- 1 | #ifdef JEMALLOC_INTERNAL_TSD_TLS_H 2 | #error This file should be included only once, by tsd.h. 3 | #endif 4 | #define JEMALLOC_INTERNAL_TSD_TLS_H 5 | 6 | extern __thread tsd_t tsd_tls; 7 | extern pthread_key_t tsd_tsd; 8 | extern bool tsd_booted; 9 | 10 | /* Initialization/cleanup. */ 11 | JEMALLOC_ALWAYS_INLINE bool 12 | tsd_boot0(void) { 13 | if (pthread_key_create(&tsd_tsd, &tsd_cleanup) != 0) { 14 | return true; 15 | } 16 | tsd_booted = true; 17 | return false; 18 | } 19 | 20 | JEMALLOC_ALWAYS_INLINE void 21 | tsd_boot1(void) { 22 | /* Do nothing. */ 23 | } 24 | 25 | JEMALLOC_ALWAYS_INLINE bool 26 | tsd_boot(void) { 27 | return tsd_boot0(); 28 | } 29 | 30 | JEMALLOC_ALWAYS_INLINE bool 31 | tsd_booted_get(void) { 32 | return tsd_booted; 33 | } 34 | 35 | JEMALLOC_ALWAYS_INLINE bool 36 | tsd_get_allocates(void) { 37 | return false; 38 | } 39 | 40 | /* Get/set. */ 41 | JEMALLOC_ALWAYS_INLINE tsd_t * 42 | tsd_get(bool init) { 43 | assert(tsd_booted); 44 | return &tsd_tls; 45 | } 46 | 47 | JEMALLOC_ALWAYS_INLINE void 48 | tsd_set(tsd_t *val) { 49 | assert(tsd_booted); 50 | if (likely(&tsd_tls != val)) { 51 | tsd_tls = (*val); 52 | } 53 | if (pthread_setspecific(tsd_tsd, (void *)(&tsd_tls)) != 0) { 54 | malloc_write(": Error setting tsd.\n"); 55 | if (opt_abort) { 56 | abort(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/internal/tsd_types.h: -------------------------------------------------------------------------------- 1 | #ifndef JEMALLOC_INTERNAL_TSD_TYPES_H 2 | #define JEMALLOC_INTERNAL_TSD_TYPES_H 3 | 4 | #define MALLOC_TSD_CLEANUPS_MAX 2 5 | 6 | typedef struct tsd_s tsd_t; 7 | typedef struct tsdn_s tsdn_t; 8 | typedef bool (*malloc_tsd_cleanup_t)(void); 9 | 10 | #endif /* JEMALLOC_INTERNAL_TSD_TYPES_H */ 11 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/jemalloc/jemalloc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | objroot=$1 4 | 5 | cat < 5 | 6 | /* MSVC doesn't define _Bool or bool in C, but does have BOOL */ 7 | /* Note this doesn't pass autoconf's test because (bool) 0.5 != true */ 8 | /* Clang-cl uses MSVC headers, so needs msvc_compat, but has _Bool as 9 | * a built-in type. */ 10 | #ifndef __clang__ 11 | typedef BOOL _Bool; 12 | #endif 13 | 14 | #define bool _Bool 15 | #define true 1 16 | #define false 0 17 | 18 | #define __bool_true_false_are_defined 1 19 | 20 | #endif /* stdbool_h */ 21 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/msvc_compat/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef strings_h 2 | #define strings_h 3 | 4 | /* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided 5 | * for both */ 6 | #ifdef _MSC_VER 7 | # include 8 | # pragma intrinsic(_BitScanForward) 9 | static __forceinline int ffsl(long x) { 10 | unsigned long i; 11 | 12 | if (_BitScanForward(&i, x)) { 13 | return i + 1; 14 | } 15 | return 0; 16 | } 17 | 18 | static __forceinline int ffs(int x) { 19 | return ffsl(x); 20 | } 21 | 22 | # ifdef _M_X64 23 | # pragma intrinsic(_BitScanForward64) 24 | # endif 25 | 26 | static __forceinline int ffsll(unsigned __int64 x) { 27 | unsigned long i; 28 | #ifdef _M_X64 29 | if (_BitScanForward64(&i, x)) { 30 | return i + 1; 31 | } 32 | return 0; 33 | #else 34 | // Fallback for 32-bit build where 64-bit version not available 35 | // assuming little endian 36 | union { 37 | unsigned __int64 ll; 38 | unsigned long l[2]; 39 | } s; 40 | 41 | s.ll = x; 42 | 43 | if (_BitScanForward(&i, s.l[0])) { 44 | return i + 1; 45 | } else if(_BitScanForward(&i, s.l[1])) { 46 | return i + 33; 47 | } 48 | return 0; 49 | #endif 50 | } 51 | 52 | #else 53 | # define ffsll(x) __builtin_ffsll(x) 54 | # define ffsl(x) __builtin_ffsl(x) 55 | # define ffs(x) __builtin_ffs(x) 56 | #endif 57 | 58 | #endif /* strings_h */ 59 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/include/msvc_compat/windows_extra.h: -------------------------------------------------------------------------------- 1 | #ifndef MSVC_COMPAT_WINDOWS_EXTRA_H 2 | #define MSVC_COMPAT_WINDOWS_EXTRA_H 3 | 4 | #include 5 | 6 | #endif /* MSVC_COMPAT_WINDOWS_EXTRA_H */ 7 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/jemalloc.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | install_suffix=@install_suffix@ 6 | 7 | Name: jemalloc 8 | Description: A general purpose malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support. 9 | URL: http://jemalloc.net/ 10 | Version: @jemalloc_version@ 11 | Cflags: -I${includedir} 12 | Libs: -L${libdir} -ljemalloc${install_suffix} 13 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/msvc/ReadMe.txt: -------------------------------------------------------------------------------- 1 | 2 | How to build jemalloc for Windows 3 | ================================= 4 | 5 | 1. Install Cygwin with at least the following packages: 6 | * autoconf 7 | * autogen 8 | * gawk 9 | * grep 10 | * sed 11 | 12 | 2. Install Visual Studio 2015 or 2017 with Visual C++ 13 | 14 | 3. Add Cygwin\bin to the PATH environment variable 15 | 16 | 4. Open "x64 Native Tools Command Prompt for VS 2017" 17 | (note: x86/x64 doesn't matter at this point) 18 | 19 | 5. Generate header files: 20 | sh -c "CC=cl ./autogen.sh" 21 | 22 | 6. Now the project can be opened and built in Visual Studio: 23 | msvc\jemalloc_vc2017.sln 24 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/msvc/projects/vc2015/test_threads/test_threads.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | Source Files 19 | 20 | 21 | 22 | 23 | Header Files 24 | 25 | 26 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/msvc/projects/vc2017/test_threads/test_threads.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | Source Files 19 | 20 | 21 | 22 | 23 | Header Files 24 | 25 | 26 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/msvc/test_threads/test_threads.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int test_threads(); 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/msvc/test_threads/test_threads_main.cpp: -------------------------------------------------------------------------------- 1 | #include "test_threads.h" 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std::chrono_literals; 7 | 8 | int main(int argc, char** argv) { 9 | int rc = test_threads(); 10 | return rc; 11 | } 12 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/run_tests.sh: -------------------------------------------------------------------------------- 1 | $(dirname "$)")/scripts/gen_run_tests.py | bash 2 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/src/extent_mmap.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_EXTENT_MMAP_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" 4 | 5 | #include "jemalloc/internal/assert.h" 6 | #include "jemalloc/internal/extent_mmap.h" 7 | 8 | /******************************************************************************/ 9 | /* Data. */ 10 | 11 | bool opt_retain = 12 | #ifdef JEMALLOC_RETAIN 13 | true 14 | #else 15 | false 16 | #endif 17 | ; 18 | 19 | /******************************************************************************/ 20 | 21 | void * 22 | extent_alloc_mmap(void *new_addr, size_t size, size_t alignment, bool *zero, 23 | bool *commit) { 24 | void *ret = pages_map(new_addr, size, ALIGNMENT_CEILING(alignment, 25 | PAGE), commit); 26 | if (ret == NULL) { 27 | return NULL; 28 | } 29 | assert(ret != NULL); 30 | if (*commit) { 31 | *zero = true; 32 | } 33 | return ret; 34 | } 35 | 36 | bool 37 | extent_dalloc_mmap(void *addr, size_t size) { 38 | if (!opt_retain) { 39 | pages_unmap(addr, size); 40 | } 41 | return opt_retain; 42 | } 43 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/src/hash.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_HASH_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/src/hooks.c: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/jemalloc_preamble.h" 2 | 3 | /* 4 | * The hooks are a little bit screwy -- they're not genuinely exported in the 5 | * sense that we want them available to end-users, but we do want them visible 6 | * from outside the generated library, so that we can use them in test code. 7 | */ 8 | JEMALLOC_EXPORT 9 | void (*hooks_arena_new_hook)() = NULL; 10 | 11 | JEMALLOC_EXPORT 12 | void (*hooks_libc_hook)() = NULL; 13 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/src/mutex_pool.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_MUTEX_POOL_C_ 2 | 3 | #include "jemalloc/internal/jemalloc_preamble.h" 4 | #include "jemalloc/internal/jemalloc_internal_includes.h" 5 | 6 | #include "jemalloc/internal/mutex.h" 7 | #include "jemalloc/internal/mutex_pool.h" 8 | 9 | bool 10 | mutex_pool_init(mutex_pool_t *pool, const char *name, witness_rank_t rank) { 11 | for (int i = 0; i < MUTEX_POOL_SIZE; ++i) { 12 | if (malloc_mutex_init(&pool->mutexes[i], name, rank, 13 | malloc_mutex_address_ordered)) { 14 | return true; 15 | } 16 | } 17 | return false; 18 | } 19 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/src/prng.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_PRNG_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/src/ticker.c: -------------------------------------------------------------------------------- 1 | #define JEMALLOC_TICKER_C_ 2 | #include "jemalloc/internal/jemalloc_preamble.h" 3 | #include "jemalloc/internal/jemalloc_internal_includes.h" 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/include/test/btalloc.h: -------------------------------------------------------------------------------- 1 | /* btalloc() provides a mechanism for allocating via permuted backtraces. */ 2 | void *btalloc(size_t size, unsigned bits); 3 | 4 | #define btalloc_n_proto(n) \ 5 | void *btalloc_##n(size_t size, unsigned bits); 6 | btalloc_n_proto(0) 7 | btalloc_n_proto(1) 8 | 9 | #define btalloc_n_gen(n) \ 10 | void * \ 11 | btalloc_##n(size_t size, unsigned bits) { \ 12 | void *p; \ 13 | \ 14 | if (bits == 0) { \ 15 | p = mallocx(size, 0); \ 16 | } else { \ 17 | switch (bits & 0x1U) { \ 18 | case 0: \ 19 | p = (btalloc_0(size, bits >> 1)); \ 20 | break; \ 21 | case 1: \ 22 | p = (btalloc_1(size, bits >> 1)); \ 23 | break; \ 24 | default: not_reached(); \ 25 | } \ 26 | } \ 27 | /* Intentionally sabotage tail call optimization. */ \ 28 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); \ 29 | return p; \ 30 | } 31 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/include/test/jemalloc_test_defs.h.in: -------------------------------------------------------------------------------- 1 | #include "jemalloc/internal/jemalloc_internal_defs.h" 2 | #include "jemalloc/internal/jemalloc_internal_decls.h" 3 | 4 | /* 5 | * For use by SFMT. configure.ac doesn't actually define HAVE_SSE2 because its 6 | * dependencies are notoriously unportable in practice. 7 | */ 8 | #undef HAVE_SSE2 9 | #undef HAVE_ALTIVEC 10 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/include/test/mtx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * mtx is a slightly simplified version of malloc_mutex. This code duplication 3 | * is unfortunate, but there are allocator bootstrapping considerations that 4 | * would leak into the test infrastructure if malloc_mutex were used directly 5 | * in tests. 6 | */ 7 | 8 | typedef struct { 9 | #ifdef _WIN32 10 | CRITICAL_SECTION lock; 11 | #elif (defined(JEMALLOC_OS_UNFAIR_LOCK)) 12 | os_unfair_lock lock; 13 | #elif (defined(JEMALLOC_OSSPIN)) 14 | OSSpinLock lock; 15 | #else 16 | pthread_mutex_t lock; 17 | #endif 18 | } mtx_t; 19 | 20 | bool mtx_init(mtx_t *mtx); 21 | void mtx_fini(mtx_t *mtx); 22 | void mtx_lock(mtx_t *mtx); 23 | void mtx_unlock(mtx_t *mtx); 24 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/include/test/thd.h: -------------------------------------------------------------------------------- 1 | /* Abstraction layer for threading in tests. */ 2 | #ifdef _WIN32 3 | typedef HANDLE thd_t; 4 | #else 5 | typedef pthread_t thd_t; 6 | #endif 7 | 8 | void thd_create(thd_t *thd, void *(*proc)(void *), void *arg); 9 | void thd_join(thd_t thd, void **ret); 10 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/include/test/timer.h: -------------------------------------------------------------------------------- 1 | /* Simple timer, for use in benchmark reporting. */ 2 | 3 | typedef struct { 4 | nstime_t t0; 5 | nstime_t t1; 6 | } timedelta_t; 7 | 8 | void timer_start(timedelta_t *timer); 9 | void timer_stop(timedelta_t *timer); 10 | uint64_t timer_usec(const timedelta_t *timer); 11 | void timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen); 12 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/integration/extent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="junk:false" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/integration/mallocx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="junk:false" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/integration/sdallocx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define MAXALIGN (((size_t)1) << 22) 4 | #define NITER 3 5 | 6 | TEST_BEGIN(test_basic) { 7 | void *ptr = mallocx(64, 0); 8 | sdallocx(ptr, 64, 0); 9 | } 10 | TEST_END 11 | 12 | TEST_BEGIN(test_alignment_and_size) { 13 | size_t nsz, sz, alignment, total; 14 | unsigned i; 15 | void *ps[NITER]; 16 | 17 | for (i = 0; i < NITER; i++) { 18 | ps[i] = NULL; 19 | } 20 | 21 | for (alignment = 8; 22 | alignment <= MAXALIGN; 23 | alignment <<= 1) { 24 | total = 0; 25 | for (sz = 1; 26 | sz < 3 * alignment && sz < (1U << 31); 27 | sz += (alignment >> (LG_SIZEOF_PTR-1)) - 1) { 28 | for (i = 0; i < NITER; i++) { 29 | nsz = nallocx(sz, MALLOCX_ALIGN(alignment) | 30 | MALLOCX_ZERO); 31 | ps[i] = mallocx(sz, MALLOCX_ALIGN(alignment) | 32 | MALLOCX_ZERO); 33 | total += nsz; 34 | if (total >= (MAXALIGN << 1)) { 35 | break; 36 | } 37 | } 38 | for (i = 0; i < NITER; i++) { 39 | if (ps[i] != NULL) { 40 | sdallocx(ps[i], sz, 41 | MALLOCX_ALIGN(alignment)); 42 | ps[i] = NULL; 43 | } 44 | } 45 | } 46 | } 47 | } 48 | TEST_END 49 | 50 | int 51 | main(void) { 52 | return test_no_reentrancy( 53 | test_basic, 54 | test_alignment_and_size); 55 | } 56 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/integration/xallocx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="junk:false" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/src/btalloc.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | void * 4 | btalloc(size_t size, unsigned bits) { 5 | return btalloc_0(size, bits); 6 | } 7 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/src/btalloc_0.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | btalloc_n_gen(0) 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/src/btalloc_1.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | btalloc_n_gen(1) 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/src/math.c: -------------------------------------------------------------------------------- 1 | #define MATH_C_ 2 | #include "test/jemalloc_test.h" 3 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/src/mq.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | /* 4 | * Sleep for approximately ns nanoseconds. No lower *nor* upper bound on sleep 5 | * time is guaranteed. 6 | */ 7 | void 8 | mq_nanosleep(unsigned ns) { 9 | assert(ns <= 1000*1000*1000); 10 | 11 | #ifdef _WIN32 12 | Sleep(ns / 1000); 13 | #else 14 | { 15 | struct timespec timeout; 16 | 17 | if (ns < 1000*1000*1000) { 18 | timeout.tv_sec = 0; 19 | timeout.tv_nsec = ns; 20 | } else { 21 | timeout.tv_sec = 1; 22 | timeout.tv_nsec = 0; 23 | } 24 | nanosleep(&timeout, NULL); 25 | } 26 | #endif 27 | } 28 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/src/thd.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #ifdef _WIN32 4 | void 5 | thd_create(thd_t *thd, void *(*proc)(void *), void *arg) { 6 | LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc; 7 | *thd = CreateThread(NULL, 0, routine, arg, 0, NULL); 8 | if (*thd == NULL) { 9 | test_fail("Error in CreateThread()\n"); 10 | } 11 | } 12 | 13 | void 14 | thd_join(thd_t thd, void **ret) { 15 | if (WaitForSingleObject(thd, INFINITE) == WAIT_OBJECT_0 && ret) { 16 | DWORD exit_code; 17 | GetExitCodeThread(thd, (LPDWORD) &exit_code); 18 | *ret = (void *)(uintptr_t)exit_code; 19 | } 20 | } 21 | 22 | #else 23 | void 24 | thd_create(thd_t *thd, void *(*proc)(void *), void *arg) { 25 | if (pthread_create(thd, NULL, proc, arg) != 0) { 26 | test_fail("Error in pthread_create()\n"); 27 | } 28 | } 29 | 30 | void 31 | thd_join(thd_t thd, void **ret) { 32 | pthread_join(thd, ret); 33 | } 34 | #endif 35 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/src/timer.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | void 4 | timer_start(timedelta_t *timer) { 5 | nstime_init(&timer->t0, 0); 6 | nstime_update(&timer->t0); 7 | } 8 | 9 | void 10 | timer_stop(timedelta_t *timer) { 11 | nstime_copy(&timer->t1, &timer->t0); 12 | nstime_update(&timer->t1); 13 | } 14 | 15 | uint64_t 16 | timer_usec(const timedelta_t *timer) { 17 | nstime_t delta; 18 | 19 | nstime_copy(&delta, &timer->t1); 20 | nstime_subtract(&delta, &timer->t0); 21 | return nstime_ns(&delta) / 1000; 22 | } 23 | 24 | void 25 | timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) { 26 | uint64_t t0 = timer_usec(a); 27 | uint64_t t1 = timer_usec(b); 28 | uint64_t mult; 29 | size_t i = 0; 30 | size_t j, n; 31 | 32 | /* Whole. */ 33 | n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1); 34 | i += n; 35 | if (i >= buflen) { 36 | return; 37 | } 38 | mult = 1; 39 | for (j = 0; j < n; j++) { 40 | mult *= 10; 41 | } 42 | 43 | /* Decimal. */ 44 | n = malloc_snprintf(&buf[i], buflen-i, "."); 45 | i += n; 46 | 47 | /* Fraction. */ 48 | while (i < buflen-1) { 49 | uint64_t round = (i+1 == buflen-1 && ((t0 * mult * 10 / t1) % 10 50 | >= 5)) ? 1 : 0; 51 | n = malloc_snprintf(&buf[i], buflen-i, 52 | "%"FMTu64, (t0 * mult / t1) % 10 + round); 53 | i += n; 54 | mult *= 10; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/a0.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_a0) { 4 | void *p; 5 | 6 | p = a0malloc(1); 7 | assert_ptr_not_null(p, "Unexpected a0malloc() error"); 8 | a0dalloc(p); 9 | } 10 | TEST_END 11 | 12 | int 13 | main(void) { 14 | return test_no_malloc_init( 15 | test_a0); 16 | } 17 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/arena_reset_prof.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | #define ARENA_RESET_PROF_C_ 3 | 4 | #include "arena_reset.c" 5 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/arena_reset_prof.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export MALLOC_CONF="prof:true,lg_prof_sample:0" 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/background_thread_enable.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | const char *malloc_conf = "background_thread:false,narenas:1"; 4 | 5 | TEST_BEGIN(test_deferred) { 6 | test_skip_if(!have_background_thread); 7 | 8 | unsigned id; 9 | size_t sz_u = sizeof(unsigned); 10 | 11 | /* 12 | * 10 here is somewhat arbitrary, except insofar as we want to ensure 13 | * that the number of background threads is smaller than the number of 14 | * arenas. I'll ragequit long before we have to spin up 10 threads per 15 | * cpu to handle background purging, so this is a conservative 16 | * approximation. 17 | */ 18 | for (unsigned i = 0; i < 10 * ncpus; i++) { 19 | assert_d_eq(mallctl("arenas.create", &id, &sz_u, NULL, 0), 0, 20 | "Failed to create arena"); 21 | } 22 | 23 | bool enable = true; 24 | size_t sz_b = sizeof(bool); 25 | assert_d_eq(mallctl("background_thread", NULL, NULL, &enable, sz_b), 0, 26 | "Failed to enable background threads"); 27 | } 28 | TEST_END 29 | 30 | int 31 | main(void) { 32 | return test_no_reentrancy( 33 | test_deferred); 34 | } 35 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/decay.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export MALLOC_CONF="dirty_decay_ms:1000,muzzy_decay_ms:1000,lg_tcache_max:0" 4 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/div.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #include "jemalloc/internal/div.h" 4 | 5 | TEST_BEGIN(test_div_exhaustive) { 6 | for (size_t divisor = 2; divisor < 1000 * 1000; ++divisor) { 7 | div_info_t div_info; 8 | div_init(&div_info, divisor); 9 | size_t max = 1000 * divisor; 10 | if (max < 1000 * 1000) { 11 | max = 1000 * 1000; 12 | } 13 | for (size_t dividend = 0; dividend < 1000 * divisor; 14 | dividend += divisor) { 15 | size_t quotient = div_compute( 16 | &div_info, dividend); 17 | assert_zu_eq(dividend, quotient * divisor, 18 | "With divisor = %zu, dividend = %zu, " 19 | "got quotient %zu", divisor, dividend, quotient); 20 | } 21 | } 22 | } 23 | TEST_END 24 | 25 | int 26 | main(void) { 27 | return test_no_reentrancy( 28 | test_div_exhaustive); 29 | } 30 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/hooks.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static bool hook_called = false; 4 | 5 | static void 6 | hook() { 7 | hook_called = true; 8 | } 9 | 10 | static int 11 | func_to_hook(int arg1, int arg2) { 12 | return arg1 + arg2; 13 | } 14 | 15 | #define func_to_hook JEMALLOC_HOOK(func_to_hook, hooks_libc_hook) 16 | 17 | TEST_BEGIN(unhooked_call) { 18 | hooks_libc_hook = NULL; 19 | hook_called = false; 20 | assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value."); 21 | assert_false(hook_called, "Nulling out hook didn't take."); 22 | } 23 | TEST_END 24 | 25 | TEST_BEGIN(hooked_call) { 26 | hooks_libc_hook = &hook; 27 | hook_called = false; 28 | assert_d_eq(3, func_to_hook(1, 2), "Hooking changed return value."); 29 | assert_true(hook_called, "Hook should have executed."); 30 | } 31 | TEST_END 32 | 33 | int 34 | main(void) { 35 | return test( 36 | unhooked_call, 37 | hooked_call); 38 | } 39 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/junk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="abort:false,zero:false,junk:true" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/junk_alloc.c: -------------------------------------------------------------------------------- 1 | #include "junk.c" 2 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/junk_alloc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="abort:false,zero:false,junk:alloc" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/junk_free.c: -------------------------------------------------------------------------------- 1 | #include "junk.c" 2 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/junk_free.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="abort:false,zero:false,junk:free" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/mtx.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #define NTHREADS 2 4 | #define NINCRS 2000000 5 | 6 | TEST_BEGIN(test_mtx_basic) { 7 | mtx_t mtx; 8 | 9 | assert_false(mtx_init(&mtx), "Unexpected mtx_init() failure"); 10 | mtx_lock(&mtx); 11 | mtx_unlock(&mtx); 12 | mtx_fini(&mtx); 13 | } 14 | TEST_END 15 | 16 | typedef struct { 17 | mtx_t mtx; 18 | unsigned x; 19 | } thd_start_arg_t; 20 | 21 | static void * 22 | thd_start(void *varg) { 23 | thd_start_arg_t *arg = (thd_start_arg_t *)varg; 24 | unsigned i; 25 | 26 | for (i = 0; i < NINCRS; i++) { 27 | mtx_lock(&arg->mtx); 28 | arg->x++; 29 | mtx_unlock(&arg->mtx); 30 | } 31 | return NULL; 32 | } 33 | 34 | TEST_BEGIN(test_mtx_race) { 35 | thd_start_arg_t arg; 36 | thd_t thds[NTHREADS]; 37 | unsigned i; 38 | 39 | assert_false(mtx_init(&arg.mtx), "Unexpected mtx_init() failure"); 40 | arg.x = 0; 41 | for (i = 0; i < NTHREADS; i++) { 42 | thd_create(&thds[i], thd_start, (void *)&arg); 43 | } 44 | for (i = 0; i < NTHREADS; i++) { 45 | thd_join(thds[i], NULL); 46 | } 47 | assert_u_eq(arg.x, NTHREADS * NINCRS, 48 | "Race-related counter corruption"); 49 | } 50 | TEST_END 51 | 52 | int 53 | main(void) { 54 | return test( 55 | test_mtx_basic, 56 | test_mtx_race); 57 | } 58 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/pack.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Immediately purge to minimize fragmentation. 4 | export MALLOC_CONF="dirty_decay_ms:0,muzzy_decay_ms:0" 5 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/pages.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_pages_huge) { 4 | size_t alloc_size; 5 | bool commit; 6 | void *pages, *hugepage; 7 | 8 | alloc_size = HUGEPAGE * 2 - PAGE; 9 | commit = true; 10 | pages = pages_map(NULL, alloc_size, PAGE, &commit); 11 | assert_ptr_not_null(pages, "Unexpected pages_map() error"); 12 | 13 | if (thp_state_madvise) { 14 | hugepage = (void *)(ALIGNMENT_CEILING((uintptr_t)pages, HUGEPAGE)); 15 | assert_b_ne(pages_huge(hugepage, HUGEPAGE), have_madvise_huge, 16 | "Unexpected pages_huge() result"); 17 | assert_false(pages_nohuge(hugepage, HUGEPAGE), 18 | "Unexpected pages_nohuge() result"); 19 | } 20 | 21 | pages_unmap(pages, alloc_size); 22 | } 23 | TEST_END 24 | 25 | int 26 | main(void) { 27 | return test( 28 | test_pages_huge); 29 | } 30 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/prof_accum.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/prof_active.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_thread_active_init:false,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/prof_gdump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_active:false,prof_gdump:true" 5 | fi 6 | 7 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/prof_idump.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | static bool did_prof_dump_open; 4 | 5 | static int 6 | prof_dump_open_intercept(bool propagate_err, const char *filename) { 7 | int fd; 8 | 9 | did_prof_dump_open = true; 10 | 11 | fd = open("/dev/null", O_WRONLY); 12 | assert_d_ne(fd, -1, "Unexpected open() failure"); 13 | 14 | return fd; 15 | } 16 | 17 | TEST_BEGIN(test_idump) { 18 | bool active; 19 | void *p; 20 | 21 | test_skip_if(!config_prof); 22 | 23 | active = true; 24 | assert_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active, 25 | sizeof(active)), 0, 26 | "Unexpected mallctl failure while activating profiling"); 27 | 28 | prof_dump_open = prof_dump_open_intercept; 29 | 30 | did_prof_dump_open = false; 31 | p = mallocx(1, 0); 32 | assert_ptr_not_null(p, "Unexpected mallocx() failure"); 33 | dallocx(p, 0); 34 | assert_true(did_prof_dump_open, "Expected a profile dump"); 35 | } 36 | TEST_END 37 | 38 | int 39 | main(void) { 40 | return test( 41 | test_idump); 42 | } 43 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/prof_idump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export MALLOC_CONF="tcache:false" 4 | if [ "x${enable_prof}" = "x1" ] ; then 5 | export MALLOC_CONF="${MALLOC_CONF},prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0,lg_prof_interval:0" 6 | fi 7 | 8 | 9 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/prof_reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_active:false,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/prof_tctx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,lg_prof_sample:0" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/prof_thread_name.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_prof}" = "x1" ] ; then 4 | export MALLOC_CONF="prof:true,prof_active:false" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/slab.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | TEST_BEGIN(test_arena_slab_regind) { 4 | szind_t binind; 5 | 6 | for (binind = 0; binind < NBINS; binind++) { 7 | size_t regind; 8 | extent_t slab; 9 | const bin_info_t *bin_info = &bin_infos[binind]; 10 | extent_init(&slab, NULL, mallocx(bin_info->slab_size, 11 | MALLOCX_LG_ALIGN(LG_PAGE)), bin_info->slab_size, true, 12 | binind, 0, extent_state_active, false, true, true); 13 | assert_ptr_not_null(extent_addr_get(&slab), 14 | "Unexpected malloc() failure"); 15 | for (regind = 0; regind < bin_info->nregs; regind++) { 16 | void *reg = (void *)((uintptr_t)extent_addr_get(&slab) + 17 | (bin_info->reg_size * regind)); 18 | assert_zu_eq(arena_slab_regind(&slab, binind, reg), 19 | regind, 20 | "Incorrect region index computed for size %zu", 21 | bin_info->reg_size); 22 | } 23 | free(extent_addr_get(&slab)); 24 | } 25 | } 26 | TEST_END 27 | 28 | int 29 | main(void) { 30 | return test( 31 | test_arena_slab_regind); 32 | } 33 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/spin.c: -------------------------------------------------------------------------------- 1 | #include "test/jemalloc_test.h" 2 | 3 | #include "jemalloc/internal/spin.h" 4 | 5 | TEST_BEGIN(test_spin) { 6 | spin_t spinner = SPIN_INITIALIZER; 7 | 8 | for (unsigned i = 0; i < 100; i++) { 9 | spin_adaptive(&spinner); 10 | } 11 | } 12 | TEST_END 13 | 14 | int 15 | main(void) { 16 | return test( 17 | test_spin); 18 | } 19 | -------------------------------------------------------------------------------- /skynet/3rd/jemalloc/test/unit/zero.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "x${enable_fill}" = "x1" ] ; then 4 | export MALLOC_CONF="abort:false,junk:false,zero:true" 5 | fi 6 | -------------------------------------------------------------------------------- /skynet/3rd/lpeg/lpcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcap.h,v 1.2 2015/02/27 17:13:17 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcap_h) 6 | #define lpcap_h 7 | 8 | 9 | #include "lptypes.h" 10 | 11 | 12 | /* kinds of captures */ 13 | typedef enum CapKind { 14 | Cclose, Cposition, Cconst, Cbackref, Carg, Csimple, Ctable, Cfunction, 15 | Cquery, Cstring, Cnum, Csubst, Cfold, Cruntime, Cgroup 16 | } CapKind; 17 | 18 | 19 | typedef struct Capture { 20 | const char *s; /* subject position */ 21 | unsigned short idx; /* extra info (group name, arg index, etc.) */ 22 | byte kind; /* kind of capture */ 23 | byte siz; /* size of full capture + 1 (0 = not a full capture) */ 24 | } Capture; 25 | 26 | 27 | typedef struct CapState { 28 | Capture *cap; /* current capture */ 29 | Capture *ocap; /* (original) capture list */ 30 | lua_State *L; 31 | int ptop; /* index of last argument to 'match' */ 32 | const char *s; /* original string */ 33 | int valuecached; /* value stored in cache slot */ 34 | } CapState; 35 | 36 | 37 | int runtimecap (CapState *cs, Capture *close, const char *s, int *rem); 38 | int getcaptures (lua_State *L, const char *s, const char *r, int ptop); 39 | int finddyncap (Capture *cap, Capture *last); 40 | 41 | #endif 42 | 43 | 44 | -------------------------------------------------------------------------------- /skynet/3rd/lpeg/lpcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpcode.h,v 1.7 2015/06/12 18:24:45 roberto Exp $ 3 | */ 4 | 5 | #if !defined(lpcode_h) 6 | #define lpcode_h 7 | 8 | #include "lua.h" 9 | 10 | #include "lptypes.h" 11 | #include "lptree.h" 12 | #include "lpvm.h" 13 | 14 | int tocharset (TTree *tree, Charset *cs); 15 | int checkaux (TTree *tree, int pred); 16 | int fixedlenx (TTree *tree, int count, int len); 17 | int hascaptures (TTree *tree); 18 | int lp_gc (lua_State *L); 19 | Instruction *compile (lua_State *L, Pattern *p); 20 | void realloccode (lua_State *L, Pattern *p, int nsize); 21 | int sizei (const Instruction *i); 22 | 23 | 24 | #define PEnullable 0 25 | #define PEnofail 1 26 | 27 | /* 28 | ** nofail(t) implies that 't' cannot fail with any input 29 | */ 30 | #define nofail(t) checkaux(t, PEnofail) 31 | 32 | /* 33 | ** (not nullable(t)) implies 't' cannot match without consuming 34 | ** something 35 | */ 36 | #define nullable(t) checkaux(t, PEnullable) 37 | 38 | #define fixedlen(t) fixedlenx(t, 0, 0) 39 | 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /skynet/3rd/lpeg/lpeg-128.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/snowolder/RoundGameServer/8c1141c58f388ab7431aad1e8c5ef70715b98803/skynet/3rd/lpeg/lpeg-128.gif -------------------------------------------------------------------------------- /skynet/3rd/lpeg/lpprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lpprint.h,v 1.2 2015/06/12 18:18:08 roberto Exp $ 3 | */ 4 | 5 | 6 | #if !defined(lpprint_h) 7 | #define lpprint_h 8 | 9 | 10 | #include "lptree.h" 11 | #include "lpvm.h" 12 | 13 | 14 | #if defined(LPEG_DEBUG) 15 | 16 | void printpatt (Instruction *p, int n); 17 | void printtree (TTree *tree, int ident); 18 | void printktable (lua_State *L, int idx); 19 | void printcharset (const byte *st); 20 | void printcaplist (Capture *cap, Capture *limit); 21 | void printinst (const Instruction *op, const Instruction *p); 22 | 23 | #else 24 | 25 | #define printktable(L,idx) \ 26 | luaL_error(L, "function only implemented in debug mode") 27 | #define printtree(tree,i) \ 28 | luaL_error(L, "function only implemented in debug mode") 29 | #define printpatt(p,n) \ 30 | luaL_error(L, "function only implemented in debug mode") 31 | 32 | #endif 33 | 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /skynet/3rd/lpeg/makefile: -------------------------------------------------------------------------------- 1 | LIBNAME = lpeg 2 | LUADIR = ../lua/ 3 | 4 | COPT = -O2 5 | # COPT = -DLPEG_DEBUG -g 6 | 7 | CWARNS = -Wall -Wextra -pedantic \ 8 | -Waggregate-return \ 9 | -Wcast-align \ 10 | -Wcast-qual \ 11 | -Wdisabled-optimization \ 12 | -Wpointer-arith \ 13 | -Wshadow \ 14 | -Wsign-compare \ 15 | -Wundef \ 16 | -Wwrite-strings \ 17 | -Wbad-function-cast \ 18 | -Wdeclaration-after-statement \ 19 | -Wmissing-prototypes \ 20 | -Wnested-externs \ 21 | -Wstrict-prototypes \ 22 | # -Wunreachable-code \ 23 | 24 | 25 | CFLAGS = $(CWARNS) $(COPT) -std=c99 -I$(LUADIR) -fPIC 26 | CC = gcc 27 | 28 | FILES = lpvm.o lpcap.o lptree.o lpcode.o lpprint.o 29 | 30 | # For Linux 31 | linux: 32 | make lpeg.so "DLLFLAGS = -shared -fPIC" 33 | 34 | # For Mac OS 35 | macosx: 36 | make lpeg.so "DLLFLAGS = -bundle -undefined dynamic_lookup" 37 | 38 | lpeg.so: $(FILES) 39 | env $(CC) $(DLLFLAGS) $(FILES) -o lpeg.so 40 | 41 | $(FILES): makefile 42 | 43 | test: test.lua re.lua lpeg.so 44 | ./test.lua 45 | 46 | clean: 47 | rm -f $(FILES) lpeg.so 48 | 49 | 50 | lpcap.o: lpcap.c lpcap.h lptypes.h 51 | lpcode.o: lpcode.c lptypes.h lpcode.h lptree.h lpvm.h lpcap.h 52 | lpprint.o: lpprint.c lptypes.h lpprint.h lptree.h lpvm.h lpcap.h 53 | lptree.o: lptree.c lptypes.h lpcap.h lpcode.h lptree.h lpvm.h lpprint.h 54 | lpvm.o: lpvm.c lpcap.h lptypes.h lpvm.h lpprint.h lptree.h 55 | 56 | -------------------------------------------------------------------------------- /skynet/3rd/lua-md5/README: -------------------------------------------------------------------------------- 1 | MD5 - Cryptographic Library for Lua 2 | Copyright 2003 PUC-Rio 3 | http://www.keplerproject.org/md5 4 | 5 | MD5 offers basic cryptographic facilities for Lua 5.1: a hash (digest) 6 | function, a pair crypt/decrypt based on MD5 and CFB, and a pair crypt/decrypt based 7 | on DES with 56-bit keys. 8 | 9 | MD5 current version is 1.1.2. 10 | 11 | This version is copy from https://github.com/keplerproject/md5 12 | 13 | -------------------------------------------------------------------------------- /skynet/3rd/lua-md5/compat-5.2.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | #include "lauxlib.h" 3 | #include "compat-5.2.h" 4 | 5 | #if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501 6 | /* 7 | ** Adapted from Lua 5.2.0 8 | */ 9 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { 10 | luaL_checkstack(L, nup+1, "too many upvalues"); 11 | for (; l->name != NULL; l++) { /* fill the table with given functions */ 12 | int i; 13 | lua_pushstring(L, l->name); 14 | for (i = 0; i < nup; i++) /* copy upvalues to the top */ 15 | lua_pushvalue(L, -(nup + 1)); 16 | lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ 17 | lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */ 18 | } 19 | lua_pop(L, nup); /* remove upvalues */ 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /skynet/3rd/lua-md5/compat-5.2.h: -------------------------------------------------------------------------------- 1 | #if !defined LUA_VERSION_NUM 2 | /* Lua 5.0 */ 3 | #define luaL_Reg luaL_reg 4 | 5 | #define luaL_addchar(B,c) \ 6 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ 7 | (*(B)->p++ = (char)(c))) 8 | #endif 9 | 10 | #if LUA_VERSION_NUM==501 11 | /* Lua 5.1 */ 12 | #define lua_rawlen lua_objlen 13 | #endif 14 | 15 | void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); 16 | -------------------------------------------------------------------------------- /skynet/3rd/lua-md5/md5.h: -------------------------------------------------------------------------------- 1 | /** 2 | * $Id: md5.h,v 1.2 2006/03/03 15:04:49 tomas Exp $ 3 | * Cryptographic module for Lua. 4 | * @author Roberto Ierusalimschy 5 | */ 6 | 7 | 8 | #ifndef md5_h 9 | #define md5_h 10 | 11 | #include 12 | 13 | 14 | #define HASHSIZE 16 15 | 16 | void md5 (const char *message, long len, char *output); 17 | int luaopen_md5_core (lua_State *L); 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /skynet/3rd/lua/README: -------------------------------------------------------------------------------- 1 | This is a modify version of lua 5.3.2 (http://www.lua.org/ftp/lua-5.3.2.tar.gz) . 2 | 3 | For detail , 4 | Shared Proto : http://lua-users.org/lists/lua-l/2014-03/msg00489.html 5 | Shared short string table : http://blog.codingnow.com/2015/08/lua_vm_share_string.html 6 | Signal for debug use : http://blog.codingnow.com/2015/03/skynet_signal.html 7 | -------------------------------------------------------------------------------- /skynet/3rd/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /skynet/3rd/lua/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h,v 1.2 2014/12/29 16:54:13 roberto Exp $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /skynet/3rd/lua/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /skynet/3rd/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h,v 1.45 2015/09/08 15:41:05 roberto Exp $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | #define MYINT(s) (s[0]-'0') 22 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 23 | #define LUAC_FORMAT 0 /* this is the official format */ 24 | 25 | /* load one chunk; from lundump.c */ 26 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 27 | 28 | /* dump one chunk; from ldump.c */ 29 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 30 | void* data, int strip); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /skynet/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2012-2015 codingnow.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /skynet/README.md: -------------------------------------------------------------------------------- 1 | ## Skynet 2 | 3 | Skynet is a lightweight online game framework, and it can be used in many other fields. 4 | 5 | ## Build 6 | 7 | For Linux, install autoconf first for jemalloc: 8 | 9 | ``` 10 | git clone https://github.com/cloudwu/skynet.git 11 | cd skynet 12 | make 'PLATFORM' # PLATFORM can be linux, macosx, freebsd now 13 | ``` 14 | 15 | Or you can: 16 | 17 | ``` 18 | export PLAT=linux 19 | make 20 | ``` 21 | 22 | For FreeBSD , use gmake instead of make. 23 | 24 | ## Test 25 | 26 | Run these in different consoles: 27 | 28 | ``` 29 | ./skynet examples/config # Launch first skynet node (Gate server) and a skynet-master (see config for standalone option) 30 | ./3rd/lua/lua examples/client.lua # Launch a client, and try to input hello. 31 | ``` 32 | 33 | ## About Lua version 34 | 35 | Skynet now uses a modified version of lua 5.3.3 ( https://github.com/ejoy/lua/tree/skynet ) for multiple lua states. 36 | 37 | You can also use official Lua versions, just edit the Makefile by yourself. 38 | 39 | ## How To Use (Sorry, Only in Chinese now) 40 | 41 | * Read Wiki for documents https://github.com/cloudwu/skynet/wiki 42 | * The FAQ in wiki https://github.com/cloudwu/skynet/wiki/FAQ 43 | -------------------------------------------------------------------------------- /skynet/examples/abort.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | require "skynet.manager" -- import skynet.abort 3 | 4 | skynet.abort() 5 | -------------------------------------------------------------------------------- /skynet/examples/checkdeadloop.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local list = {} 4 | 5 | local function timeout_check(ti) 6 | if not next(list) then 7 | return 8 | end 9 | skynet.sleep(ti) -- sleep 10 sec 10 | for k,v in pairs(list) do 11 | skynet.error("timout",ti,k,v) 12 | end 13 | end 14 | 15 | skynet.start(function() 16 | skynet.error("ping all") 17 | local list_ret = skynet.call(".launcher", "lua", "LIST") 18 | for addr, desc in pairs(list_ret) do 19 | list[addr] = desc 20 | skynet.fork(function() 21 | skynet.call(addr,"debug","INFO") 22 | list[addr] = nil 23 | end) 24 | end 25 | skynet.sleep(0) 26 | timeout_check(100) 27 | timeout_check(400) 28 | timeout_check(500) 29 | skynet.exit() 30 | end) 31 | -------------------------------------------------------------------------------- /skynet/examples/cluster1.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local cluster = require "cluster" 3 | local snax = require "snax" 4 | 5 | skynet.start(function() 6 | local sdb = skynet.newservice("simpledb") 7 | -- register name "sdb" for simpledb, you can use cluster.query() later. 8 | -- See cluster2.lua 9 | cluster.register("sdb", sdb) 10 | 11 | print(skynet.call(sdb, "lua", "SET", "a", "foobar")) 12 | print(skynet.call(sdb, "lua", "SET", "b", "foobar2")) 13 | print(skynet.call(sdb, "lua", "GET", "a")) 14 | print(skynet.call(sdb, "lua", "GET", "b")) 15 | cluster.open "db" 16 | cluster.open "db2" 17 | -- unique snax service 18 | snax.uniqueservice "pingserver" 19 | end) 20 | -------------------------------------------------------------------------------- /skynet/examples/cluster2.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local cluster = require "cluster" 3 | 4 | skynet.start(function() 5 | -- query name "sdb" of cluster db. 6 | local sdb = cluster.query("db", "sdb") 7 | print("db.sbd=",sdb) 8 | local proxy = cluster.proxy("db", sdb) 9 | local largekey = string.rep("X", 128*1024) 10 | local largevalue = string.rep("R", 100 * 1024) 11 | print(skynet.call(proxy, "lua", "SET", largekey, largevalue)) 12 | local v = skynet.call(proxy, "lua", "GET", largekey) 13 | assert(largevalue == v) 14 | 15 | print(cluster.call("db", sdb, "GET", "a")) 16 | print(cluster.call("db2", sdb, "GET", "b")) 17 | 18 | -- test snax service 19 | local pingserver = cluster.snax("db", "pingserver") 20 | print(pingserver.req.ping "hello") 21 | end) 22 | -------------------------------------------------------------------------------- /skynet/examples/clustername.lua: -------------------------------------------------------------------------------- 1 | db = "127.0.0.1:2528" 2 | db2 = "127.0.0.1:2529" 3 | -------------------------------------------------------------------------------- /skynet/examples/config: -------------------------------------------------------------------------------- 1 | root = "./" 2 | thread = 8 3 | logger = nil 4 | logpath = "." 5 | harbor = 1 6 | address = "127.0.0.1:2526" 7 | master = "127.0.0.1:2013" 8 | start = "main" -- main script 9 | bootstrap = "snlua bootstrap" -- The service for bootstrap 10 | standalone = "0.0.0.0:2013" 11 | luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua" 12 | lualoader = root .. "lualib/loader.lua" 13 | lua_path = root.."lualib/?.lua;"..root.."lualib/?/init.lua" 14 | lua_cpath = root .. "luaclib/?.so" 15 | -- preload = "./examples/preload.lua" -- run preload.lua before every lua service run 16 | snax = root.."examples/?.lua;"..root.."test/?.lua" 17 | -- snax_interface_g = "snax_g" 18 | cpath = root.."cservice/?.so" 19 | -- daemon = "./skynet.pid" 20 | -------------------------------------------------------------------------------- /skynet/examples/config.c1: -------------------------------------------------------------------------------- 1 | thread = 8 2 | logger = nil 3 | harbor = 0 4 | start = "cluster1" 5 | bootstrap = "snlua bootstrap" -- The service for bootstrap 6 | luaservice = "./service/?.lua;./test/?.lua;./examples/?.lua" 7 | lualoader = "lualib/loader.lua" 8 | cpath = "./cservice/?.so" 9 | cluster = "./examples/clustername.lua" 10 | snax = "./test/?.lua" 11 | -------------------------------------------------------------------------------- /skynet/examples/config.c2: -------------------------------------------------------------------------------- 1 | thread = 8 2 | logger = nil 3 | harbor = 0 4 | start = "cluster2" 5 | bootstrap = "snlua bootstrap" -- The service for bootstrap 6 | luaservice = "./service/?.lua;./test/?.lua;./examples/?.lua" 7 | lualoader = "lualib/loader.lua" 8 | cpath = "./cservice/?.so" 9 | cluster = "./examples/clustername.lua" 10 | snax = "./test/?.lua" 11 | -------------------------------------------------------------------------------- /skynet/examples/config.login: -------------------------------------------------------------------------------- 1 | thread = 8 2 | logger = nil 3 | harbor = 0 4 | start = "main" 5 | bootstrap = "snlua bootstrap" -- The service for bootstrap 6 | luaservice = "./service/?.lua;./examples/login/?.lua" 7 | lualoader = "lualib/loader.lua" 8 | cpath = "./cservice/?.so" 9 | -------------------------------------------------------------------------------- /skynet/examples/config.mc: -------------------------------------------------------------------------------- 1 | root = "./" 2 | thread = 8 3 | logger = nil 4 | harbor = 2 5 | address = "127.0.0.1:2527" 6 | master = "127.0.0.1:2013" 7 | start = "testmulticast2" -- main script 8 | bootstrap = "snlua bootstrap" -- The service for bootstrap 9 | --standalone = "0.0.0.0:2013" 10 | luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua" 11 | lualoader = "lualib/loader.lua" 12 | -- preload = "./examples/preload.lua" -- run preload.lua before every lua service run 13 | snax = root.."examples/?.lua;"..root.."test/?.lua" 14 | cpath = root.."cservice/?.so" 15 | -------------------------------------------------------------------------------- /skynet/examples/config.mysql: -------------------------------------------------------------------------------- 1 | root = "./" 2 | thread = 8 3 | logger = nil 4 | harbor = 0 5 | start = "main_mysql" -- main script 6 | bootstrap = "snlua bootstrap" -- The service for bootstrap 7 | luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua" 8 | lualoader = "lualib/loader.lua" 9 | snax = root.."examples/?.lua;"..root.."test/?.lua" 10 | cpath = root.."cservice/?.so" 11 | -- daemon = "./skynet.pid" 12 | -------------------------------------------------------------------------------- /skynet/examples/config.userlog: -------------------------------------------------------------------------------- 1 | root = "./" 2 | thread = 8 3 | logger = "userlog" 4 | logservice = "snlua" 5 | logpath = "." 6 | harbor = 0 7 | start = "main" -- main script 8 | bootstrap = "snlua bootstrap" -- The service for bootstrap 9 | luaservice = root.."service/?.lua;"..root.."test/?.lua;"..root.."examples/?.lua" 10 | lualoader = "lualib/loader.lua" 11 | -- preload = "./examples/preload.lua" -- run preload.lua before every lua service run 12 | snax = root.."examples/?.lua;"..root.."test/?.lua" 13 | -- snax_interface_g = "snax_g" 14 | cpath = root.."cservice/?.so" 15 | -- daemon = "./skynet.pid" 16 | -------------------------------------------------------------------------------- /skynet/examples/config_log: -------------------------------------------------------------------------------- 1 | thread = 8 2 | mqueue = 256 3 | cpath = "./cservice/?.so" 4 | logger = nil 5 | harbor = 2 6 | address = "127.0.0.1:2527" 7 | master = "127.0.0.1:2013" 8 | start = "main_log" 9 | luaservice ="./service/?.lua;./test/?.lua;./examples/?.lua" 10 | snax = "./examples/?.lua;./test/?.lua" 11 | -------------------------------------------------------------------------------- /skynet/examples/globallog.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | require "skynet.manager" -- import skynet.register 3 | 4 | skynet.start(function() 5 | skynet.dispatch("lua", function(session, address, ...) 6 | print("[GLOBALLOG]", skynet.address(address), ...) 7 | end) 8 | skynet.register ".log" 9 | skynet.register "LOG" 10 | end) 11 | -------------------------------------------------------------------------------- /skynet/examples/injectlaunch.lua: -------------------------------------------------------------------------------- 1 | if not _P then 2 | print[[ 3 | This file is examples to show how to inject code into lua service. 4 | It is used to inject into launcher service to change the command.LAUNCH to command.LOGLAUNCH. 5 | telnet the debug_console service (nc 127.0.0.1 8000), and run: 6 | inject 3 examples/injectlaunch.lua -- 3 means launcher service 7 | ]] 8 | return 9 | end 10 | local command = _P.lua.command 11 | 12 | if command.RAWLAUNCH then 13 | command.LAUNCH, command.RAWLAUNCH = command.RAWLAUNCH 14 | print "restore command.LAUNCH" 15 | else 16 | command.RAWLAUNCH = command.LAUNCH 17 | command.LAUNCH = command.LOGLAUNCH 18 | print "replace command.LAUNCH" 19 | end 20 | -------------------------------------------------------------------------------- /skynet/examples/login/main.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | skynet.start(function() 4 | local loginserver = skynet.newservice("logind") 5 | local gate = skynet.newservice("gated", loginserver) 6 | 7 | skynet.call(gate, "lua", "open" , { 8 | port = 8888, 9 | maxclient = 64, 10 | servername = "sample", 11 | }) 12 | end) 13 | -------------------------------------------------------------------------------- /skynet/examples/login/msgagent.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | skynet.register_protocol { 4 | name = "client", 5 | id = skynet.PTYPE_CLIENT, 6 | unpack = skynet.tostring, 7 | } 8 | 9 | local gate 10 | local userid, subid 11 | 12 | local CMD = {} 13 | 14 | function CMD.login(source, uid, sid, secret) 15 | -- you may use secret to make a encrypted data stream 16 | skynet.error(string.format("%s is login", uid)) 17 | gate = source 18 | userid = uid 19 | subid = sid 20 | -- you may load user data from database 21 | end 22 | 23 | local function logout() 24 | if gate then 25 | skynet.call(gate, "lua", "logout", userid, subid) 26 | end 27 | skynet.exit() 28 | end 29 | 30 | function CMD.logout(source) 31 | -- NOTICE: The logout MAY be reentry 32 | skynet.error(string.format("%s is logout", userid)) 33 | logout() 34 | end 35 | 36 | function CMD.afk(source) 37 | -- the connection is broken, but the user may back 38 | skynet.error(string.format("AFK")) 39 | end 40 | 41 | skynet.start(function() 42 | -- If you want to fork a work thread , you MUST do it in CMD.login 43 | skynet.dispatch("lua", function(session, source, command, ...) 44 | local f = assert(CMD[command]) 45 | skynet.ret(skynet.pack(f(source, ...))) 46 | end) 47 | 48 | skynet.dispatch("client", function(_,_, msg) 49 | -- the simple echo service 50 | skynet.sleep(10) -- sleep a while 51 | skynet.ret(msg) 52 | end) 53 | end) 54 | -------------------------------------------------------------------------------- /skynet/examples/main.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local sprotoloader = require "sprotoloader" 3 | 4 | local max_client = 64 5 | 6 | skynet.start(function() 7 | skynet.error("Server start") 8 | skynet.uniqueservice("protoloader") 9 | if not skynet.getenv "daemon" then 10 | local console = skynet.newservice("console") 11 | end 12 | skynet.newservice("debug_console",8000) 13 | skynet.newservice("simpledb") 14 | local watchdog = skynet.newservice("watchdog") 15 | skynet.call(watchdog, "lua", "start", { 16 | port = 8888, 17 | maxclient = max_client, 18 | nodelay = true, 19 | }) 20 | skynet.error("Watchdog listen on", 8888) 21 | skynet.exit() 22 | end) 23 | -------------------------------------------------------------------------------- /skynet/examples/main_log.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local harbor = require "skynet.harbor" 3 | require "skynet.manager" -- import skynet.monitor 4 | 5 | local function monitor_master() 6 | harbor.linkmaster() 7 | print("master is down") 8 | skynet.exit() 9 | end 10 | 11 | skynet.start(function() 12 | print("Log server start") 13 | skynet.monitor "simplemonitor" 14 | local log = skynet.newservice("globallog") 15 | skynet.fork(monitor_master) 16 | end) 17 | 18 | -------------------------------------------------------------------------------- /skynet/examples/main_mysql.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | 4 | skynet.start(function() 5 | print("Main Server start") 6 | local console = skynet.newservice("testmysql") 7 | 8 | print("Main Server exit") 9 | skynet.exit() 10 | end) 11 | -------------------------------------------------------------------------------- /skynet/examples/preload.lua: -------------------------------------------------------------------------------- 1 | -- This file will execute before every lua service start 2 | -- See config 3 | 4 | print("PRELOAD", ...) 5 | 6 | -------------------------------------------------------------------------------- /skynet/examples/proto.lua: -------------------------------------------------------------------------------- 1 | local sprotoparser = require "sprotoparser" 2 | 3 | local proto = {} 4 | 5 | proto.c2s = sprotoparser.parse [[ 6 | .package { 7 | type 0 : integer 8 | session 1 : integer 9 | } 10 | 11 | handshake 1 { 12 | response { 13 | msg 0 : string 14 | } 15 | } 16 | 17 | get 2 { 18 | request { 19 | what 0 : string 20 | } 21 | response { 22 | result 0 : string 23 | } 24 | } 25 | 26 | set 3 { 27 | request { 28 | what 0 : string 29 | value 1 : string 30 | } 31 | } 32 | 33 | quit 4 {} 34 | 35 | ]] 36 | 37 | proto.s2c = sprotoparser.parse [[ 38 | .package { 39 | type 0 : integer 40 | session 1 : integer 41 | } 42 | 43 | heartbeat 1 {} 44 | ]] 45 | 46 | return proto 47 | -------------------------------------------------------------------------------- /skynet/examples/protoloader.lua: -------------------------------------------------------------------------------- 1 | -- module proto as examples/proto.lua 2 | package.path = "./examples/?.lua;" .. package.path 3 | 4 | local skynet = require "skynet" 5 | local sprotoparser = require "sprotoparser" 6 | local sprotoloader = require "sprotoloader" 7 | local proto = require "proto" 8 | 9 | skynet.start(function() 10 | sprotoloader.save(proto.c2s, 1) 11 | sprotoloader.save(proto.s2c, 2) 12 | -- don't call skynet.exit() , because sproto.core may unload and the global slot become invalid 13 | end) 14 | -------------------------------------------------------------------------------- /skynet/examples/simpledb.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | require "skynet.manager" -- import skynet.register 3 | local db = {} 4 | 5 | local command = {} 6 | 7 | function command.GET(key) 8 | return db[key] 9 | end 10 | 11 | function command.SET(key, value) 12 | local last = db[key] 13 | db[key] = value 14 | return last 15 | end 16 | 17 | skynet.start(function() 18 | skynet.dispatch("lua", function(session, address, cmd, ...) 19 | local f = command[string.upper(cmd)] 20 | if f then 21 | skynet.ret(skynet.pack(f(...))) 22 | else 23 | error(string.format("Unknown command %s", tostring(cmd))) 24 | end 25 | end) 26 | skynet.register "SIMPLEDB" 27 | end) 28 | -------------------------------------------------------------------------------- /skynet/examples/simplemonitor.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | -- It's a simple service exit monitor, you can do something more when a service exit. 4 | 5 | local service_map = {} 6 | 7 | skynet.register_protocol { 8 | name = "client", 9 | id = skynet.PTYPE_CLIENT, -- PTYPE_CLIENT = 3 10 | unpack = function() end, 11 | dispatch = function(_, address) 12 | local w = service_map[address] 13 | if w then 14 | for watcher in pairs(w) do 15 | skynet.redirect(watcher, address, "error", 0, "") 16 | end 17 | service_map[address] = false 18 | end 19 | end 20 | } 21 | 22 | local function monitor(session, watcher, command, service) 23 | assert(command, "WATCH") 24 | local w = service_map[service] 25 | if not w then 26 | if w == false then 27 | skynet.ret(skynet.pack(false)) 28 | return 29 | end 30 | w = {} 31 | service_map[service] = w 32 | end 33 | w[watcher] = true 34 | skynet.ret(skynet.pack(true)) 35 | end 36 | 37 | skynet.start(function() 38 | skynet.dispatch("lua", monitor) 39 | end) 40 | -------------------------------------------------------------------------------- /skynet/examples/userlog.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | require "skynet.manager" 3 | 4 | skynet.register_protocol { 5 | name = "text", 6 | id = skynet.PTYPE_TEXT, 7 | unpack = skynet.tostring, 8 | dispatch = function(_, address, msg) 9 | print(string.format(":%08x(%.2f): %s", address, skynet.time(), msg)) 10 | end 11 | } 12 | 13 | skynet.register_protocol { 14 | name = "SYSTEM", 15 | id = skynet.PTYPE_SYSTEM, 16 | unpack = function(...) return ... end, 17 | dispatch = function() 18 | -- reopen signal 19 | print("SIGHUP") 20 | end 21 | } 22 | 23 | skynet.start(function() 24 | skynet.register ".logger" 25 | end) -------------------------------------------------------------------------------- /skynet/lualib-src/lua-memory.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "malloc_hook.h" 5 | #include "luashrtbl.h" 6 | 7 | static int 8 | ltotal(lua_State *L) { 9 | size_t t = malloc_used_memory(); 10 | lua_pushinteger(L, (lua_Integer)t); 11 | 12 | return 1; 13 | } 14 | 15 | static int 16 | lblock(lua_State *L) { 17 | size_t t = malloc_memory_block(); 18 | lua_pushinteger(L, (lua_Integer)t); 19 | 20 | return 1; 21 | } 22 | 23 | static int 24 | ldumpinfo(lua_State *L) { 25 | memory_info_dump(); 26 | 27 | return 0; 28 | } 29 | 30 | static int 31 | ldump(lua_State *L) { 32 | dump_c_mem(); 33 | 34 | return 0; 35 | } 36 | 37 | static int 38 | lexpandshrtbl(lua_State *L) { 39 | int n = luaL_checkinteger(L, 1); 40 | luaS_expandshr(n); 41 | return 0; 42 | } 43 | 44 | static int 45 | lcurrent(lua_State *L) { 46 | lua_pushinteger(L, malloc_current_memory()); 47 | return 1; 48 | } 49 | 50 | int 51 | luaopen_memory(lua_State *L) { 52 | luaL_checkversion(L); 53 | 54 | luaL_Reg l[] = { 55 | { "total", ltotal }, 56 | { "block", lblock }, 57 | { "dumpinfo", ldumpinfo }, 58 | { "dump", ldump }, 59 | { "info", dump_mem_lua }, 60 | { "ssinfo", luaS_shrinfo }, 61 | { "ssexpand", lexpandshrtbl }, 62 | { "current", lcurrent }, 63 | { NULL, NULL }, 64 | }; 65 | 66 | luaL_newlib(L,l); 67 | 68 | return 1; 69 | } 70 | -------------------------------------------------------------------------------- /skynet/lualib-src/lua-seri.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_SERIALIZE_H 2 | #define LUA_SERIALIZE_H 3 | 4 | #include 5 | 6 | int luaseri_pack(lua_State *L); 7 | int luaseri_unpack(lua_State *L); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /skynet/lualib-src/sproto/README: -------------------------------------------------------------------------------- 1 | Check https://github.com/cloudwu/sproto for more 2 | -------------------------------------------------------------------------------- /skynet/lualib-src/sproto/msvcint.h: -------------------------------------------------------------------------------- 1 | #ifndef msvc_int_h 2 | #define msvc_int_h 3 | 4 | #ifdef _MSC_VER 5 | # define inline __inline 6 | # ifndef _MSC_STDINT_H_ 7 | # if (_MSC_VER < 1300) 8 | typedef signed char int8_t; 9 | typedef signed short int16_t; 10 | typedef signed int int32_t; 11 | typedef unsigned char uint8_t; 12 | typedef unsigned short uint16_t; 13 | typedef unsigned int uint32_t; 14 | # else 15 | typedef signed __int8 int8_t; 16 | typedef signed __int16 int16_t; 17 | typedef signed __int32 int32_t; 18 | typedef unsigned __int8 uint8_t; 19 | typedef unsigned __int16 uint16_t; 20 | typedef unsigned __int32 uint32_t; 21 | # endif 22 | typedef signed __int64 int64_t; 23 | typedef unsigned __int64 uint64_t; 24 | # endif 25 | 26 | #else 27 | 28 | #include 29 | 30 | #endif 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /skynet/lualib-src/timingwheel/twheel.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _TWHEEL_H_ 3 | #define _TWHEEL_H_ 4 | 5 | #include 6 | 7 | #define TIME_NEAR_SHIFT 8 8 | #define TIME_NEAR (1 << TIME_NEAR_SHIFT) 9 | #define TIME_NEAR_MASK (TIME_NEAR - 1) 10 | #define TIME_FAR_SHIFT 6 11 | #define TIME_FAR (1 << TIME_FAR_SHIFT) 12 | #define TIME_FAR_MASK (TIME_FAR - 1) 13 | #define MAX_DELAY_TIME (8 * 24 * 3600 * 1000) 14 | #define MAX_TIME (((uint64_t)1 << 32) - MAX_DELAY_TIME - 1) 15 | 16 | #define LOCK(X) while (__sync_lock_test_and_set(&((X)->lock),1)) {} 17 | #define UNLOCK(X) __sync_lock_release(&((X)->lock)) 18 | 19 | typedef void (*TimeFunc) (void* arg); 20 | 21 | struct TimeCallback { 22 | TimeFunc func; 23 | void* arg; 24 | }; 25 | 26 | struct TimeNode { 27 | uint32_t time; 28 | struct TimeCallback callback; 29 | struct TimeNode* next; 30 | }; 31 | 32 | struct TimeList { 33 | struct TimeNode head; 34 | struct TimeNode* tail; 35 | }; 36 | 37 | struct TimeWheel { 38 | uint32_t lock; 39 | uint32_t curr_time; 40 | uint64_t start_time; 41 | struct TimeList near[TIME_NEAR]; 42 | struct TimeList far[4][TIME_FAR]; 43 | }; 44 | 45 | 46 | //user interface 47 | 48 | void 49 | timewheel_create(uint64_t t); 50 | 51 | void 52 | timewheel_add_time(TimeFunc func, void* arg, uint32_t t); 53 | 54 | void 55 | timewheel_update(uint64_t t); 56 | 57 | uint64_t 58 | timewheel_gettime(); 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /skynet/lualib/datacenter.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local datacenter = {} 4 | 5 | function datacenter.get(...) 6 | return skynet.call("DATACENTER", "lua", "QUERY", ...) 7 | end 8 | 9 | function datacenter.set(...) 10 | return skynet.call("DATACENTER", "lua", "UPDATE", ...) 11 | end 12 | 13 | function datacenter.wait(...) 14 | return skynet.call("DATACENTER", "lua", "WAIT", ...) 15 | end 16 | 17 | return datacenter 18 | 19 | -------------------------------------------------------------------------------- /skynet/lualib/http/url.lua: -------------------------------------------------------------------------------- 1 | local url = {} 2 | 3 | local function decode_func(c) 4 | return string.char(tonumber(c, 16)) 5 | end 6 | 7 | local function decode(str) 8 | local str = str:gsub('+', ' ') 9 | return str:gsub("%%(..)", decode_func) 10 | end 11 | 12 | function url.parse(u) 13 | local path,query = u:match "([^?]*)%??(.*)" 14 | if path then 15 | path = decode(path) 16 | end 17 | return path, query 18 | end 19 | 20 | function url.parse_query(q) 21 | local r = {} 22 | for k,v in q:gmatch "(.-)=([^&]*)&?" do 23 | r[decode(k)] = decode(v) 24 | end 25 | return r 26 | end 27 | 28 | return url 29 | -------------------------------------------------------------------------------- /skynet/lualib/loader.lua: -------------------------------------------------------------------------------- 1 | local args = {} 2 | for word in string.gmatch(..., "%S+") do 3 | table.insert(args, word) 4 | end 5 | 6 | SERVICE_NAME = args[1] 7 | 8 | local main, pattern 9 | 10 | local err = {} 11 | for pat in string.gmatch(LUA_SERVICE, "([^;]+);*") do 12 | local filename = string.gsub(pat, "?", SERVICE_NAME) 13 | local f, msg = loadfile(filename) 14 | if not f then 15 | table.insert(err, msg) 16 | else 17 | pattern = pat 18 | main = f 19 | break 20 | end 21 | end 22 | 23 | if not main then 24 | error(table.concat(err, "\n")) 25 | end 26 | 27 | LUA_SERVICE = nil 28 | package.path , LUA_PATH = LUA_PATH 29 | package.cpath , LUA_CPATH = LUA_CPATH 30 | 31 | local service_path = string.match(pattern, "(.*/)[^/?]+$") 32 | 33 | if service_path then 34 | service_path = string.gsub(service_path, "?", args[1]) 35 | package.path = service_path .. "?.lua;" .. package.path 36 | SERVICE_PATH = service_path 37 | else 38 | local p = string.match(pattern, "(.*/).+$") 39 | SERVICE_PATH = p 40 | end 41 | 42 | if LUA_PRELOAD then 43 | local f = assert(loadfile(LUA_PRELOAD)) 44 | f(table.unpack(args)) 45 | LUA_PRELOAD = nil 46 | end 47 | 48 | main(select(2, table.unpack(args))) 49 | -------------------------------------------------------------------------------- /skynet/lualib/md5.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------- 2 | -- Modify version from https://github.com/keplerproject/md5 3 | ---------------------------------------------------------------------------- 4 | 5 | local core = require "md5.core" 6 | 7 | ---------------------------------------------------------------------------- 8 | -- @param k String with original message. 9 | -- @return String with the md5 hash value converted to hexadecimal digits 10 | 11 | function core.sumhexa (k) 12 | k = core.sum(k) 13 | return (string.gsub(k, ".", function (c) 14 | return string.format("%02x", string.byte(c)) 15 | end)) 16 | end 17 | 18 | local function get_ipad(c) 19 | return string.char(c:byte() ~ 0x36) 20 | end 21 | 22 | local function get_opad(c) 23 | return string.char(c:byte() ~ 0x5c) 24 | end 25 | 26 | function core.hmacmd5(data,key) 27 | if #key>64 then 28 | key=core.sum(key) 29 | key=key:sub(1,16) 30 | end 31 | local ipad_s=key:gsub(".", get_ipad)..string.rep("6",64-#key) 32 | local opad_s=key:gsub(".", get_opad)..string.rep("\\",64-#key) 33 | local istr=core.sum(ipad_s..data) 34 | local ostr=core.sumhexa(opad_s..istr) 35 | return ostr 36 | end 37 | 38 | return core 39 | -------------------------------------------------------------------------------- /skynet/lualib/sharedata.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local sd = require "sharedata.corelib" 3 | 4 | local service 5 | 6 | skynet.init(function() 7 | service = skynet.uniqueservice "sharedatad" 8 | end) 9 | 10 | local sharedata = {} 11 | 12 | local function monitor(name, obj, cobj) 13 | local newobj = cobj 14 | while true do 15 | newobj = skynet.call(service, "lua", "monitor", name, newobj) 16 | if newobj == nil then 17 | break 18 | end 19 | sd.update(obj, newobj) 20 | end 21 | end 22 | 23 | function sharedata.query(name) 24 | local obj = skynet.call(service, "lua", "query", name) 25 | local r = sd.box(obj) 26 | skynet.send(service, "lua", "confirm" , obj) 27 | skynet.fork(monitor,name, r, obj) 28 | return r 29 | end 30 | 31 | function sharedata.new(name, v, ...) 32 | skynet.call(service, "lua", "new", name, v, ...) 33 | end 34 | 35 | function sharedata.update(name, v, ...) 36 | skynet.call(service, "lua", "update", name, v, ...) 37 | end 38 | 39 | function sharedata.delete(name) 40 | skynet.call(service, "lua", "delete", name) 41 | end 42 | 43 | return sharedata 44 | -------------------------------------------------------------------------------- /skynet/lualib/skynet/harbor.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local harbor = {} 4 | 5 | function harbor.globalname(name, handle) 6 | handle = handle or skynet.self() 7 | skynet.send(".cslave", "lua", "REGISTER", name, handle) 8 | end 9 | 10 | function harbor.queryname(name) 11 | return skynet.call(".cslave", "lua", "QUERYNAME", name) 12 | end 13 | 14 | function harbor.link(id) 15 | skynet.call(".cslave", "lua", "LINK", id) 16 | end 17 | 18 | function harbor.connect(id) 19 | skynet.call(".cslave", "lua", "CONNECT", id) 20 | end 21 | 22 | function harbor.linkmaster() 23 | skynet.call(".cslave", "lua", "LINKMASTER") 24 | end 25 | 26 | return harbor 27 | -------------------------------------------------------------------------------- /skynet/lualib/skynet/queue.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local coroutine = coroutine 3 | local xpcall = xpcall 4 | local traceback = debug.traceback 5 | local table = table 6 | 7 | function skynet.queue() 8 | local current_thread 9 | local ref = 0 10 | local thread_queue = {} 11 | 12 | local function xpcall_ret(ok, ...) 13 | ref = ref - 1 14 | if ref == 0 then 15 | current_thread = table.remove(thread_queue,1) 16 | if current_thread then 17 | skynet.wakeup(current_thread) 18 | end 19 | end 20 | assert(ok, (...)) 21 | return ... 22 | end 23 | 24 | return function(f, ...) 25 | local thread = coroutine.running() 26 | if current_thread and current_thread ~= thread then 27 | table.insert(thread_queue, thread) 28 | skynet.wait() 29 | assert(ref == 0) -- current_thread == thread 30 | end 31 | current_thread = thread 32 | 33 | ref = ref + 1 34 | return xpcall_ret(xpcall(f, traceback, ...)) 35 | end 36 | end 37 | 38 | return skynet.queue 39 | -------------------------------------------------------------------------------- /skynet/lualib/sprotoloader.lua: -------------------------------------------------------------------------------- 1 | local parser = require "sprotoparser" 2 | local core = require "sproto.core" 3 | local sproto = require "sproto" 4 | 5 | local loader = {} 6 | 7 | function loader.register(filename, index) 8 | local f = assert(io.open(filename), "Can't open sproto file") 9 | local data = f:read "a" 10 | f:close() 11 | local sp = core.newproto(parser.parse(data)) 12 | core.saveproto(sp, index) 13 | end 14 | 15 | function loader.save(bin, index) 16 | local sp = core.newproto(bin) 17 | core.saveproto(sp, index) 18 | end 19 | 20 | function loader.load(index) 21 | local sp = core.loadproto(index) 22 | -- no __gc in metatable 23 | return sproto.sharenew(sp) 24 | end 25 | 26 | return loader 27 | 28 | -------------------------------------------------------------------------------- /skynet/pbc/alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOBUF_C_ALLOC_H 2 | #define PROTOBUF_C_ALLOC_H 3 | 4 | #include 5 | #include 6 | 7 | void * _pbcM_malloc(size_t sz); 8 | void _pbcM_free(void *p); 9 | void * _pbcM_realloc(void *p, size_t sz); 10 | void _pbcM_memory(); 11 | 12 | struct heap; 13 | 14 | struct heap * _pbcH_new(int pagesize); 15 | void _pbcH_delete(struct heap *); 16 | void* _pbcH_alloc(struct heap *, int size); 17 | 18 | #define HMALLOC(size) ((h) ? _pbcH_alloc(h, size) : _pbcM_malloc(size)) 19 | 20 | #define malloc _pbcM_malloc 21 | #define free _pbcM_free 22 | #define realloc _pbcM_realloc 23 | #define memory _pbcM_memory 24 | 25 | #ifdef _WIN32 26 | 27 | #include 28 | 29 | #endif 30 | 31 | #ifdef _MSC_VER 32 | 33 | #define alloca _alloca 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /skynet/pbc/array.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOBUF_C_ARRAY_H 2 | #define PROTOBUF_C_ARRAY_H 3 | 4 | #include "varint.h" 5 | #include "pbc.h" 6 | #include "alloc.h" 7 | 8 | typedef union _pbc_var { 9 | struct longlong integer; 10 | double real; 11 | struct { 12 | const char * str; 13 | int len; 14 | } s; 15 | struct { 16 | int id; 17 | const char * name; 18 | } e; 19 | struct pbc_slice m; 20 | void * p[2]; 21 | } pbc_var[1]; 22 | 23 | void _pbcA_open(pbc_array); 24 | void _pbcA_open_heap(pbc_array, struct heap *h); 25 | void _pbcA_close(pbc_array); 26 | 27 | void _pbcA_push(pbc_array, pbc_var var); 28 | void _pbcA_index(pbc_array , int idx, pbc_var var); 29 | void * _pbcA_index_p(pbc_array _array, int idx); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /skynet/pbc/binding/lua/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -O2 -fPIC -Wall 3 | LUADIR = /usr/local/include 4 | TARGET = protobuf.so 5 | 6 | .PHONY : all clean 7 | 8 | all : $(TARGET) 9 | 10 | $(TARGET) : pbc-lua.c 11 | $(CC) $(CFLAGS) -shared -o $@ -I../.. -I$(LUADIR) -L../../build $^ -lpbc 12 | 13 | clean : 14 | rm -f $(TARGET) 15 | -------------------------------------------------------------------------------- /skynet/pbc/binding/lua/test.lua: -------------------------------------------------------------------------------- 1 | require "protobuf" 2 | 3 | addr = io.open("../../build/addressbook.pb","rb") 4 | buffer = addr:read "*a" 5 | addr:close() 6 | 7 | protobuf.register(buffer) 8 | 9 | t = protobuf.decode("google.protobuf.FileDescriptorSet", buffer) 10 | 11 | proto = t.file[1] 12 | 13 | print(proto.name) 14 | print(proto.package) 15 | 16 | message = proto.message_type 17 | 18 | for _,v in ipairs(message) do 19 | print(v.name) 20 | for _,v in ipairs(v.field) do 21 | print("\t".. v.name .. " ["..v.number.."] " .. v.label) 22 | end 23 | end 24 | 25 | addressbook = { 26 | name = "Alice", 27 | id = 12345, 28 | phone = { 29 | { number = "1301234567" }, 30 | { number = "87654321", type = "WORK" }, 31 | } 32 | } 33 | 34 | code = protobuf.encode("tutorial.Person", addressbook) 35 | 36 | decode = protobuf.decode("tutorial.Person" , code) 37 | 38 | print(decode.name) 39 | print(decode.id) 40 | for _,v in ipairs(decode.phone) do 41 | print("\t"..v.number, v.type) 42 | end 43 | 44 | phonebuf = protobuf.pack("tutorial.Person.PhoneNumber number","87654321") 45 | buffer = protobuf.pack("tutorial.Person name id phone", "Alice", 123, { phonebuf }) 46 | print(protobuf.unpack("tutorial.Person name id phone", buffer)) 47 | -------------------------------------------------------------------------------- /skynet/pbc/binding/lua/test2.lua: -------------------------------------------------------------------------------- 1 | local protobuf = require "protobuf" 2 | 3 | addr = io.open("../../build/addressbook.pb","rb") 4 | buffer = addr:read "*a" 5 | addr:close() 6 | protobuf.register(buffer) 7 | 8 | local person = { 9 | name = "Alice", 10 | id = 123, 11 | phone = { 12 | { number = "123456789" , type = "MOBILE" }, 13 | { number = "87654321" , type = "HOME" }, 14 | } 15 | } 16 | 17 | local buffer = protobuf.encode("tutorial.Person", person) 18 | 19 | local t = protobuf.decode("tutorial.Person", buffer) 20 | 21 | for k,v in pairs(t) do 22 | if type(k) == "string" then 23 | print(k,v) 24 | end 25 | end 26 | 27 | print(t.phone[2].type) 28 | 29 | for k,v in pairs(t.phone[1]) do 30 | print(k,v) 31 | end 32 | 33 | -------------------------------------------------------------------------------- /skynet/pbc/binding/lua53/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | CFLAGS = -O2 -fPIC -Wall 3 | LUADIR = /usr/local/include 4 | TARGET = protobuf.so 5 | 6 | .PHONY : all clean 7 | 8 | all : $(TARGET) 9 | 10 | $(TARGET) : pbc-lua53.c 11 | $(CC) $(CFLAGS) -shared -o $@ -I../.. -I$(LUADIR) -L../../build $^ -lpbc 12 | 13 | clean : 14 | rm -f $(TARGET) 15 | -------------------------------------------------------------------------------- /skynet/pbc/binding/lua53/test.lua: -------------------------------------------------------------------------------- 1 | local protobuf = require "protobuf" 2 | 3 | addr = io.open("../../build/addressbook.pb","rb") 4 | buffer = addr:read "*a" 5 | addr:close() 6 | 7 | protobuf.register(buffer) 8 | 9 | t = protobuf.decode("google.protobuf.FileDescriptorSet", buffer) 10 | 11 | proto = t.file[1] 12 | 13 | print(proto.name) 14 | print(proto.package) 15 | 16 | message = proto.message_type 17 | 18 | for _,v in ipairs(message) do 19 | print(v.name) 20 | for _,v in ipairs(v.field) do 21 | print("\t".. v.name .. " ["..v.number.."] " .. v.label) 22 | end 23 | end 24 | 25 | addressbook = { 26 | name = "Alice", 27 | id = 12345, 28 | phone = { 29 | { number = "1301234567" }, 30 | { number = "87654321", type = "WORK" }, 31 | } 32 | } 33 | 34 | code = protobuf.encode("tutorial.Person", addressbook) 35 | 36 | decode = protobuf.decode("tutorial.Person" , code) 37 | 38 | print(decode.name) 39 | print(decode.id) 40 | for _,v in ipairs(decode.phone) do 41 | print("\t"..v.number, v.type) 42 | end 43 | 44 | phonebuf = protobuf.pack("tutorial.Person.PhoneNumber number","87654321") 45 | buffer = protobuf.pack("tutorial.Person name id phone", "Alice", 123, { phonebuf }) 46 | print(protobuf.unpack("tutorial.Person name id phone", buffer)) 47 | -------------------------------------------------------------------------------- /skynet/pbc/bootstrap.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOBUF_C_BOOTSTRAP_H 2 | #define PROTOBUF_C_BOOTSTRAP_H 3 | 4 | #include "proto.h" 5 | #include "pbc.h" 6 | 7 | void _pbcB_init(struct pbc_env *); 8 | void _pbcB_register_fields(struct pbc_env *, pbc_array queue); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/alloc.d: -------------------------------------------------------------------------------- 1 | build/o/alloc.o: alloc.c 2 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/array.d: -------------------------------------------------------------------------------- 1 | build/o/array.o: array.c pbc.h array.h varint.h alloc.h 2 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/bootstrap.d: -------------------------------------------------------------------------------- 1 | build/o/bootstrap.o: bootstrap.c pbc.h map.h alloc.h context.h array.h \ 2 | varint.h pattern.h proto.h bootstrap.h stringpool.h descriptor.pbc.h 3 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/context.d: -------------------------------------------------------------------------------- 1 | build/o/context.o: context.c pbc.h alloc.h varint.h context.h array.h 2 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/decode.d: -------------------------------------------------------------------------------- 1 | build/o/decode.o: decode.c pbc.h alloc.h context.h array.h varint.h \ 2 | proto.h map.h 3 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/map.d: -------------------------------------------------------------------------------- 1 | build/o/map.o: map.c map.h alloc.h 2 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/pattern.d: -------------------------------------------------------------------------------- 1 | build/o/pattern.o: pattern.c alloc.h context.h array.h varint.h pbc.h \ 2 | pattern.h proto.h map.h 3 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/proto.d: -------------------------------------------------------------------------------- 1 | build/o/proto.o: proto.c pbc.h proto.h map.h alloc.h array.h varint.h \ 2 | pattern.h context.h stringpool.h bootstrap.h 3 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/register.d: -------------------------------------------------------------------------------- 1 | build/o/register.o: register.c pbc.h proto.h map.h alloc.h array.h \ 2 | varint.h bootstrap.h context.h stringpool.h 3 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/rmessage.d: -------------------------------------------------------------------------------- 1 | build/o/rmessage.o: rmessage.c pbc.h alloc.h map.h context.h array.h \ 2 | varint.h proto.h pattern.h 3 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/stringpool.d: -------------------------------------------------------------------------------- 1 | build/o/stringpool.o: stringpool.c alloc.h 2 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/varint.d: -------------------------------------------------------------------------------- 1 | build/o/varint.o: varint.c varint.h pbc.h 2 | -------------------------------------------------------------------------------- /skynet/pbc/build/o/wmessage.d: -------------------------------------------------------------------------------- 1 | build/o/wmessage.o: wmessage.c pbc.h context.h array.h varint.h alloc.h \ 2 | map.h proto.h 3 | -------------------------------------------------------------------------------- /skynet/pbc/map.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOBUF_C_MAP_H 2 | #define PROTOBUF_C_MAP_H 3 | 4 | #include "alloc.h" 5 | 6 | struct map_ip; 7 | struct map_si; 8 | struct map_sp; 9 | 10 | struct map_kv { 11 | int id; 12 | void *pointer; 13 | }; 14 | 15 | struct map_si * _pbcM_si_new(struct map_kv * table, int size); 16 | int _pbcM_si_query(struct map_si *map, const char *key, int *result); 17 | void _pbcM_si_delete(struct map_si *map); 18 | 19 | struct map_ip * _pbcM_ip_new(struct map_kv * table, int size); 20 | struct map_ip * _pbcM_ip_combine(struct map_ip * a, struct map_ip * b); 21 | void * _pbcM_ip_query(struct map_ip * map, int id); 22 | void _pbcM_ip_delete(struct map_ip *map); 23 | 24 | struct map_sp * _pbcM_sp_new(int max, struct heap *h); 25 | void _pbcM_sp_insert(struct map_sp *map, const char *key, void * value); 26 | void * _pbcM_sp_query(struct map_sp *map, const char *key); 27 | void ** _pbcM_sp_query_insert(struct map_sp *map, const char *key); 28 | void _pbcM_sp_delete(struct map_sp *map); 29 | void _pbcM_sp_foreach(struct map_sp *map, void (*func)(void *p)); 30 | void _pbcM_sp_foreach_ud(struct map_sp *map, void (*func)(void *p, void *ud), void *ud); 31 | void * _pbcM_sp_next(struct map_sp *map, const char ** key); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /skynet/pbc/pattern.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOBUF_C_PATTERN_H 2 | #define PROTOBUF_C_PATTERN_H 3 | 4 | #include "pbc.h" 5 | #include "context.h" 6 | #include "array.h" 7 | 8 | struct _pattern_field { 9 | int id; 10 | int offset; 11 | int ptype; 12 | int ctype; 13 | int label; 14 | pbc_var defv; 15 | }; 16 | 17 | struct pbc_pattern { 18 | struct pbc_env * env; 19 | int count; 20 | struct _pattern_field f[1]; 21 | }; 22 | 23 | struct pbc_pattern * _pbcP_new(struct pbc_env * env, int n); 24 | int _pbcP_unpack_packed(uint8_t *buffer, int size, int ptype, pbc_array array); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /skynet/pbc/stringpool.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOBUF_C_STRINGPOOL_H 2 | #define PROTOBUF_C_STRINGPOOL_H 3 | 4 | struct _stringpool; 5 | 6 | struct _stringpool * _pbcS_new(void); 7 | void _pbcS_delete(struct _stringpool *pool); 8 | const char * _pbcS_build(struct _stringpool *pool, const char * str , int sz); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /skynet/pbc/varint.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOBUF_C_VARINT_H 2 | #define PROTOBUF_C_VARINT_H 3 | 4 | #include 5 | 6 | struct longlong { 7 | uint32_t low; 8 | uint32_t hi; 9 | }; 10 | 11 | int _pbcV_encode32(uint32_t number, uint8_t buffer[10]); 12 | int _pbcV_encode(uint64_t number, uint8_t buffer[10]); 13 | int _pbcV_zigzag32(int32_t number, uint8_t buffer[10]); 14 | int _pbcV_zigzag(int64_t number, uint8_t buffer[10]); 15 | 16 | int _pbcV_decode(uint8_t buffer[10], struct longlong *result); 17 | void _pbcV_dezigzag64(struct longlong *r); 18 | void _pbcV_dezigzag32(struct longlong *r); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /skynet/platform.mk: -------------------------------------------------------------------------------- 1 | PLAT ?= none 2 | PLATS = linux freebsd macosx 3 | 4 | CC ?= gcc 5 | 6 | .PHONY : none $(PLATS) clean all cleanall 7 | 8 | #ifneq ($(PLAT), none) 9 | 10 | .PHONY : default 11 | 12 | default : 13 | $(MAKE) $(PLAT) 14 | 15 | #endif 16 | 17 | none : 18 | @echo "Please do 'make PLATFORM' where PLATFORM is one of these:" 19 | @echo " $(PLATS)" 20 | 21 | SKYNET_LIBS := -lpthread -lm 22 | SHARED := -fPIC --shared 23 | EXPORT := -Wl,-E 24 | 25 | linux : PLAT = linux 26 | macosx : PLAT = macosx 27 | freebsd : PLAT = freebsd 28 | 29 | macosx : SHARED := -fPIC -dynamiclib -Wl,-undefined,dynamic_lookup 30 | macosx : EXPORT := 31 | macosx linux : SKYNET_LIBS += -ldl 32 | linux freebsd : SKYNET_LIBS += -lrt 33 | 34 | # Turn off jemalloc and malloc hook on macosx 35 | 36 | macosx : MALLOC_STATICLIB := 37 | macosx : SKYNET_DEFINES :=-DNOUSE_JEMALLOC 38 | 39 | linux macosx freebsd : 40 | $(MAKE) all PLAT=$@ SKYNET_LIBS="$(SKYNET_LIBS)" SHARED="$(SHARED)" EXPORT="$(EXPORT)" MALLOC_STATICLIB="$(MALLOC_STATICLIB)" SKYNET_DEFINES="$(SKYNET_DEFINES)" 41 | -------------------------------------------------------------------------------- /skynet/service/bootstrap.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local harbor = require "skynet.harbor" 3 | require "skynet.manager" -- import skynet.launch, ... 4 | local memory = require "memory" 5 | 6 | skynet.start(function() 7 | local sharestring = tonumber(skynet.getenv "sharestring" or 4096) 8 | memory.ssexpand(sharestring) 9 | 10 | local standalone = skynet.getenv "standalone" 11 | 12 | local launcher = assert(skynet.launch("snlua","launcher")) 13 | skynet.name(".launcher", launcher) 14 | 15 | local harbor_id = tonumber(skynet.getenv "harbor" or 0) 16 | if harbor_id == 0 then 17 | assert(standalone == nil) 18 | standalone = true 19 | skynet.setenv("standalone", "true") 20 | 21 | local ok, slave = pcall(skynet.newservice, "cdummy") 22 | if not ok then 23 | skynet.abort() 24 | end 25 | skynet.name(".cslave", slave) 26 | 27 | else 28 | if standalone then 29 | if not pcall(skynet.newservice,"cmaster") then 30 | skynet.abort() 31 | end 32 | end 33 | 34 | local ok, slave = pcall(skynet.newservice, "cslave") 35 | if not ok then 36 | skynet.abort() 37 | end 38 | skynet.name(".cslave", slave) 39 | end 40 | 41 | if standalone then 42 | local datacenter = skynet.newservice "datacenterd" 43 | skynet.name("DATACENTER", datacenter) 44 | end 45 | skynet.newservice "service_mgr" 46 | pcall(skynet.newservice,skynet.getenv "start" or "main") 47 | skynet.exit() 48 | end) 49 | -------------------------------------------------------------------------------- /skynet/service/clusterproxy.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local cluster = require "cluster" 3 | require "skynet.manager" -- inject skynet.forward_type 4 | 5 | local node, address = ... 6 | 7 | skynet.register_protocol { 8 | name = "system", 9 | id = skynet.PTYPE_SYSTEM, 10 | unpack = function (...) return ... end, 11 | } 12 | 13 | local forward_map = { 14 | [skynet.PTYPE_SNAX] = skynet.PTYPE_SYSTEM, 15 | [skynet.PTYPE_LUA] = skynet.PTYPE_SYSTEM, 16 | [skynet.PTYPE_RESPONSE] = skynet.PTYPE_RESPONSE, -- don't free response message 17 | } 18 | 19 | skynet.forward_type( forward_map ,function() 20 | local clusterd = skynet.uniqueservice("clusterd") 21 | local n = tonumber(address) 22 | if n then 23 | address = n 24 | end 25 | skynet.dispatch("system", function (session, source, msg, sz) 26 | skynet.ret(skynet.rawcall(clusterd, "lua", skynet.pack("req", node, address, msg, sz))) 27 | end) 28 | end) 29 | -------------------------------------------------------------------------------- /skynet/service/cmemory.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local memory = require "memory" 3 | 4 | memory.dumpinfo() 5 | --memory.dump() 6 | local info = memory.info() 7 | for k,v in pairs(info) do 8 | print(string.format(":%08x %gK",k,v/1024)) 9 | end 10 | 11 | print("Total memory:", memory.total()) 12 | print("Total block:", memory.block()) 13 | 14 | skynet.start(function() skynet.exit() end) 15 | -------------------------------------------------------------------------------- /skynet/service/console.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local snax = require "snax" 3 | local socket = require "socket" 4 | 5 | local function split_cmdline(cmdline) 6 | local split = {} 7 | for i in string.gmatch(cmdline, "%S+") do 8 | table.insert(split,i) 9 | end 10 | return split 11 | end 12 | 13 | local function console_main_loop() 14 | local stdin = socket.stdin() 15 | socket.lock(stdin) 16 | while true do 17 | local cmdline = socket.readline(stdin, "\n") 18 | local split = split_cmdline(cmdline) 19 | local command = split[1] 20 | if command == "snax" then 21 | pcall(snax.newservice, select(2, table.unpack(split))) 22 | elseif cmdline ~= "" then 23 | pcall(skynet.newservice, cmdline) 24 | end 25 | end 26 | socket.unlock(stdin) 27 | end 28 | 29 | skynet.start(function() 30 | skynet.fork(console_main_loop) 31 | end) 32 | -------------------------------------------------------------------------------- /skynet/service/dbg.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local cmd = { ... } 4 | 5 | local function format_table(t) 6 | local index = {} 7 | for k in pairs(t) do 8 | table.insert(index, k) 9 | end 10 | table.sort(index) 11 | local result = {} 12 | for _,v in ipairs(index) do 13 | table.insert(result, string.format("%s:%s",v,tostring(t[v]))) 14 | end 15 | return table.concat(result,"\t") 16 | end 17 | 18 | local function dump_line(key, value) 19 | if type(value) == "table" then 20 | print(key, format_table(value)) 21 | else 22 | print(key,tostring(value)) 23 | end 24 | end 25 | 26 | local function dump_list(list) 27 | local index = {} 28 | for k in pairs(list) do 29 | table.insert(index, k) 30 | end 31 | table.sort(index) 32 | for _,v in ipairs(index) do 33 | dump_line(v, list[v]) 34 | end 35 | end 36 | 37 | skynet.start(function() 38 | local list = skynet.call(".launcher","lua", table.unpack(cmd)) 39 | if list then 40 | dump_list(list) 41 | end 42 | skynet.exit() 43 | end) -------------------------------------------------------------------------------- /skynet/service/debug_agent.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local debugchannel = require "debugchannel" 3 | 4 | local CMD = {} 5 | 6 | local channel 7 | 8 | function CMD.start(address, fd) 9 | assert(channel == nil, "start more than once") 10 | skynet.error(string.format("Attach to :%08x", address)) 11 | local handle 12 | channel, handle = debugchannel.create() 13 | skynet.call(address, "debug", "REMOTEDEBUG", fd, handle) 14 | -- todo hook 15 | skynet.ret(skynet.pack(nil)) 16 | skynet.exit() 17 | end 18 | 19 | function CMD.cmd(cmdline) 20 | channel:write(cmdline) 21 | end 22 | 23 | skynet.start(function() 24 | skynet.dispatch("lua", function(_,_,cmd,...) 25 | local f = CMD[cmd] 26 | f(...) 27 | end) 28 | end) 29 | -------------------------------------------------------------------------------- /skynet/skynet-src/atomic.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_ATOMIC_H 2 | #define SKYNET_ATOMIC_H 3 | 4 | #define ATOM_CAS(ptr, oval, nval) __sync_bool_compare_and_swap(ptr, oval, nval) 5 | #define ATOM_CAS_POINTER(ptr, oval, nval) __sync_bool_compare_and_swap(ptr, oval, nval) 6 | #define ATOM_INC(ptr) __sync_add_and_fetch(ptr, 1) 7 | #define ATOM_FINC(ptr) __sync_fetch_and_add(ptr, 1) 8 | #define ATOM_DEC(ptr) __sync_sub_and_fetch(ptr, 1) 9 | #define ATOM_FDEC(ptr) __sync_fetch_and_sub(ptr, 1) 10 | #define ATOM_ADD(ptr,n) __sync_add_and_fetch(ptr, n) 11 | #define ATOM_SUB(ptr,n) __sync_sub_and_fetch(ptr, n) 12 | #define ATOM_AND(ptr,n) __sync_and_and_fetch(ptr, n) 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /skynet/skynet-src/luashrtbl.h: -------------------------------------------------------------------------------- 1 | #ifndef LUA_SHORT_STRING_TABLE_H 2 | #define LUA_SHORT_STRING_TABLE_H 3 | 4 | #include "lstring.h" 5 | 6 | // If you use modified lua, this macro would be defined in lstring.h 7 | #ifndef ENABLE_SHORT_STRING_TABLE 8 | 9 | static inline int luaS_shrinfo(lua_State *L) { return 0; } 10 | static inline void luaS_initshr() {} 11 | static inline void luaS_exitshr() {} 12 | static inline void luaS_expandshr(int n) {} 13 | 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /skynet/skynet-src/malloc_hook.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_MALLOC_HOOK_H 2 | #define SKYNET_MALLOC_HOOK_H 3 | 4 | #include 5 | #include 6 | 7 | extern size_t malloc_used_memory(void); 8 | extern size_t malloc_memory_block(void); 9 | extern void memory_info_dump(void); 10 | extern size_t mallctl_int64(const char* name, size_t* newval); 11 | extern int mallctl_opt(const char* name, int* newval); 12 | extern void dump_c_mem(void); 13 | extern int dump_mem_lua(lua_State *L); 14 | extern size_t malloc_current_memory(void); 15 | 16 | #endif /* SKYNET_MALLOC_HOOK_H */ 17 | 18 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_daemon.h: -------------------------------------------------------------------------------- 1 | #ifndef skynet_daemon_h 2 | #define skynet_daemon_h 3 | 4 | int daemon_init(const char *pidfile); 5 | int daemon_exit(const char *pidfile); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_env.c: -------------------------------------------------------------------------------- 1 | #include "skynet.h" 2 | #include "skynet_env.h" 3 | #include "spinlock.h" 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | struct skynet_env { 12 | struct spinlock lock; 13 | lua_State *L; 14 | }; 15 | 16 | static struct skynet_env *E = NULL; 17 | 18 | const char * 19 | skynet_getenv(const char *key) { 20 | SPIN_LOCK(E) 21 | 22 | lua_State *L = E->L; 23 | 24 | lua_getglobal(L, key); 25 | const char * result = lua_tostring(L, -1); 26 | lua_pop(L, 1); 27 | 28 | SPIN_UNLOCK(E) 29 | 30 | return result; 31 | } 32 | 33 | void 34 | skynet_setenv(const char *key, const char *value) { 35 | SPIN_LOCK(E) 36 | 37 | lua_State *L = E->L; 38 | lua_getglobal(L, key); 39 | assert(lua_isnil(L, -1)); 40 | lua_pop(L,1); 41 | lua_pushstring(L,value); 42 | lua_setglobal(L,key); 43 | 44 | SPIN_UNLOCK(E) 45 | } 46 | 47 | void 48 | skynet_env_init() { 49 | E = skynet_malloc(sizeof(*E)); 50 | SPIN_INIT(E) 51 | E->L = luaL_newstate(); 52 | } 53 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_env.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_ENV_H 2 | #define SKYNET_ENV_H 3 | 4 | const char * skynet_getenv(const char *key); 5 | void skynet_setenv(const char *key, const char *value); 6 | 7 | void skynet_env_init(); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_handle.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_CONTEXT_HANDLE_H 2 | #define SKYNET_CONTEXT_HANDLE_H 3 | 4 | #include 5 | 6 | // reserve high 8 bits for remote id 7 | #define HANDLE_MASK 0xffffff 8 | #define HANDLE_REMOTE_SHIFT 24 9 | 10 | struct skynet_context; 11 | 12 | uint32_t skynet_handle_register(struct skynet_context *); 13 | int skynet_handle_retire(uint32_t handle); 14 | struct skynet_context * skynet_handle_grab(uint32_t handle); 15 | void skynet_handle_retireall(); 16 | 17 | uint32_t skynet_handle_findname(const char * name); 18 | const char * skynet_handle_namehandle(uint32_t handle, const char *name); 19 | 20 | void skynet_handle_init(int harbor); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_harbor.c: -------------------------------------------------------------------------------- 1 | #include "skynet.h" 2 | #include "skynet_harbor.h" 3 | #include "skynet_server.h" 4 | #include "skynet_mq.h" 5 | #include "skynet_handle.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | static struct skynet_context * REMOTE = 0; 12 | static unsigned int HARBOR = ~0; 13 | 14 | void 15 | skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session) { 16 | int type = rmsg->sz >> MESSAGE_TYPE_SHIFT; 17 | rmsg->sz &= MESSAGE_TYPE_MASK; 18 | assert(type != PTYPE_SYSTEM && type != PTYPE_HARBOR && REMOTE); 19 | skynet_context_send(REMOTE, rmsg, sizeof(*rmsg) , source, type , session); 20 | } 21 | 22 | int 23 | skynet_harbor_message_isremote(uint32_t handle) { 24 | assert(HARBOR != ~0); 25 | int h = (handle & ~HANDLE_MASK); 26 | return h != HARBOR && h !=0; 27 | } 28 | 29 | void 30 | skynet_harbor_init(int harbor) { 31 | HARBOR = (unsigned int)harbor << HANDLE_REMOTE_SHIFT; 32 | } 33 | 34 | void 35 | skynet_harbor_start(void *ctx) { 36 | // the HARBOR must be reserved to ensure the pointer is valid. 37 | // It will be released at last by calling skynet_harbor_exit 38 | skynet_context_reserve(ctx); 39 | REMOTE = ctx; 40 | } 41 | 42 | void 43 | skynet_harbor_exit() { 44 | struct skynet_context * ctx = REMOTE; 45 | REMOTE= NULL; 46 | if (ctx) { 47 | skynet_context_release(ctx); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_harbor.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_HARBOR_H 2 | #define SKYNET_HARBOR_H 3 | 4 | #include 5 | #include 6 | 7 | #define GLOBALNAME_LENGTH 16 8 | #define REMOTE_MAX 256 9 | 10 | struct remote_name { 11 | char name[GLOBALNAME_LENGTH]; 12 | uint32_t handle; 13 | }; 14 | 15 | struct remote_message { 16 | struct remote_name destination; 17 | const void * message; 18 | size_t sz; 19 | }; 20 | 21 | void skynet_harbor_send(struct remote_message *rmsg, uint32_t source, int session); 22 | int skynet_harbor_message_isremote(uint32_t handle); 23 | void skynet_harbor_init(int harbor); 24 | void skynet_harbor_start(void * ctx); 25 | void skynet_harbor_exit(); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_imp.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_IMP_H 2 | #define SKYNET_IMP_H 3 | 4 | struct skynet_config { 5 | int thread; 6 | int harbor; 7 | const char * daemon; 8 | const char * module_path; 9 | const char * bootstrap; 10 | const char * logger; 11 | const char * logservice; 12 | }; 13 | 14 | #define THREAD_WORKER 0 15 | #define THREAD_MAIN 1 16 | #define THREAD_SOCKET 2 17 | #define THREAD_TIMER 3 18 | #define THREAD_MONITOR 4 19 | 20 | void skynet_start(struct skynet_config * config); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_log.h: -------------------------------------------------------------------------------- 1 | #ifndef skynet_log_h 2 | #define skynet_log_h 3 | 4 | #include "skynet_env.h" 5 | #include "skynet.h" 6 | 7 | #include 8 | #include 9 | 10 | FILE * skynet_log_open(struct skynet_context * ctx, uint32_t handle); 11 | void skynet_log_close(struct skynet_context * ctx, FILE *f, uint32_t handle); 12 | void skynet_log_output(FILE *f, uint32_t source, int type, int session, void * buffer, size_t sz); 13 | 14 | #endif -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_malloc.h: -------------------------------------------------------------------------------- 1 | #ifndef skynet_malloc_h 2 | #define skynet_malloc_h 3 | 4 | #include 5 | 6 | #define skynet_malloc malloc 7 | #define skynet_calloc calloc 8 | #define skynet_realloc realloc 9 | #define skynet_free free 10 | 11 | void * skynet_malloc(size_t sz); 12 | void * skynet_calloc(size_t nmemb,size_t size); 13 | void * skynet_realloc(void *ptr, size_t size); 14 | void skynet_free(void *ptr); 15 | char * skynet_strdup(const char *str); 16 | void * skynet_lalloc(void *ptr, size_t osize, size_t nsize); // use for lua 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_module.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_MODULE_H 2 | #define SKYNET_MODULE_H 3 | 4 | struct skynet_context; 5 | 6 | typedef void * (*skynet_dl_create)(void); 7 | typedef int (*skynet_dl_init)(void * inst, struct skynet_context *, const char * parm); 8 | typedef void (*skynet_dl_release)(void * inst); 9 | typedef void (*skynet_dl_signal)(void * inst, int signal); 10 | 11 | struct skynet_module { 12 | const char * name; 13 | void * module; 14 | skynet_dl_create create; 15 | skynet_dl_init init; 16 | skynet_dl_release release; 17 | skynet_dl_signal signal; 18 | }; 19 | 20 | void skynet_module_insert(struct skynet_module *mod); 21 | struct skynet_module * skynet_module_query(const char * name); 22 | void * skynet_module_instance_create(struct skynet_module *); 23 | int skynet_module_instance_init(struct skynet_module *, void * inst, struct skynet_context *ctx, const char * parm); 24 | void skynet_module_instance_release(struct skynet_module *, void *inst); 25 | void skynet_module_instance_signal(struct skynet_module *, void *inst, int signal); 26 | 27 | void skynet_module_init(const char *path); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_monitor.c: -------------------------------------------------------------------------------- 1 | #include "skynet.h" 2 | 3 | #include "skynet_monitor.h" 4 | #include "skynet_server.h" 5 | #include "skynet.h" 6 | #include "atomic.h" 7 | 8 | #include 9 | #include 10 | 11 | struct skynet_monitor { 12 | int version; 13 | int check_version; 14 | uint32_t source; 15 | uint32_t destination; 16 | }; 17 | 18 | struct skynet_monitor * 19 | skynet_monitor_new() { 20 | struct skynet_monitor * ret = skynet_malloc(sizeof(*ret)); 21 | memset(ret, 0, sizeof(*ret)); 22 | return ret; 23 | } 24 | 25 | void 26 | skynet_monitor_delete(struct skynet_monitor *sm) { 27 | skynet_free(sm); 28 | } 29 | 30 | void 31 | skynet_monitor_trigger(struct skynet_monitor *sm, uint32_t source, uint32_t destination) { 32 | sm->source = source; 33 | sm->destination = destination; 34 | ATOM_INC(&sm->version); 35 | } 36 | 37 | void 38 | skynet_monitor_check(struct skynet_monitor *sm) { 39 | if (sm->version == sm->check_version) { 40 | if (sm->destination) { 41 | skynet_context_endless(sm->destination); 42 | skynet_error(NULL, "A message from [ :%08x ] to [ :%08x ] maybe in an endless loop (version = %d)", sm->source , sm->destination, sm->version); 43 | } 44 | } else { 45 | sm->check_version = sm->version; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_MONITOR_H 2 | #define SKYNET_MONITOR_H 3 | 4 | #include 5 | 6 | struct skynet_monitor; 7 | 8 | struct skynet_monitor * skynet_monitor_new(); 9 | void skynet_monitor_delete(struct skynet_monitor *); 10 | void skynet_monitor_trigger(struct skynet_monitor *, uint32_t source, uint32_t destination); 11 | void skynet_monitor_check(struct skynet_monitor *); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_mq.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_MESSAGE_QUEUE_H 2 | #define SKYNET_MESSAGE_QUEUE_H 3 | 4 | #include 5 | #include 6 | 7 | struct skynet_message { 8 | uint32_t source; 9 | int session; 10 | void * data; 11 | size_t sz; 12 | }; 13 | 14 | // type is encoding in skynet_message.sz high 8bit 15 | #define MESSAGE_TYPE_MASK (SIZE_MAX >> 8) 16 | #define MESSAGE_TYPE_SHIFT ((sizeof(size_t)-1) * 8) 17 | 18 | struct message_queue; 19 | 20 | void skynet_globalmq_push(struct message_queue * queue); 21 | struct message_queue * skynet_globalmq_pop(void); 22 | 23 | struct message_queue * skynet_mq_create(uint32_t handle); 24 | void skynet_mq_mark_release(struct message_queue *q); 25 | 26 | typedef void (*message_drop)(struct skynet_message *, void *); 27 | 28 | void skynet_mq_release(struct message_queue *q, message_drop drop_func, void *ud); 29 | uint32_t skynet_mq_handle(struct message_queue *); 30 | 31 | // 0 for success 32 | int skynet_mq_pop(struct message_queue *q, struct skynet_message *message); 33 | void skynet_mq_push(struct message_queue *q, struct skynet_message *message); 34 | 35 | // return the length of message queue, for debug 36 | int skynet_mq_length(struct message_queue *q); 37 | int skynet_mq_overload(struct message_queue *q); 38 | 39 | void skynet_mq_init(); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_server.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_SERVER_H 2 | #define SKYNET_SERVER_H 3 | 4 | #include 5 | #include 6 | 7 | struct skynet_context; 8 | struct skynet_message; 9 | struct skynet_monitor; 10 | 11 | struct skynet_context * skynet_context_new(const char * name, const char * parm); 12 | void skynet_context_grab(struct skynet_context *); 13 | void skynet_context_reserve(struct skynet_context *ctx); 14 | struct skynet_context * skynet_context_release(struct skynet_context *); 15 | uint32_t skynet_context_handle(struct skynet_context *); 16 | int skynet_context_push(uint32_t handle, struct skynet_message *message); 17 | void skynet_context_send(struct skynet_context * context, void * msg, size_t sz, uint32_t source, int type, int session); 18 | int skynet_context_newsession(struct skynet_context *); 19 | struct message_queue * skynet_context_message_dispatch(struct skynet_monitor *, struct message_queue *, int weight); // return next queue 20 | int skynet_context_total(); 21 | void skynet_context_dispatchall(struct skynet_context * context); // for skynet_error output before exit 22 | 23 | void skynet_context_endless(uint32_t handle); // for monitor 24 | 25 | void skynet_globalinit(void); 26 | void skynet_globalexit(void); 27 | void skynet_initthread(int m); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /skynet/skynet-src/skynet_timer.h: -------------------------------------------------------------------------------- 1 | #ifndef SKYNET_TIMER_H 2 | #define SKYNET_TIMER_H 3 | 4 | #include 5 | 6 | int skynet_timeout(uint32_t handle, int time, int session); 7 | void skynet_updatetime(void); 8 | uint32_t skynet_starttime(void); 9 | 10 | void skynet_timer_init(void); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /skynet/skynet-src/socket_poll.h: -------------------------------------------------------------------------------- 1 | #ifndef socket_poll_h 2 | #define socket_poll_h 3 | 4 | #include 5 | 6 | typedef int poll_fd; 7 | 8 | struct event { 9 | void * s; 10 | bool read; 11 | bool write; 12 | }; 13 | 14 | static bool sp_invalid(poll_fd fd); 15 | static poll_fd sp_create(); 16 | static void sp_release(poll_fd fd); 17 | static int sp_add(poll_fd fd, int sock, void *ud); 18 | static void sp_del(poll_fd fd, int sock); 19 | static void sp_write(poll_fd, int sock, void *ud, bool enable); 20 | static int sp_wait(poll_fd, struct event *e, int max); 21 | static void sp_nonblocking(int sock); 22 | 23 | #ifdef __linux__ 24 | #include "socket_epoll.h" 25 | #endif 26 | 27 | #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__) 28 | #include "socket_kqueue.h" 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /skynet/test/pingserver.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local queue = require "skynet.queue" 3 | local snax = require "snax" 4 | 5 | local i = 0 6 | local hello = "hello" 7 | 8 | function response.ping(hello) 9 | skynet.sleep(100) 10 | return hello 11 | end 12 | 13 | -- response.sleep and accept.hello share one lock 14 | local lock 15 | 16 | function accept.sleep(queue, n) 17 | if queue then 18 | lock( 19 | function() 20 | print("queue=",queue, n) 21 | skynet.sleep(n) 22 | end) 23 | else 24 | print("queue=",queue, n) 25 | skynet.sleep(n) 26 | end 27 | end 28 | 29 | function accept.hello() 30 | lock(function() 31 | i = i + 1 32 | print (i, hello) 33 | end) 34 | end 35 | 36 | function accept.exit(...) 37 | snax.exit(...) 38 | end 39 | 40 | function response.error() 41 | error "throw an error" 42 | end 43 | 44 | function init( ... ) 45 | print ("ping server start:", ...) 46 | snax.enablecluster() -- enable cluster call 47 | -- init queue 48 | lock = queue() 49 | end 50 | 51 | function exit(...) 52 | print ("ping server exit:", ...) 53 | end 54 | -------------------------------------------------------------------------------- /skynet/test/sharemap.sp: -------------------------------------------------------------------------------- 1 | .foobar { 2 | x 0 : integer 3 | y 1 : integer 4 | s 2 : string 5 | } 6 | -------------------------------------------------------------------------------- /skynet/test/testcoroutine.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | -- You should use skynet.coroutine instead of origin coroutine in skynet 3 | local coroutine = require "skynet.coroutine" 4 | local profile = require "profile" 5 | 6 | local function status(co) 7 | repeat 8 | local status = coroutine.status(co) 9 | print("STATUS", status) 10 | skynet.sleep(100) 11 | until status == "suspended" 12 | 13 | repeat 14 | local ok, n = assert(coroutine.resume(co)) 15 | print("status thread", n) 16 | until not n 17 | skynet.exit() 18 | end 19 | 20 | local function test(n) 21 | local co = coroutine.running() 22 | print ("begin", co, coroutine.thread(co)) -- false 23 | skynet.fork(status, co) 24 | for i=1,n do 25 | skynet.sleep(100) 26 | coroutine.yield(i) 27 | end 28 | print ("end", co) 29 | end 30 | 31 | local function main() 32 | local f = coroutine.wrap(test) 33 | coroutine.yield "begin" 34 | for i=1,3 do 35 | local n = f(5) 36 | print("main thread",n) 37 | end 38 | coroutine.yield "end" 39 | print("main thread time:", profile.stop(coroutine.thread())) 40 | end 41 | 42 | skynet.start(function() 43 | print("Main thead :", coroutine.thread()) -- true 44 | print(coroutine.resume(coroutine.running())) -- always return false 45 | 46 | profile.start() 47 | 48 | local f = coroutine.wrap(main) 49 | print("main step", f()) 50 | print("main step", f()) 51 | print("main step", f()) 52 | -- print("main thread time:", profile.stop()) 53 | end) 54 | -------------------------------------------------------------------------------- /skynet/test/testdatacenter.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local datacenter = require "datacenter" 3 | 4 | local function f1() 5 | print("====1==== wait hello") 6 | print("\t1>",datacenter.wait ("hello")) 7 | print("====1==== wait key.foobar") 8 | print("\t1>", pcall(datacenter.wait,"key")) -- will failed, because "key" is a branch 9 | print("\t1>",datacenter.wait ("key", "foobar")) 10 | end 11 | 12 | local function f2() 13 | skynet.sleep(10) 14 | print("====2==== set key.foobar") 15 | datacenter.set("key", "foobar", "bingo") 16 | end 17 | 18 | skynet.start(function() 19 | datacenter.set("hello", "world") 20 | print(datacenter.get "hello") 21 | skynet.fork(f1) 22 | skynet.fork(f2) 23 | end) 24 | -------------------------------------------------------------------------------- /skynet/test/testdeadcall.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local mode = ... 4 | 5 | if mode == "test" then 6 | 7 | skynet.start(function() 8 | skynet.dispatch("lua", function (...) 9 | print("====>", ...) 10 | skynet.exit() 11 | end) 12 | end) 13 | 14 | elseif mode == "dead" then 15 | 16 | skynet.start(function() 17 | skynet.dispatch("lua", function (...) 18 | skynet.sleep(100) 19 | print("return", skynet.ret "") 20 | end) 21 | end) 22 | 23 | else 24 | 25 | skynet.start(function() 26 | local test = skynet.newservice(SERVICE_NAME, "test") -- launch self in test mode 27 | 28 | print(pcall(function() 29 | skynet.call(test,"lua", "dead call") 30 | end)) 31 | 32 | local dead = skynet.newservice(SERVICE_NAME, "dead") -- launch self in dead mode 33 | 34 | skynet.timeout(0, skynet.exit) -- exit after a while, so the call never return 35 | skynet.call(dead, "lua", "whould not return") 36 | end) 37 | end 38 | -------------------------------------------------------------------------------- /skynet/test/testdeadloop.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local function dead_loop() 3 | while true do 4 | skynet.sleep(0) 5 | end 6 | end 7 | 8 | skynet.start(function() 9 | skynet.fork(dead_loop) 10 | end) 11 | -------------------------------------------------------------------------------- /skynet/test/testdns.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local dns = require "dns" 3 | 4 | skynet.start(function() 5 | print("nameserver:", dns.server()) -- set nameserver 6 | -- you can specify the server like dns.server("8.8.4.4", 53) 7 | local ip, ips = dns.resolve "github.com" 8 | for k,v in ipairs(ips) do 9 | print("github.com",v) 10 | end 11 | end) 12 | -------------------------------------------------------------------------------- /skynet/test/testecho.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local mode = ... 4 | 5 | if mode == "slave" then 6 | 7 | skynet.start(function() 8 | skynet.dispatch("lua", function(_,_, ...) 9 | skynet.ret(skynet.pack(...)) 10 | end) 11 | end) 12 | 13 | else 14 | 15 | skynet.start(function() 16 | local slave = skynet.newservice(SERVICE_NAME, "slave") 17 | local n = 100000 18 | local start = skynet.now() 19 | print("call salve", n, "times in queue") 20 | for i=1,n do 21 | skynet.call(slave, "lua") 22 | end 23 | print("qps = ", n/ (skynet.now() - start) * 100) 24 | 25 | start = skynet.now() 26 | 27 | local worker = 10 28 | local task = n/worker 29 | print("call salve", n, "times in parallel, worker = ", worker) 30 | 31 | for i=1,worker do 32 | skynet.fork(function() 33 | for i=1,task do 34 | skynet.call(slave, "lua") 35 | end 36 | worker = worker -1 37 | if worker == 0 then 38 | print("qps = ", n/ (skynet.now() - start) * 100) 39 | end 40 | end) 41 | end 42 | end) 43 | 44 | end 45 | -------------------------------------------------------------------------------- /skynet/test/testharborlink.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local harbor = require "skynet.harbor" 3 | 4 | skynet.start(function() 5 | print("wait for harbor 2") 6 | print("run skynet examples/config_log please") 7 | harbor.connect(2) 8 | print("harbor 2 connected") 9 | print("LOG =", skynet.address(harbor.queryname "LOG")) 10 | harbor.link(2) 11 | print("disconnected") 12 | end) 13 | -------------------------------------------------------------------------------- /skynet/test/testhttp.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local httpc = require "http.httpc" 3 | local dns = require "dns" 4 | 5 | skynet.start(function() 6 | httpc.dns() -- set dns server 7 | print("GET baidu.com") 8 | local respheader = {} 9 | local status, body = httpc.get("baidu.com", "/", respheader) 10 | print("[header] =====>") 11 | for k,v in pairs(respheader) do 12 | print(k,v) 13 | end 14 | print("[body] =====>", status) 15 | print(body) 16 | 17 | local respheader = {} 18 | dns.server() 19 | local ip = dns.resolve "baidu.com" 20 | print(string.format("GET %s (baidu.com)", ip)) 21 | local status, body = httpc.get("baidu.com", "/", respheader, { host = "baidu.com" }) 22 | print(status) 23 | 24 | skynet.exit() 25 | end) 26 | -------------------------------------------------------------------------------- /skynet/test/testmemlimit.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local names = {"cluster", "dns", "mongo", "mysql", "redis", "sharedata", "socket", "sproto"} 4 | 5 | -- set sandbox memory limit to 1M, must set here (at start, out of skynet.start) 6 | skynet.memlimit(1 * 1024 * 1024) 7 | 8 | skynet.start(function() 9 | local a = {} 10 | local limit 11 | local ok, err = pcall(function() 12 | for i=1, 12355 do 13 | limit = i 14 | table.insert(a, {}) 15 | end 16 | end) 17 | local libs = {} 18 | for k,v in ipairs(names) do 19 | local ok, m = pcall(require, v) 20 | if ok then 21 | libs[v] = m 22 | end 23 | end 24 | skynet.error(limit, err) 25 | skynet.exit() 26 | end) 27 | -------------------------------------------------------------------------------- /skynet/test/testmulticast.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local mc = require "multicast" 3 | local dc = require "datacenter" 4 | 5 | local mode = ... 6 | 7 | if mode == "sub" then 8 | 9 | skynet.start(function() 10 | skynet.dispatch("lua", function (_,_, cmd, channel) 11 | assert(cmd == "init") 12 | local c = mc.new { 13 | channel = channel , 14 | dispatch = function (channel, source, ...) 15 | print(string.format("%s <=== %s %s",skynet.address(skynet.self()),skynet.address(source), channel), ...) 16 | end 17 | } 18 | print(skynet.address(skynet.self()), "sub", c) 19 | c:subscribe() 20 | skynet.ret(skynet.pack()) 21 | end) 22 | end) 23 | 24 | else 25 | 26 | skynet.start(function() 27 | local channel = mc.new() 28 | print("New channel", channel) 29 | for i=1,10 do 30 | local sub = skynet.newservice(SERVICE_NAME, "sub") 31 | skynet.call(sub, "lua", "init", channel.channel) 32 | end 33 | 34 | dc.set("MCCHANNEL", channel.channel) -- for multi node test 35 | 36 | print(skynet.address(skynet.self()), "===>", channel) 37 | channel:publish("Hello World") 38 | end) 39 | 40 | end -------------------------------------------------------------------------------- /skynet/test/testmulticast2.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local dc = require "datacenter" 3 | local mc = require "multicast" 4 | 5 | skynet.start(function() 6 | print("remote start") 7 | local console = skynet.newservice("console") 8 | local channel = dc.get "MCCHANNEL" 9 | if channel then 10 | print("remote channel", channel) 11 | else 12 | print("create local channel") 13 | end 14 | for i=1,10 do 15 | local sub = skynet.newservice("testmulticast", "sub") 16 | skynet.call(sub, "lua", "init", channel) 17 | end 18 | local c = mc.new { 19 | channel = channel , 20 | dispatch = function(...) print("======>", ...) end, 21 | } 22 | c:subscribe() 23 | c:publish("Remote message") 24 | c:unsubscribe() 25 | c:publish("Remote message2") 26 | c:delete() 27 | skynet.exit() 28 | end) 29 | -------------------------------------------------------------------------------- /skynet/test/testoverload.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local mode = ... 4 | 5 | if mode == "slave" then 6 | 7 | local CMD = {} 8 | 9 | function CMD.sum(n) 10 | skynet.error("for loop begin") 11 | local s = 0 12 | for i = 1, n do 13 | s = s + i 14 | end 15 | skynet.error("for loop end") 16 | end 17 | 18 | function CMD.blackhole() 19 | end 20 | 21 | skynet.start(function() 22 | skynet.dispatch("lua", function(_,_, cmd, ...) 23 | local f = CMD[cmd] 24 | f(...) 25 | end) 26 | end) 27 | 28 | else 29 | 30 | skynet.start(function() 31 | local slave = skynet.newservice(SERVICE_NAME, "slave") 32 | for step = 1, 20 do 33 | skynet.error("overload test ".. step) 34 | for i = 1, 512 * step do 35 | skynet.send(slave, "lua", "blackhole") 36 | end 37 | skynet.sleep(step) 38 | end 39 | local n = 1000000000 40 | skynet.error(string.format("endless test n=%d", n)) 41 | skynet.send(slave, "lua", "sum", n) 42 | end) 43 | 44 | end 45 | -------------------------------------------------------------------------------- /skynet/test/testping.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local snax = require "snax" 3 | 4 | skynet.start(function() 5 | local ps = snax.newservice ("pingserver", "hello world") 6 | print(ps.req.ping("foobar")) 7 | print(ps.post.hello()) 8 | print(pcall(ps.req.error)) 9 | print("Hotfix (i) :", snax.hotfix(ps, [[ 10 | 11 | local i 12 | local hello 13 | 14 | function accept.hello() 15 | i = i + 1 16 | print ("fix", i, hello) 17 | end 18 | 19 | function hotfix(...) 20 | local temp = i 21 | i = 100 22 | return temp 23 | end 24 | 25 | ]])) 26 | print(ps.post.hello()) 27 | 28 | local info = skynet.call(ps.handle, "debug", "INFO") 29 | 30 | for name,v in pairs(info) do 31 | print(string.format("%s\tcount:%d time:%f", name, v.count, v.time)) 32 | end 33 | 34 | print(ps.post.exit("exit")) -- == snax.kill(ps, "exit") 35 | skynet.exit() 36 | end) 37 | -------------------------------------------------------------------------------- /skynet/test/testqueue.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local snax = require "snax" 3 | 4 | skynet.start(function() 5 | local ps = snax.uniqueservice ("pingserver", "test queue") 6 | for i=1, 10 do 7 | ps.post.sleep(true,i*10) 8 | ps.post.hello() 9 | end 10 | for i=1, 10 do 11 | ps.post.sleep(false,i*10) 12 | ps.post.hello() 13 | end 14 | 15 | skynet.exit() 16 | end) 17 | 18 | 19 | -------------------------------------------------------------------------------- /skynet/test/testredis.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local redis = require "redis" 3 | 4 | local conf = { 5 | host = "127.0.0.1" , 6 | port = 6379 , 7 | db = 0 8 | } 9 | 10 | local function watching() 11 | local w = redis.watch(conf) 12 | w:subscribe "foo" 13 | w:psubscribe "hello.*" 14 | while true do 15 | print("Watch", w:message()) 16 | end 17 | end 18 | 19 | skynet.start(function() 20 | skynet.fork(watching) 21 | local db = redis.connect(conf) 22 | 23 | db:del "C" 24 | db:set("A", "hello") 25 | db:set("B", "world") 26 | db:sadd("C", "one") 27 | 28 | print(db:get("A")) 29 | print(db:get("B")) 30 | 31 | db:del "D" 32 | for i=1,10 do 33 | db:hset("D",i,i) 34 | end 35 | local r = db:hvals "D" 36 | for k,v in pairs(r) do 37 | print(k,v) 38 | end 39 | 40 | db:multi() 41 | db:get "A" 42 | db:get "B" 43 | local t = db:exec() 44 | for k,v in ipairs(t) do 45 | print("Exec", v) 46 | end 47 | 48 | print(db:exists "A") 49 | print(db:get "A") 50 | print(db:set("A","hello world")) 51 | print(db:get("A")) 52 | print(db:sismember("C","one")) 53 | print(db:sismember("C","two")) 54 | 55 | print("===========publish============") 56 | 57 | for i=1,10 do 58 | db:publish("foo", i) 59 | end 60 | for i=11,20 do 61 | db:publish("hello.foo", i) 62 | end 63 | 64 | db:disconnect() 65 | -- skynet.exit() 66 | end) 67 | 68 | -------------------------------------------------------------------------------- /skynet/test/testredis2.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local redis = require "redis" 3 | 4 | local db 5 | 6 | function add1(key, count) 7 | local t = {} 8 | for i = 1, count do 9 | t[2*i -1] = "key" ..i 10 | t[2*i] = "value" .. i 11 | end 12 | db:hmset(key, table.unpack(t)) 13 | end 14 | 15 | function add2(key, count) 16 | local t = {} 17 | for i = 1, count do 18 | t[2*i -1] = "key" ..i 19 | t[2*i] = "value" .. i 20 | end 21 | table.insert(t, 1, key) 22 | db:hmset(t) 23 | end 24 | 25 | function __init__() 26 | db = redis.connect { 27 | host = "127.0.0.1", 28 | port = 6300, 29 | db = 0, 30 | auth = "foobared" 31 | } 32 | print("dbsize:", db:dbsize()) 33 | local ok, msg = xpcall(add1, debug.traceback, "test1", 250000) 34 | if not ok then 35 | print("add1 failed", msg) 36 | else 37 | print("add1 succeed") 38 | 39 | end 40 | 41 | local ok, msg = xpcall(add2, debug.traceback, "test2", 250000) 42 | if not ok then 43 | print("add2 failed", msg) 44 | else 45 | print("add2 succeed") 46 | end 47 | print("dbsize:", db:dbsize()) 48 | 49 | print("redistest launched") 50 | end 51 | 52 | skynet.start(__init__) 53 | 54 | -------------------------------------------------------------------------------- /skynet/test/testresponse.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local mode = ... 4 | 5 | if mode == "TICK" then 6 | -- this service whould response the request every 1s. 7 | 8 | local response_queue = {} 9 | 10 | local function response() 11 | while true do 12 | skynet.sleep(100) -- sleep 1s 13 | for k,v in ipairs(response_queue) do 14 | v(true, skynet.now()) -- true means succ, false means error 15 | response_queue[k] = nil 16 | end 17 | end 18 | end 19 | 20 | skynet.start(function() 21 | skynet.fork(response) 22 | skynet.dispatch("lua", function() 23 | table.insert(response_queue, skynet.response()) 24 | end) 25 | end) 26 | 27 | else 28 | 29 | local function request(tick, i) 30 | print(i, "call", skynet.now()) 31 | print(i, "response", skynet.call(tick, "lua")) 32 | print(i, "end", skynet.now()) 33 | end 34 | 35 | skynet.start(function() 36 | local tick = skynet.newservice(SERVICE_NAME, "TICK") 37 | 38 | for i=1,5 do 39 | skynet.fork(request, tick, i) 40 | skynet.sleep(10) 41 | end 42 | end) 43 | 44 | end -------------------------------------------------------------------------------- /skynet/test/testsm.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local sharemap = require "sharemap" 3 | 4 | local mode = ... 5 | 6 | if mode == "slave" then 7 | --slave 8 | 9 | local function dump(reader) 10 | reader:update() 11 | print("x=", reader.x) 12 | print("y=", reader.y) 13 | print("s=", reader.s) 14 | end 15 | 16 | skynet.start(function() 17 | local reader 18 | skynet.dispatch("lua", function(_,_,cmd,...) 19 | if cmd == "init" then 20 | reader = sharemap.reader(...) 21 | else 22 | assert(cmd == "ping") 23 | dump(reader) 24 | end 25 | skynet.ret() 26 | end) 27 | end) 28 | 29 | else 30 | -- master 31 | skynet.start(function() 32 | -- register share type schema 33 | sharemap.register("./test/sharemap.sp") 34 | local slave = skynet.newservice(SERVICE_NAME, "slave") 35 | local writer = sharemap.writer("foobar", { x=0,y=0,s="hello" }) 36 | skynet.call(slave, "lua", "init", "foobar", writer:copy()) 37 | writer.x = 1 38 | writer:commit() 39 | skynet.call(slave, "lua", "ping") 40 | writer.y = 2 41 | writer:commit() 42 | skynet.call(slave, "lua", "ping") 43 | writer.s = "world" 44 | writer:commit() 45 | skynet.call(slave, "lua", "ping") 46 | end) 47 | 48 | end -------------------------------------------------------------------------------- /skynet/test/testsocket.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local socket = require "socket" 3 | 4 | local mode , id = ... 5 | 6 | local function echo(id) 7 | socket.start(id) 8 | 9 | while true do 10 | local str = socket.read(id) 11 | if str then 12 | socket.write(id, str) 13 | else 14 | socket.close(id) 15 | return 16 | end 17 | end 18 | end 19 | 20 | if mode == "agent" then 21 | id = tonumber(id) 22 | 23 | skynet.start(function() 24 | skynet.fork(function() 25 | echo(id) 26 | skynet.exit() 27 | end) 28 | end) 29 | else 30 | local function accept(id) 31 | socket.start(id) 32 | socket.write(id, "Hello Skynet\n") 33 | skynet.newservice(SERVICE_NAME, "agent", id) 34 | -- notice: Some data on this connection(id) may lost before new service start. 35 | -- So, be careful when you want to use start / abandon / start . 36 | socket.abandon(id) 37 | end 38 | 39 | skynet.start(function() 40 | local id = socket.listen("127.0.0.1", 8001) 41 | print("Listen socket :", "127.0.0.1", 8001) 42 | 43 | socket.start(id , function(id, addr) 44 | print("connect from " .. addr .. " " .. id) 45 | -- you have choices : 46 | -- 1. skynet.newservice("testsocket", "agent", id) 47 | -- 2. skynet.fork(echo, id) 48 | -- 3. accept(id) 49 | accept(id) 50 | end) 51 | end) 52 | end -------------------------------------------------------------------------------- /skynet/test/teststm.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local stm = require "stm" 3 | 4 | local mode = ... 5 | 6 | if mode == "slave" then 7 | 8 | skynet.start(function() 9 | skynet.dispatch("lua", function (_,_, obj) 10 | local obj = stm.newcopy(obj) 11 | print("read:", obj(skynet.unpack)) 12 | skynet.ret() 13 | skynet.error("sleep and read") 14 | for i=1,10 do 15 | skynet.sleep(10) 16 | print("read:", obj(skynet.unpack)) 17 | end 18 | skynet.exit() 19 | end) 20 | end) 21 | 22 | else 23 | 24 | skynet.start(function() 25 | local slave = skynet.newservice(SERVICE_NAME, "slave") 26 | local obj = stm.new(skynet.pack(1,2,3,4,5)) 27 | local copy = stm.copy(obj) 28 | skynet.call(slave, "lua", copy) 29 | for i=1,5 do 30 | skynet.sleep(20) 31 | print("write", i) 32 | obj(skynet.pack("hello world", i)) 33 | end 34 | skynet.exit() 35 | end) 36 | end 37 | -------------------------------------------------------------------------------- /skynet/test/testterm.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local function term() 4 | skynet.error("Sleep one second, and term the call to UNEXIST") 5 | skynet.sleep(100) 6 | local self = skynet.self() 7 | skynet.send(skynet.self(), "debug", "TERM", "UNEXIST") 8 | end 9 | 10 | skynet.start(function() 11 | skynet.fork(term) 12 | skynet.error("call an unexist named service UNEXIST, may block") 13 | pcall(skynet.call, "UNEXIST", "lua", "test") 14 | skynet.error("unblock the unexisted service call") 15 | end) 16 | -------------------------------------------------------------------------------- /skynet/test/testtimer.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | 3 | local function timeout(t) 4 | print(t) 5 | end 6 | 7 | local function wakeup(co) 8 | for i=1,5 do 9 | skynet.sleep(50) 10 | skynet.wakeup(co) 11 | end 12 | end 13 | 14 | local function test() 15 | skynet.timeout(10, function() print("test timeout 10") end) 16 | for i=1,10 do 17 | print("test sleep",i,skynet.now()) 18 | skynet.sleep(1) 19 | end 20 | end 21 | 22 | skynet.start(function() 23 | test() 24 | 25 | skynet.fork(wakeup, coroutine.running()) 26 | skynet.timeout(300, function() timeout "Hello World" end) 27 | for i = 1, 10 do 28 | print(i, skynet.now()) 29 | print(skynet.sleep(100)) 30 | end 31 | skynet.exit() 32 | print("Test timer exit") 33 | 34 | end) 35 | -------------------------------------------------------------------------------- /skynet/test/testudp.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | local socket = require "socket" 3 | 4 | local function server() 5 | local host 6 | host = socket.udp(function(str, from) 7 | print("server recv", str, socket.udp_address(from)) 8 | socket.sendto(host, from, "OK " .. str) 9 | end , "127.0.0.1", 8765) -- bind an address 10 | end 11 | 12 | local function client() 13 | local c = socket.udp(function(str, from) 14 | print("client recv", str, socket.udp_address(from)) 15 | end) 16 | socket.udp_connect(c, "127.0.0.1", 8765) 17 | for i=1,20 do 18 | socket.write(c, "hello " .. i) -- write to the address by udp_connect binding 19 | end 20 | end 21 | 22 | skynet.start(function() 23 | skynet.fork(server) 24 | skynet.fork(client) 25 | end) 26 | -------------------------------------------------------------------------------- /skynet/test/time.lua: -------------------------------------------------------------------------------- 1 | local skynet = require "skynet" 2 | skynet.start(function() 3 | print(skynet.starttime()) 4 | print(skynet.now()) 5 | 6 | skynet.timeout(1, function() 7 | print("in 1", skynet.now()) 8 | end) 9 | skynet.timeout(2, function() 10 | print("in 2", skynet.now()) 11 | end) 12 | skynet.timeout(3, function() 13 | print("in 3", skynet.now()) 14 | end) 15 | 16 | skynet.timeout(4, function() 17 | print("in 4", skynet.now()) 18 | end) 19 | skynet.timeout(100, function() 20 | print("in 100", skynet.now()) 21 | end) 22 | end) 23 | -------------------------------------------------------------------------------- /tools/client.lua: -------------------------------------------------------------------------------- 1 | package.path = package.path..";../service/?.lua"..";./lualib/?.lua" 2 | require "tools.robot" 3 | local socket = require "clientsocket" 4 | local argparse = require "base.argparse" 5 | 6 | function main(...) 7 | local parser = argparse("script", "robot") 8 | parser:option("-s --script", "script file") 9 | parser:option("-a --account", "account id") 10 | 11 | local script = parser:parse().script 12 | local account = parser:parse().account 13 | 14 | local robot_obj = robot:new("127.0.0.1", 8102) 15 | robot.account = account 16 | robot_obj:fork(robot_obj.run_script, robot_obj, script) 17 | 18 | local co = coroutine.create(function() 19 | robot_obj:start() 20 | end) 21 | 22 | while robot_obj.runing do 23 | coroutine.resume(co) 24 | socket.usleep(10000) 25 | end 26 | end 27 | 28 | main(...) 29 | -------------------------------------------------------------------------------- /tools/client.sh: -------------------------------------------------------------------------------- 1 | ./../skynet/3rd/lua/lua tools/client.lua $@ 2 | -------------------------------------------------------------------------------- /tools/client_script/login.lua: -------------------------------------------------------------------------------- 1 | 2 | local login = require "common.login" 3 | 4 | client.server_proto_handle = login 5 | 6 | -------------------------------------------------------------------------------- /tools/common/login.lua: -------------------------------------------------------------------------------- 1 | local login = {} 2 | 3 | login.GS2CHello = function(client, args) 4 | client:run_cmd("C2GSLoginAccount", {account=client.account, pwd=""}) 5 | end 6 | 7 | login.GS2CSelectRole = function(client, args) 8 | if not args.role_list or #args.role_list <= 0 then 9 | local args = { 10 | account = client.account, 11 | name = tostring(os.time()), 12 | icon = 1, 13 | } 14 | client:run_cmd("C2GSCreateRole", args) 15 | else 16 | local role = args.role_list[1] 17 | client:run_cmd("C2GSSelectRole", {account=client.account, pid=role.pid}) 18 | end 19 | end 20 | 21 | return login 22 | --------------------------------------------------------------------------------