├── README.md ├── bin └── libmysql.dll ├── build.txt ├── dependencies ├── concurrentqueue │ ├── blockingconcurrentqueue.h │ ├── concurrentqueue.h │ └── lightweightsemaphore.h ├── google │ └── protobuf │ │ └── protobuf.txt ├── hiredis │ ├── adapters │ │ ├── ae.h │ │ ├── glib.h │ │ ├── ivykis.h │ │ ├── libev.h │ │ ├── libevent.h │ │ ├── libuv.h │ │ ├── macosx.h │ │ └── qt.h │ ├── alloc.c │ ├── alloc.h │ ├── async.c │ ├── async.h │ ├── async_private.h │ ├── dict.c │ ├── dict.h │ ├── fmacros.h │ ├── hiredis.c │ ├── hiredis.def │ ├── hiredis.h │ ├── hiredis.pc.in │ ├── hiredis_ssl.h │ ├── hiredis_ssl.pc.in │ ├── net.c │ ├── net.h │ ├── read.c │ ├── read.h │ ├── sds.c │ ├── sds.h │ ├── sdsalloc.h │ ├── sockcompat.c │ ├── sockcompat.h │ ├── ssl.c │ ├── test.c │ └── win32.h ├── libuv │ ├── include │ │ ├── uv.h │ │ └── uv │ │ │ ├── aix.h │ │ │ ├── android-ifaddrs.h │ │ │ ├── bsd.h │ │ │ ├── darwin.h │ │ │ ├── errno.h │ │ │ ├── linux.h │ │ │ ├── os390.h │ │ │ ├── posix.h │ │ │ ├── stdint-msvc2008.h │ │ │ ├── sunos.h │ │ │ ├── threadpool.h │ │ │ ├── tree.h │ │ │ ├── unix.h │ │ │ ├── version.h │ │ │ └── win.h │ └── src │ │ ├── fs-poll.c │ │ ├── heap-inl.h │ │ ├── idna.c │ │ ├── idna.h │ │ ├── inet.c │ │ ├── queue.h │ │ ├── random.c │ │ ├── strscpy.c │ │ ├── strscpy.h │ │ ├── threadpool.c │ │ ├── timer.c │ │ ├── unix │ │ ├── aix-common.c │ │ ├── aix.c │ │ ├── android-ifaddrs.c │ │ ├── async.c │ │ ├── atomic-ops.h │ │ ├── bsd-ifaddrs.c │ │ ├── bsd-proctitle.c │ │ ├── core.c │ │ ├── cygwin.c │ │ ├── darwin-proctitle.c │ │ ├── darwin.c │ │ ├── dl.c │ │ ├── freebsd.c │ │ ├── fs.c │ │ ├── fsevents.c │ │ ├── getaddrinfo.c │ │ ├── getnameinfo.c │ │ ├── haiku.c │ │ ├── ibmi.c │ │ ├── internal.h │ │ ├── kqueue.c │ │ ├── linux-core.c │ │ ├── linux-inotify.c │ │ ├── linux-syscalls.c │ │ ├── linux-syscalls.h │ │ ├── loop-watcher.c │ │ ├── loop.c │ │ ├── netbsd.c │ │ ├── no-fsevents.c │ │ ├── no-proctitle.c │ │ ├── openbsd.c │ │ ├── os390-syscalls.c │ │ ├── os390-syscalls.h │ │ ├── os390.c │ │ ├── pipe.c │ │ ├── poll.c │ │ ├── posix-hrtime.c │ │ ├── posix-poll.c │ │ ├── process.c │ │ ├── procfs-exepath.c │ │ ├── proctitle.c │ │ ├── pthread-fixes.c │ │ ├── random-devurandom.c │ │ ├── random-getentropy.c │ │ ├── random-getrandom.c │ │ ├── random-sysctl-linux.c │ │ ├── signal.c │ │ ├── spinlock.h │ │ ├── stream.c │ │ ├── sunos.c │ │ ├── sysinfo-loadavg.c │ │ ├── sysinfo-memory.c │ │ ├── tcp.c │ │ ├── thread.c │ │ ├── tty.c │ │ └── udp.c │ │ ├── uv-common.c │ │ ├── uv-common.h │ │ ├── uv-data-getter-setters.c │ │ ├── version.c │ │ └── win │ │ ├── async.c │ │ ├── atomicops-inl.h │ │ ├── core.c │ │ ├── detect-wakeup.c │ │ ├── dl.c │ │ ├── error.c │ │ ├── fs-event.c │ │ ├── fs-fd-hash-inl.h │ │ ├── fs.c │ │ ├── getaddrinfo.c │ │ ├── getnameinfo.c │ │ ├── handle-inl.h │ │ ├── handle.c │ │ ├── internal.h │ │ ├── loop-watcher.c │ │ ├── pipe.c │ │ ├── poll.c │ │ ├── process-stdio.c │ │ ├── process.c │ │ ├── req-inl.h │ │ ├── signal.c │ │ ├── snprintf.c │ │ ├── stream-inl.h │ │ ├── stream.c │ │ ├── tcp.c │ │ ├── thread.c │ │ ├── tty.c │ │ ├── udp.c │ │ ├── util.c │ │ ├── winapi.c │ │ ├── winapi.h │ │ ├── winsock.c │ │ └── winsock.h ├── lua │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.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 │ ├── ljumptab.h │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── lopnames.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 │ ├── ltests.c │ ├── ltests.h │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── lua.h │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ ├── lzio.h │ └── onelua.c ├── mysql │ ├── big_endian.h │ ├── binary_log_types.h │ ├── byte_order_generic.h │ ├── byte_order_generic_x86.h │ ├── decimal.h │ ├── errmsg.h │ ├── keycache.h │ ├── little_endian.h │ ├── m_ctype.h │ ├── m_string.h │ ├── my_alloc.h │ ├── my_byteorder.h │ ├── my_command.h │ ├── my_compiler.h │ ├── my_config.h │ ├── my_dbug.h │ ├── my_dir.h │ ├── my_getopt.h │ ├── my_global.h │ ├── my_list.h │ ├── my_sys.h │ ├── my_thread.h │ ├── my_thread_local.h │ ├── my_xml.h │ ├── mysql.h │ ├── mysql │ │ ├── client_authentication.h │ │ ├── client_plugin.h │ │ ├── client_plugin.h.pp │ │ ├── get_password.h │ │ ├── mysql_lex_string.h │ │ ├── plugin_auth_common.h │ │ ├── plugin_trace.h │ │ ├── psi │ │ │ ├── mysql_file.h │ │ │ ├── mysql_idle.h │ │ │ ├── mysql_mdl.h │ │ │ ├── mysql_memory.h │ │ │ ├── mysql_ps.h │ │ │ ├── mysql_socket.h │ │ │ ├── mysql_sp.h │ │ │ ├── mysql_stage.h │ │ │ ├── mysql_statement.h │ │ │ ├── mysql_table.h │ │ │ ├── mysql_thread.h │ │ │ ├── mysql_transaction.h │ │ │ ├── psi.h │ │ │ ├── psi_base.h │ │ │ └── psi_memory.h │ │ ├── service_my_snprintf.h │ │ └── service_mysql_alloc.h │ ├── mysql_com.h │ ├── mysql_com_server.h │ ├── mysql_embed.h │ ├── mysql_time.h │ ├── mysql_version.h │ ├── mysqld_ername.h │ ├── mysqld_error.h │ ├── sql_common.h │ ├── sql_state.h │ ├── sslopt-case.h │ ├── sslopt-longopts.h │ ├── sslopt-vars.h │ ├── thr_cond.h │ ├── thr_mutex.h │ ├── thr_rwlock.h │ └── typelib.h └── sol2 │ └── include │ └── sol │ ├── as_args.hpp │ ├── as_returns.hpp │ ├── base_traits.hpp │ ├── bind_traits.hpp │ ├── bytecode.hpp │ ├── call.hpp │ ├── compatibility.hpp │ ├── compatibility │ ├── compat-5.3.c.h │ ├── compat-5.3.h │ ├── compat-5.4.h │ └── lua_version.hpp │ ├── config.hpp │ ├── coroutine.hpp │ ├── debug.hpp │ ├── demangle.hpp │ ├── deprecate.hpp │ ├── dump_handler.hpp │ ├── ebco.hpp │ ├── environment.hpp │ ├── error.hpp │ ├── error_handler.hpp │ ├── forward.hpp │ ├── forward_detail.hpp │ ├── function.hpp │ ├── function_result.hpp │ ├── function_types.hpp │ ├── function_types_core.hpp │ ├── function_types_overloaded.hpp │ ├── function_types_stateful.hpp │ ├── function_types_stateless.hpp │ ├── function_types_templated.hpp │ ├── in_place.hpp │ ├── inheritance.hpp │ ├── load_result.hpp │ ├── lua_table.hpp │ ├── lua_value.hpp │ ├── make_reference.hpp │ ├── metatable.hpp │ ├── object.hpp │ ├── object_base.hpp │ ├── optional.hpp │ ├── optional_implementation.hpp │ ├── overload.hpp │ ├── pointer_like.hpp │ ├── policies.hpp │ ├── property.hpp │ ├── protect.hpp │ ├── protected_function.hpp │ ├── protected_function_result.hpp │ ├── protected_handler.hpp │ ├── proxy_base.hpp │ ├── raii.hpp │ ├── reference.hpp │ ├── resolve.hpp │ ├── sol.hpp │ ├── stack.hpp │ ├── stack_check.hpp │ ├── stack_check_get.hpp │ ├── stack_check_get_qualified.hpp │ ├── stack_check_get_unqualified.hpp │ ├── stack_check_qualified.hpp │ ├── stack_check_unqualified.hpp │ ├── stack_core.hpp │ ├── stack_field.hpp │ ├── stack_get.hpp │ ├── stack_get_qualified.hpp │ ├── stack_get_unqualified.hpp │ ├── stack_guard.hpp │ ├── stack_iterator.hpp │ ├── stack_pop.hpp │ ├── stack_probe.hpp │ ├── stack_proxy.hpp │ ├── stack_proxy_base.hpp │ ├── stack_push.hpp │ ├── stack_reference.hpp │ ├── state.hpp │ ├── state_handling.hpp │ ├── state_view.hpp │ ├── string_view.hpp │ ├── table.hpp │ ├── table_core.hpp │ ├── table_iterator.hpp │ ├── table_proxy.hpp │ ├── thread.hpp │ ├── tie.hpp │ ├── traits.hpp │ ├── trampoline.hpp │ ├── tuple.hpp │ ├── types.hpp │ ├── unicode.hpp │ ├── unique_usertype_traits.hpp │ ├── unsafe_function.hpp │ ├── unsafe_function_result.hpp │ ├── userdata.hpp │ ├── usertype.hpp │ ├── usertype_container.hpp │ ├── usertype_container_launch.hpp │ ├── usertype_core.hpp │ ├── usertype_proxy.hpp │ ├── usertype_storage.hpp │ ├── usertype_traits.hpp │ ├── variadic_args.hpp │ ├── variadic_results.hpp │ ├── version.hpp │ └── wrapper.hpp ├── doc └── C1001.txt ├── example ├── Http_Ext.cpp ├── Http_Server.cpp ├── JsonTest.cpp ├── Redis_Test.cpp ├── Test_Tcp.cpp ├── Test_Timer.cpp ├── Test_Udp.cpp ├── Test_WebSocket.cpp ├── cpp_lua │ ├── cpp_server.cpp │ ├── gen_cpp.bat │ ├── gen_lua.bat │ ├── lua_client.bat │ ├── lua_client.lua │ ├── testmsg.cpp │ ├── testmsg.h │ ├── testmsg.lua │ ├── testmsg.msg │ ├── types.cpp │ ├── types.h │ ├── types.lua │ └── types.msg ├── cpp_lua_protobuf │ ├── client │ │ ├── main.cpp │ │ ├── msgtest.pb.cc │ │ └── msgtest.pb.h │ ├── liblua │ │ ├── luaunit.lua │ │ ├── protoc.lua │ │ └── serpent.lua │ ├── msgtest.proto │ ├── protoc.exe │ ├── server │ │ ├── msgtest.pb │ │ ├── server.bat │ │ └── server.lua │ ├── 生成c++.bat │ └── 生成pb文件.bat ├── csv_lua │ ├── config.csv │ ├── csv.bat │ └── test.lua ├── db_blob │ ├── blob.bat │ ├── gen_lua.bat │ ├── struct.blob │ ├── struct.lua │ └── test.lua ├── http_server.lua ├── js_websocket │ ├── server.bat │ ├── server.lua │ ├── start.html │ └── websocket.js ├── lua_json │ ├── json.bat │ ├── json.lua │ └── jsonlib │ │ └── json.lua ├── lua_kcp │ ├── client.bat │ ├── client.lua │ ├── server.bat │ └── server.lua ├── lua_tcp │ ├── client.bat │ ├── client.lua │ ├── server.bat │ └── server.lua ├── mysql │ ├── createdb.bat │ ├── mysql_test.cpp │ ├── mysql_test.lua │ ├── run.bat │ └── sql.sql ├── python │ ├── client_test.py │ ├── net.py │ └── socket_buffer.py ├── redis_test.lua └── rpc │ ├── call.lua │ ├── client.bat │ ├── client.lua │ ├── logic.lua │ ├── role.lua │ ├── server.bat │ └── server.lua ├── libs ├── libmysqlclient.a ├── libmysqlclient.lib └── libmysqlclient.so ├── premake ├── makeclean.bat ├── makeclean2.bat ├── premake.bat ├── premake.lua ├── premake.sh ├── premake5 └── premake5.exe ├── src ├── common │ ├── BaseType.h │ ├── ByteBuffer.cpp │ ├── ByteBuffer.h │ ├── ByteConverter.h │ ├── CommonPool.h │ ├── CsvParser.cpp │ ├── CsvParser.h │ ├── Define.h │ ├── EventLoop.cpp │ ├── EventLoop.h │ ├── Heap.cpp │ ├── Heap.h │ ├── HttpParam.cpp │ ├── HttpParam.h │ ├── Objectpool.h │ ├── Platform.h │ ├── PoolObject.h │ ├── Singleton.h │ ├── SpinLock.h │ ├── TQueue.h │ ├── ThreadPool.cpp │ ├── ThreadPool.h │ ├── Timer.cpp │ ├── Timer.h │ ├── Tools.cpp │ ├── Tools.h │ ├── UTimer.h │ ├── XAssert.cpp │ ├── XAssert.h │ ├── XFile.cpp │ ├── XFile.h │ ├── XLog.cpp │ ├── XLog.h │ ├── XTime.cpp │ ├── XTime.h │ ├── base64.cpp │ ├── base64.h │ ├── sha1.cpp │ └── sha1.h ├── db │ ├── DBResult.h │ ├── DBThreadPool.cpp │ ├── DBThreadPool.h │ ├── DB_Interface.cpp │ ├── DB_Interface.h │ ├── DB_Interface_mysql.cpp │ ├── DB_Interface_mysql.h │ ├── DB_Interface_redis.cpp │ ├── DB_Interface_redis.h │ ├── MysqlResult.cpp │ ├── MysqlResult.h │ ├── RedisCommand.cpp │ ├── RedisCommand.h │ ├── RedisResult.cpp │ ├── RedisResult.h │ ├── SqlPrepare.cpp │ ├── SqlPrepare.h │ ├── SqlResultSet.cpp │ └── SqlResultSet.h ├── network │ ├── BasePacket.cpp │ ├── BasePacket.h │ ├── HttpConnect.cpp │ ├── HttpConnect.h │ ├── HttpEvent.h │ ├── HttpServer.cpp │ ├── HttpServer.h │ ├── KcpClient.cpp │ ├── KcpClient.h │ ├── KcpEvent.cpp │ ├── KcpEvent.h │ ├── KcpServer.cpp │ ├── KcpServer.h │ ├── KcpSession.cpp │ ├── KcpSession.h │ ├── MessageBuffer.h │ ├── NetClient.cpp │ ├── NetClient.h │ ├── NetConnect.cpp │ ├── NetConnect.h │ ├── NetEvent.cpp │ ├── NetEvent.h │ ├── NetPacket.cpp │ ├── NetPacket.h │ ├── NetServer.cpp │ ├── NetServer.h │ ├── ProtoPacket.h │ ├── TcpClient.cpp │ ├── TcpClient.h │ ├── TcpServer.cpp │ ├── TcpServer.h │ ├── TcpSocket.cpp │ ├── TcpSocket.h │ ├── UdpClient.cpp │ ├── UdpClient.h │ ├── UdpPacket.cpp │ ├── UdpPacket.h │ ├── UdpServer.cpp │ ├── UdpServer.h │ ├── WebSocketConnect.cpp │ ├── WebSocketConnect.h │ ├── WebSocketEvent.cpp │ ├── WebSocketEvent.h │ ├── WebSocketPacket.cpp │ ├── WebSocketPacket.h │ ├── WebSocketServer.cpp │ ├── WebSocketServer.h │ ├── ikcp.cpp │ └── ikcp.h ├── script │ ├── Lua_Base.cpp │ ├── Lua_Common.cpp │ ├── Lua_CsvFile.cpp │ ├── Lua_EventLoop.cpp │ ├── Lua_HttpServer.cpp │ ├── Lua_Json.cpp │ ├── Lua_KcpServer.cpp │ ├── Lua_Mysql.cpp │ ├── Lua_NetServer.cpp │ ├── Lua_Redis.cpp │ ├── Lua_WebSockServer.cpp │ ├── main.cpp │ ├── pb.c │ └── pb.h ├── serialization │ ├── Common.cpp │ ├── Common.h │ ├── Event.h │ ├── Fio.cpp │ ├── Fio.h │ ├── Generate.cpp │ ├── Generate.h │ ├── GenerateLua.cpp │ ├── GenerateLua.h │ ├── Keyword.cpp │ ├── Keyword.h │ ├── Parser.cpp │ ├── Parser.h │ ├── Token.cpp │ ├── Token.h │ ├── Typedef.cpp │ ├── Typedef.h │ ├── main.cpp │ └── test.cpp └── utils │ ├── HttpParser.cpp │ ├── HttpParser.h │ ├── Json.cpp │ ├── Json.h │ ├── JsonReader.cpp │ ├── JsonReader.h │ ├── ParseUrl.cpp │ ├── ParseUrl.h │ ├── api.c │ ├── http.c │ ├── http_parser.cpp │ ├── http_parser.h │ ├── llhttp.c │ └── llhttp.h └── tool ├── serialization_cpp.exe └── serialization_lua.exe /bin/libmysql.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/bin/libmysql.dll -------------------------------------------------------------------------------- /build.txt: -------------------------------------------------------------------------------- 1 | Ready to work: Visual Studio 2019 and Git 2 | 3 | 1.Download project => git clone https://github.com/jwcpp/jwEngine.git 4 | 5 | 2.Generate project => premake/premake.bat 6 | 7 | 3.Set to c++17 8 | -------------------------------------------------------------------------------- /dependencies/google/protobuf/protobuf.txt: -------------------------------------------------------------------------------- 1 | Storage directory of protobuf header file 2 | 3 | Attach include directory: ..\dependencies 4 | #include 5 | -------------------------------------------------------------------------------- /dependencies/hiredis/fmacros.h: -------------------------------------------------------------------------------- 1 | #ifndef __HIREDIS_FMACRO_H 2 | #define __HIREDIS_FMACRO_H 3 | 4 | #define _XOPEN_SOURCE 600 5 | #define _POSIX_C_SOURCE 200112L 6 | 7 | #if defined(__APPLE__) && defined(__MACH__) 8 | /* Enable TCP_KEEPALIVE */ 9 | #define _DARWIN_C_SOURCE 10 | #endif 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /dependencies/hiredis/hiredis.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | redisAppendCommand 3 | redisAppendCommandArgv 4 | redisAppendFormattedCommand 5 | redisBufferRead 6 | redisBufferWrite 7 | redisCommand 8 | redisCommand 9 | redisCommandArgv 10 | redisConnect 11 | redisConnectBindNonBlock 12 | redisConnectBindNonBlockWithReuse 13 | redisConnectFd 14 | redisConnectNonBlock 15 | redisConnectUnix 16 | redisConnectUnixNonBlock 17 | redisConnectUnixWithTimeout 18 | redisConnectWithOptions 19 | redisConnectWithTimeout 20 | redisEnableKeepAlive 21 | redisFormatCommand 22 | redisFormatCommandArgv 23 | redisFormatSdsCommandArgv 24 | redisFree 25 | redisFreeCommand 26 | redisFreeKeepFd 27 | redisFreeSdsCommand 28 | redisGetReply 29 | redisGetReplyFromReader 30 | redisReaderCreate 31 | redisReconnect 32 | redisSetTimeout 33 | redisvAppendCommand 34 | redisvCommand 35 | redisvFormatCommand 36 | freeReplyObject 37 | hi_calloc 38 | hi_malloc 39 | -------------------------------------------------------------------------------- /dependencies/hiredis/hiredis.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | pkgincludedir=${includedir}/hiredis 6 | 7 | Name: hiredis 8 | Description: Minimalistic C client library for Redis. 9 | Version: @PROJECT_VERSION@ 10 | Libs: -L${libdir} -lhiredis 11 | Cflags: -I${pkgincludedir} -D_FILE_OFFSET_BITS=64 12 | -------------------------------------------------------------------------------- /dependencies/hiredis/hiredis_ssl.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | pkgincludedir=${includedir}/hiredis 6 | 7 | Name: hiredis_ssl 8 | Description: SSL Support for hiredis. 9 | Version: @PROJECT_VERSION@ 10 | Requires: hiredis 11 | Libs: -L${libdir} -lhiredis_ssl 12 | Libs.private: -lssl -lcrypto 13 | -------------------------------------------------------------------------------- /dependencies/hiredis/win32.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIN32_HELPER_INCLUDE 2 | #define _WIN32_HELPER_INCLUDE 3 | #ifdef _MSC_VER 4 | 5 | #include /* for struct timeval */ 6 | 7 | #ifndef inline 8 | #define inline __inline 9 | #endif 10 | 11 | #ifndef strcasecmp 12 | #define strcasecmp stricmp 13 | #endif 14 | 15 | #ifndef strncasecmp 16 | #define strncasecmp strnicmp 17 | #endif 18 | 19 | #ifndef va_copy 20 | #define va_copy(d,s) ((d) = (s)) 21 | #endif 22 | 23 | #ifndef snprintf 24 | #define snprintf c99_snprintf 25 | 26 | __inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap) 27 | { 28 | int count = -1; 29 | 30 | if (size != 0) 31 | count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); 32 | if (count == -1) 33 | count = _vscprintf(format, ap); 34 | 35 | return count; 36 | } 37 | 38 | __inline int c99_snprintf(char* str, size_t size, const char* format, ...) 39 | { 40 | int count; 41 | va_list ap; 42 | 43 | va_start(ap, format); 44 | count = c99_vsnprintf(str, size, format, ap); 45 | va_end(ap); 46 | 47 | return count; 48 | } 49 | #endif 50 | #endif /* _MSC_VER */ 51 | 52 | #ifdef _WIN32 53 | #define strerror_r(errno,buf,len) strerror_s(buf,len,errno) 54 | #endif /* _WIN32 */ 55 | 56 | #endif /* _WIN32_HELPER_INCLUDE */ 57 | -------------------------------------------------------------------------------- /dependencies/libuv/include/uv/aix.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_AIX_H 23 | #define UV_AIX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | int fs_fd; \ 27 | 28 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 29 | uv__io_t event_watcher; \ 30 | char *dir_filename; \ 31 | 32 | #endif /* UV_AIX_H */ 33 | -------------------------------------------------------------------------------- /dependencies/libuv/include/uv/bsd.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_BSD_H 23 | #define UV_BSD_H 24 | 25 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 26 | uv__io_t event_watcher; \ 27 | 28 | #define UV_IO_PRIVATE_PLATFORM_FIELDS \ 29 | int rcount; \ 30 | int wcount; \ 31 | 32 | #define UV_HAVE_KQUEUE 1 33 | 34 | #endif /* UV_BSD_H */ 35 | -------------------------------------------------------------------------------- /dependencies/libuv/include/uv/linux.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_LINUX_H 23 | #define UV_LINUX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | uv__io_t inotify_read_watcher; \ 27 | void* inotify_watchers; \ 28 | int inotify_fd; \ 29 | 30 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 31 | void* watchers[2]; \ 32 | int wd; \ 33 | 34 | #endif /* UV_LINUX_H */ 35 | -------------------------------------------------------------------------------- /dependencies/libuv/include/uv/os390.h: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_MVS_H 23 | #define UV_MVS_H 24 | 25 | #define UV_PLATFORM_SEM_T long 26 | 27 | #define UV_PLATFORM_LOOP_FIELDS \ 28 | void* ep; \ 29 | 30 | #define UV_PLATFORM_FS_EVENT_FIELDS \ 31 | char rfis_rftok[8]; \ 32 | 33 | #endif /* UV_MVS_H */ 34 | -------------------------------------------------------------------------------- /dependencies/libuv/include/uv/posix.h: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_POSIX_H 23 | #define UV_POSIX_H 24 | 25 | #define UV_PLATFORM_LOOP_FIELDS \ 26 | struct pollfd* poll_fds; \ 27 | size_t poll_fds_used; \ 28 | size_t poll_fds_size; \ 29 | unsigned char poll_fds_iterating; \ 30 | 31 | #endif /* UV_POSIX_H */ 32 | -------------------------------------------------------------------------------- /dependencies/libuv/include/uv/threadpool.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | /* 23 | * This file is private to libuv. It provides common functionality to both 24 | * Windows and Unix backends. 25 | */ 26 | 27 | #ifndef UV_THREADPOOL_H_ 28 | #define UV_THREADPOOL_H_ 29 | 30 | struct uv__work { 31 | void (*work)(struct uv__work *w); 32 | void (*done)(struct uv__work *w, int status); 33 | struct uv_loop_s* loop; 34 | void* wq[2]; 35 | }; 36 | 37 | #endif /* UV_THREADPOOL_H_ */ 38 | -------------------------------------------------------------------------------- /dependencies/libuv/include/uv/version.h: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef UV_VERSION_H 23 | #define UV_VERSION_H 24 | 25 | /* 26 | * Versions with the same major number are ABI stable. API is allowed to 27 | * evolve between minor releases, but only in a backwards compatible way. 28 | * Make sure you update the -soname directives in configure.ac 29 | * and uv.gyp whenever you bump UV_VERSION_MAJOR or UV_VERSION_MINOR (but 30 | * not UV_VERSION_PATCH.) 31 | */ 32 | 33 | #define UV_VERSION_MAJOR 1 34 | #define UV_VERSION_MINOR 33 35 | #define UV_VERSION_PATCH 2 36 | #define UV_VERSION_IS_RELEASE 0 37 | #define UV_VERSION_SUFFIX "dev" 38 | 39 | #define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \ 40 | (UV_VERSION_MINOR << 8) | \ 41 | (UV_VERSION_PATCH)) 42 | 43 | #endif /* UV_VERSION_H */ 44 | -------------------------------------------------------------------------------- /dependencies/libuv/src/idna.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2011, 2018 Ben Noordhuis 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | */ 15 | 16 | #ifndef UV_SRC_IDNA_H_ 17 | #define UV_SRC_IDNA_H_ 18 | 19 | /* Decode a single codepoint. Returns the codepoint or UINT32_MAX on error. 20 | * |p| is updated on success _and_ error, i.e., bad multi-byte sequences are 21 | * skipped in their entirety, not just the first bad byte. 22 | */ 23 | unsigned uv__utf8_decode1(const char** p, const char* pe); 24 | 25 | /* Convert a UTF-8 domain name to IDNA 2008 / Punycode. A return value >= 0 26 | * is the number of bytes written to |d|, including the trailing nul byte. 27 | * A return value < 0 is a libuv error code. |s| and |d| can not overlap. 28 | */ 29 | long uv__idna_toascii(const char* s, const char* se, char* d, char* de); 30 | 31 | #endif /* UV_SRC_IDNA_H_ */ 32 | -------------------------------------------------------------------------------- /dependencies/libuv/src/strscpy.c: -------------------------------------------------------------------------------- 1 | #include "strscpy.h" 2 | #include /* SSIZE_MAX */ 3 | 4 | ssize_t uv__strscpy(char* d, const char* s, size_t n) { 5 | size_t i; 6 | 7 | for (i = 0; i < n; i++) 8 | if ('\0' == (d[i] = s[i])) 9 | return i > SSIZE_MAX ? UV_E2BIG : (ssize_t) i; 10 | 11 | if (i == 0) 12 | return 0; 13 | 14 | d[--i] = '\0'; 15 | 16 | return UV_E2BIG; 17 | } 18 | -------------------------------------------------------------------------------- /dependencies/libuv/src/strscpy.h: -------------------------------------------------------------------------------- 1 | #ifndef UV_STRSCPY_H_ 2 | #define UV_STRSCPY_H_ 3 | 4 | /* Include uv.h for its definitions of size_t and ssize_t. 5 | * size_t can be obtained directly from but ssize_t requires 6 | * some hoop jumping on Windows that I didn't want to duplicate here. 7 | */ 8 | #include "uv.h" 9 | 10 | /* Copies up to |n-1| bytes from |d| to |s| and always zero-terminates 11 | * the result, except when |n==0|. Returns the number of bytes copied 12 | * or UV_E2BIG if |d| is too small. 13 | * 14 | * See https://www.kernel.org/doc/htmldocs/kernel-api/API-strscpy.html 15 | */ 16 | ssize_t uv__strscpy(char* d, const char* s, size_t n); 17 | 18 | #endif /* UV_STRSCPY_H_ */ 19 | -------------------------------------------------------------------------------- /dependencies/libuv/src/unix/cygwin.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | 28 | int uv_uptime(double* uptime) { 29 | struct sysinfo info; 30 | 31 | if (sysinfo(&info) < 0) 32 | return UV__ERR(errno); 33 | 34 | *uptime = info.uptime; 35 | return 0; 36 | } 37 | 38 | int uv_resident_set_memory(size_t* rss) { 39 | /* FIXME: read /proc/meminfo? */ 40 | *rss = 0; 41 | return 0; 42 | } 43 | 44 | int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { 45 | /* FIXME: read /proc/stat? */ 46 | *cpu_infos = NULL; 47 | *count = 0; 48 | return UV_ENOSYS; 49 | } 50 | 51 | uint64_t uv_get_constrained_memory(void) { 52 | return 0; /* Memory constraints are unknown. */ 53 | } 54 | -------------------------------------------------------------------------------- /dependencies/libuv/src/unix/no-fsevents.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | 27 | int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) { 28 | return UV_ENOSYS; 29 | } 30 | 31 | int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb, 32 | const char* filename, unsigned int flags) { 33 | return UV_ENOSYS; 34 | } 35 | 36 | int uv_fs_event_stop(uv_fs_event_t* handle) { 37 | return UV_ENOSYS; 38 | } 39 | 40 | void uv__fs_event_close(uv_fs_event_t* handle) { 41 | UNREACHABLE(); 42 | } 43 | -------------------------------------------------------------------------------- /dependencies/libuv/src/unix/no-proctitle.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | 28 | char** uv_setup_args(int argc, char** argv) { 29 | return argv; 30 | } 31 | 32 | int uv_set_process_title(const char* title) { 33 | return 0; 34 | } 35 | 36 | int uv_get_process_title(char* buffer, size_t size) { 37 | if (buffer == NULL || size == 0) 38 | return UV_EINVAL; 39 | 40 | buffer[0] = '\0'; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /dependencies/libuv/src/unix/posix-hrtime.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | 28 | #undef NANOSEC 29 | #define NANOSEC ((uint64_t) 1e9) 30 | 31 | uint64_t uv__hrtime(uv_clocktype_t type) { 32 | struct timespec ts; 33 | clock_gettime(CLOCK_MONOTONIC, &ts); 34 | return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); 35 | } 36 | -------------------------------------------------------------------------------- /dependencies/libuv/src/unix/procfs-exepath.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | 28 | int uv_exepath(char* buffer, size_t* size) { 29 | ssize_t n; 30 | 31 | if (buffer == NULL || size == NULL || *size == 0) 32 | return UV_EINVAL; 33 | 34 | n = *size - 1; 35 | if (n > 0) 36 | n = readlink("/proc/self/exe", buffer, n); 37 | 38 | if (n == -1) 39 | return UV__ERR(errno); 40 | 41 | buffer[n] = '\0'; 42 | *size = n; 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /dependencies/libuv/src/unix/sysinfo-loadavg.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | 28 | void uv_loadavg(double avg[3]) { 29 | struct sysinfo info; 30 | 31 | if (sysinfo(&info) < 0) return; 32 | 33 | avg[0] = (double) info.loads[0] / 65536.0; 34 | avg[1] = (double) info.loads[1] / 65536.0; 35 | avg[2] = (double) info.loads[2] / 65536.0; 36 | } 37 | -------------------------------------------------------------------------------- /dependencies/libuv/src/unix/sysinfo-memory.c: -------------------------------------------------------------------------------- 1 | /* Copyright libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | #include "internal.h" 24 | 25 | #include 26 | #include 27 | 28 | uint64_t uv_get_free_memory(void) { 29 | struct sysinfo info; 30 | 31 | if (sysinfo(&info) == 0) 32 | return (uint64_t) info.freeram * info.mem_unit; 33 | return 0; 34 | } 35 | 36 | uint64_t uv_get_total_memory(void) { 37 | struct sysinfo info; 38 | 39 | if (sysinfo(&info) == 0) 40 | return (uint64_t) info.totalram * info.mem_unit; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /dependencies/libuv/src/version.c: -------------------------------------------------------------------------------- 1 | /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #include "uv.h" 23 | 24 | #define UV_STRINGIFY(v) UV_STRINGIFY_HELPER(v) 25 | #define UV_STRINGIFY_HELPER(v) #v 26 | 27 | #define UV_VERSION_STRING_BASE UV_STRINGIFY(UV_VERSION_MAJOR) "." \ 28 | UV_STRINGIFY(UV_VERSION_MINOR) "." \ 29 | UV_STRINGIFY(UV_VERSION_PATCH) 30 | 31 | #if UV_VERSION_IS_RELEASE 32 | # define UV_VERSION_STRING UV_VERSION_STRING_BASE 33 | #else 34 | # define UV_VERSION_STRING UV_VERSION_STRING_BASE "-" UV_VERSION_SUFFIX 35 | #endif 36 | 37 | 38 | unsigned int uv_version(void) { 39 | return UV_VERSION_HEX; 40 | } 41 | 42 | 43 | const char* uv_version_string(void) { 44 | return UV_VERSION_STRING; 45 | } 46 | -------------------------------------------------------------------------------- /dependencies/libuv/src/win/detect-wakeup.c: -------------------------------------------------------------------------------- 1 | #include "uv.h" 2 | #include "internal.h" 3 | #include "winapi.h" 4 | 5 | static void uv__register_system_resume_callback(void); 6 | 7 | void uv__init_detect_system_wakeup(void) { 8 | /* Try registering system power event callback. This is the cleanest 9 | * method, but it will only work on Win8 and above. 10 | */ 11 | uv__register_system_resume_callback(); 12 | } 13 | 14 | static ULONG CALLBACK uv__system_resume_callback(PVOID Context, 15 | ULONG Type, 16 | PVOID Setting) { 17 | if (Type == PBT_APMRESUMESUSPEND || Type == PBT_APMRESUMEAUTOMATIC) 18 | uv__wake_all_loops(); 19 | 20 | return 0; 21 | } 22 | 23 | static void uv__register_system_resume_callback(void) { 24 | _DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS recipient; 25 | _HPOWERNOTIFY registration_handle; 26 | 27 | if (pPowerRegisterSuspendResumeNotification == NULL) 28 | return; 29 | 30 | recipient.Callback = uv__system_resume_callback; 31 | recipient.Context = NULL; 32 | (*pPowerRegisterSuspendResumeNotification)(DEVICE_NOTIFY_CALLBACK, 33 | &recipient, 34 | ®istration_handle); 35 | } 36 | -------------------------------------------------------------------------------- /dependencies/libuv/src/win/snprintf.c: -------------------------------------------------------------------------------- 1 | /* Copyright the libuv project contributors. All rights reserved. 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to 5 | * deal in the Software without restriction, including without limitation the 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | * sell copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | * IN THE SOFTWARE. 20 | */ 21 | 22 | #if defined(_MSC_VER) && _MSC_VER < 1900 23 | 24 | #include 25 | #include 26 | 27 | /* Emulate snprintf() on MSVC<2015, _snprintf() doesn't zero-terminate the buffer 28 | * on overflow... 29 | */ 30 | int snprintf(char* buf, size_t len, const char* fmt, ...) { 31 | int n; 32 | va_list ap; 33 | va_start(ap, fmt); 34 | 35 | n = _vscprintf(fmt, ap); 36 | vsnprintf_s(buf, len, _TRUNCATE, fmt, ap); 37 | 38 | va_end(ap); 39 | return n; 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /dependencies/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 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 | 15 | /* Increments 'L->top', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 17 | "stack overflow");} 18 | 19 | 20 | /* 21 | ** If a call returns too many multiple returns, the callee may not have 22 | ** stack space to accommodate all results. In this case, this macro 23 | ** increases its stack space ('L->ci->top'). 24 | */ 25 | #define adjustresults(L,nres) \ 26 | { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 27 | 28 | 29 | /* Ensure the stack has at least 'n' elements */ 30 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 31 | "not enough elements in the stack") 32 | 33 | 34 | /* 35 | ** To reduce the overhead of returning from C functions, the presence of 36 | ** to-be-closed variables in these functions is coded in the CallInfo's 37 | ** field 'nresults', in a way that functions with no to-be-closed variables 38 | ** with zero, one, or "all" wanted results have no overhead. Functions 39 | ** with other number of wanted results, as well as functions with 40 | ** variables to be closed, have an extra check. 41 | */ 42 | 43 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 44 | 45 | #define codeNresults(n) (-(n) - 3) 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /dependencies/lua/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast_int((pc) - (p)->code) - 1) 15 | 16 | #define resethookcount(L) (L->hookcount = L->basehookcount) 17 | 18 | /* 19 | ** mark for entries in 'lineinfo' array that has absolute information in 20 | ** 'abslineinfo' array 21 | */ 22 | #define ABSLINEINFO (-0x80) 23 | 24 | LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc); 25 | LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, 26 | StkId *pos); 27 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 28 | const char *opname); 29 | LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o, 30 | const char *what); 31 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 32 | const TValue *p2); 33 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 34 | const TValue *p2, 35 | const char *msg); 36 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 37 | const TValue *p2); 38 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 39 | const TValue *p2); 40 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 41 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 42 | TString *src, int line); 43 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 44 | LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc); 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /dependencies/lua/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {LUA_GNAME, luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | {NULL, NULL} 54 | }; 55 | 56 | 57 | LUALIB_API void luaL_openlibs (lua_State *L) { 58 | const luaL_Reg *lib; 59 | /* "require" functions from 'loadedlibs' and set results to global table */ 60 | for (lib = loadedlibs; lib->func; lib++) { 61 | luaL_requiref(L, lib->name, lib->func, 1); 62 | lua_pop(L, 1); /* remove lib */ 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /dependencies/lua/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | /* ORDER OP */ 11 | 12 | static const char *const opnames[] = { 13 | "MOVE", 14 | "LOADI", 15 | "LOADF", 16 | "LOADK", 17 | "LOADKX", 18 | "LOADFALSE", 19 | "LOADTRUE", 20 | "LOADNIL", 21 | "GETUPVAL", 22 | "SETUPVAL", 23 | "GETTABUP", 24 | "GETTABLE", 25 | "GETI", 26 | "GETFIELD", 27 | "SETTABUP", 28 | "SETTABLE", 29 | "SETI", 30 | "SETFIELD", 31 | "NEWTABLE", 32 | "SELF", 33 | "ADDI", 34 | "ADDK", 35 | "SUBK", 36 | "MULK", 37 | "MODK", 38 | "POWK", 39 | "DIVK", 40 | "IDIVK", 41 | "BANDK", 42 | "BORK", 43 | "BXORK", 44 | "SHRI", 45 | "SHLI", 46 | "ADD", 47 | "SUB", 48 | "MUL", 49 | "MOD", 50 | "POW", 51 | "DIV", 52 | "IDIV", 53 | "BAND", 54 | "BOR", 55 | "BXOR", 56 | "SHL", 57 | "SHR", 58 | "MMBIN", 59 | "MMBINI", 60 | "MMBINK", 61 | "UNM", 62 | "BNOT", 63 | "NOT", 64 | "LEN", 65 | "CONCAT", 66 | "CLOSE", 67 | "TBC", 68 | "JMP", 69 | "EQ", 70 | "LT", 71 | "LE", 72 | "EQK", 73 | "EQI", 74 | "LTI", 75 | "LEI", 76 | "GTI", 77 | "GEI", 78 | "TEST", 79 | "TESTSET", 80 | "CALL", 81 | "TAILCALL", 82 | "RETURN", 83 | "RETURN0", 84 | "RETURN1", 85 | "FORLOOP", 86 | "FORPREP", 87 | "TFORPREP", 88 | "TFORCALL", 89 | "TFORLOOP", 90 | "SETLIST", 91 | "CLOSURE", 92 | "VARARG", 93 | "VARARGPREP", 94 | "EXTRAARG", 95 | NULL 96 | }; 97 | 98 | #endif 99 | 100 | -------------------------------------------------------------------------------- /dependencies/lua/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 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 | -------------------------------------------------------------------------------- /dependencies/lua/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | #define sizelstring(l) (sizeof(TString) + ((l) + 1) * sizeof(char)) 23 | 24 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 25 | (sizeof(s)/sizeof(char))-1)) 26 | 27 | 28 | /* 29 | ** test whether a string is a reserved word 30 | */ 31 | #define isreserved(s) ((s)->tt == LUA_TSHRSTR && (s)->extra > 0) 32 | 33 | 34 | /* 35 | ** equality for short strings, which are always internalized 36 | */ 37 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_TSHRSTR, (a) == (b)) 38 | 39 | 40 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 41 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 42 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 43 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 44 | LUAI_FUNC void luaS_clearcache (global_State *g); 45 | LUAI_FUNC void luaS_init (lua_State *L); 46 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 47 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 48 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 49 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 50 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 51 | 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /dependencies/lua/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->u.next) 16 | 17 | 18 | #define invalidateTMcache(t) ((t)->flags = 0) 19 | 20 | 21 | /* true when 't' is using 'dummynode' as its hash part */ 22 | #define isdummy(t) ((t)->lastfree == NULL) 23 | 24 | 25 | /* allocated size for hash nodes */ 26 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 27 | 28 | 29 | /* returns the Node, given the value of a table entry */ 30 | #define nodefromval(v) cast(Node *, (v)) 31 | 32 | 33 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 34 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 35 | TValue *value); 36 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 37 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 38 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 39 | LUAI_FUNC TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key); 40 | LUAI_FUNC TValue *luaH_set (lua_State *L, Table *t, const TValue *key); 41 | LUAI_FUNC Table *luaH_new (lua_State *L); 42 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 43 | unsigned int nhsize); 44 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 45 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 46 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 47 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 48 | LUAI_FUNC unsigned int luaH_realasize (const Table *t); 49 | 50 | 51 | #if defined(LUA_DEBUG) 52 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 53 | LUAI_FUNC int luaH_isdummy (const Table *t); 54 | #endif 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /dependencies/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | 53 | #if !defined(lua_assert) 54 | #define lua_assert(x) ((void)0) 55 | #endif 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /dependencies/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 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 LUAC_VERSION LUA_VERSION_NUM 22 | #define LUAC_FORMAT 0 /* this is the official format */ 23 | 24 | /* load one chunk; from lundump.c */ 25 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 26 | 27 | /* dump one chunk; from ldump.c */ 28 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 29 | void* data, int strip); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /dependencies/lua/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /dependencies/lua/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /dependencies/mysql/my_command.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | #ifndef _mysql_command_h 17 | #define _mysql_command_h 18 | 19 | /** 20 | @enum enum_server_command 21 | @brief You should add new commands to the end of this list, otherwise old 22 | servers won't be able to handle them as 'unsupported'. 23 | */ 24 | enum enum_server_command 25 | { 26 | COM_SLEEP, 27 | COM_QUIT, 28 | COM_INIT_DB, 29 | COM_QUERY, 30 | COM_FIELD_LIST, 31 | COM_CREATE_DB, 32 | COM_DROP_DB, 33 | COM_REFRESH, 34 | COM_SHUTDOWN, 35 | COM_STATISTICS, 36 | COM_PROCESS_INFO, 37 | COM_CONNECT, 38 | COM_PROCESS_KILL, 39 | COM_DEBUG, 40 | COM_PING, 41 | COM_TIME, 42 | COM_DELAYED_INSERT, 43 | COM_CHANGE_USER, 44 | COM_BINLOG_DUMP, 45 | COM_TABLE_DUMP, 46 | COM_CONNECT_OUT, 47 | COM_REGISTER_SLAVE, 48 | COM_STMT_PREPARE, 49 | COM_STMT_EXECUTE, 50 | COM_STMT_SEND_LONG_DATA, 51 | COM_STMT_CLOSE, 52 | COM_STMT_RESET, 53 | COM_SET_OPTION, 54 | COM_STMT_FETCH, 55 | COM_DAEMON, 56 | COM_BINLOG_DUMP_GTID, 57 | COM_RESET_CONNECTION, 58 | /* don't forget to update const char *command_name[] in sql_parse.cc */ 59 | 60 | /* Must be last */ 61 | COM_END 62 | }; 63 | 64 | #endif /* _mysql_command_h */ 65 | -------------------------------------------------------------------------------- /dependencies/mysql/my_list.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | #ifndef _list_h_ 17 | #define _list_h_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef struct st_list { 24 | struct st_list *prev,*next; 25 | void *data; 26 | } LIST; 27 | 28 | typedef int (*list_walk_action)(void *,void *); 29 | 30 | extern LIST *list_add(LIST *root,LIST *element); 31 | extern LIST *list_delete(LIST *root,LIST *element); 32 | extern LIST *list_cons(void *data,LIST *root); 33 | extern LIST *list_reverse(LIST *root); 34 | extern void list_free(LIST *root,unsigned int free_data); 35 | extern unsigned int list_length(LIST *); 36 | extern int list_walk(LIST *,list_walk_action action,unsigned char * argument); 37 | 38 | #define list_rest(a) ((a)->next) 39 | #define list_push(a,b) (a)=list_cons((b),(a)) 40 | #define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old); my_free(old); } 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /dependencies/mysql/mysql/client_authentication.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | #ifndef CLIENT_AUTHENTICATION_H 16 | #define CLIENT_AUTHENTICATION_H 17 | #include 18 | #include "mysql.h" 19 | #include "mysql/client_plugin.h" 20 | 21 | C_MODE_START 22 | int sha256_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql); 23 | int sha256_password_init(char *, size_t, int, va_list); 24 | int sha256_password_deinit(void); 25 | C_MODE_END 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /dependencies/mysql/mysql/get_password.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | /* 17 | ** Ask for a password from tty 18 | ** This is an own file to avoid conflicts with curses 19 | */ 20 | 21 | #ifndef MYSQL_GET_PASSWORD_H_INCLUDED 22 | #define MYSQL_GET_PASSWORD_H_INCLUDED 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | typedef char *(* strdup_handler_t)(const char *, int); 29 | char *get_tty_password_ext(const char *opt_message, 30 | strdup_handler_t strdup_function); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* ! MYSQL_GET_PASSWORD_H_INCLUDED */ 37 | -------------------------------------------------------------------------------- /dependencies/mysql/mysql/mysql_lex_string.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | #ifndef MYSQL_LEX_STRING_INCLUDED 17 | #define MYSQL_LEX_STRING_INCLUDED 18 | 19 | struct st_mysql_lex_string 20 | { 21 | char *str; 22 | size_t length; 23 | }; 24 | typedef struct st_mysql_lex_string MYSQL_LEX_STRING; 25 | 26 | struct st_mysql_const_lex_string 27 | { 28 | const char *str; 29 | size_t length; 30 | }; 31 | typedef struct st_mysql_const_lex_string MYSQL_LEX_CSTRING; 32 | 33 | #endif // MYSQL_LEX_STRING_INCLUDED 34 | -------------------------------------------------------------------------------- /dependencies/mysql/mysql/psi/mysql_memory.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software Foundation, 14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 15 | 16 | #ifndef MYSQL_MEMORY_H 17 | #define MYSQL_MEMORY_H 18 | 19 | /** 20 | @file mysql/psi/mysql_memory.h 21 | Instrumentation helpers for memory allocation. 22 | */ 23 | 24 | #include "mysql/psi/psi.h" 25 | 26 | #ifndef PSI_MEMORY_CALL 27 | #define PSI_MEMORY_CALL(M) PSI_DYNAMIC_CALL(M) 28 | #endif 29 | 30 | /** 31 | @defgroup Memory_instrumentation Memory Instrumentation 32 | @ingroup Instrumentation_interface 33 | @{ 34 | */ 35 | 36 | /** 37 | @def mysql_memory_register(P1, P2, P3) 38 | Memory registration. 39 | */ 40 | #define mysql_memory_register(P1, P2, P3) \ 41 | inline_mysql_memory_register(P1, P2, P3) 42 | 43 | static inline void inline_mysql_memory_register( 44 | #ifdef HAVE_PSI_MEMORY_INTERFACE 45 | const char *category, 46 | PSI_memory_info *info, 47 | int count) 48 | #else 49 | const char *category MY_ATTRIBUTE((unused)), 50 | void *info MY_ATTRIBUTE((unused)), 51 | int count MY_ATTRIBUTE((unused))) 52 | #endif 53 | { 54 | #ifdef HAVE_PSI_MEMORY_INTERFACE 55 | PSI_MEMORY_CALL(register_memory)(category, info, count); 56 | #endif 57 | } 58 | 59 | /** @} (end of group Memory_instrumentation) */ 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /dependencies/mysql/mysql_com_server.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 2 | 3 | This program is free software; you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation; version 2 of the License. 6 | 7 | This program is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | GNU General Public License for more details. 11 | 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 15 | 16 | /* 17 | Definitions private to the server, 18 | used in the networking layer to notify specific events. 19 | */ 20 | 21 | #ifndef _mysql_com_server_h 22 | #define _mysql_com_server_h 23 | 24 | struct st_net_server; 25 | 26 | typedef void (*before_header_callback_fn) 27 | (struct st_net *net, void *user_data, size_t count); 28 | 29 | typedef void (*after_header_callback_fn) 30 | (struct st_net *net, void *user_data, size_t count, my_bool rc); 31 | 32 | struct st_net_server 33 | { 34 | before_header_callback_fn m_before_header; 35 | after_header_callback_fn m_after_header; 36 | void *m_user_data; 37 | }; 38 | 39 | typedef struct st_net_server NET_SERVER; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /dependencies/mysql/mysql_embed.h: -------------------------------------------------------------------------------- 1 | #ifndef MYSQL_EMBED_INCLUDED 2 | #define MYSQL_EMBED_INCLUDED 3 | 4 | /* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; version 2 of the License. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 18 | 19 | /* Defines that are unique to the embedded version of MySQL */ 20 | 21 | #ifdef EMBEDDED_LIBRARY 22 | 23 | /* Things we don't need in the embedded version of MySQL */ 24 | /* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */ 25 | 26 | #undef HAVE_DLOPEN /* No udf functions */ 27 | 28 | #endif /* EMBEDDED_LIBRARY */ 29 | #endif /* MYSQL_EMBED_INCLUDED */ 30 | -------------------------------------------------------------------------------- /dependencies/mysql/mysql_version.h: -------------------------------------------------------------------------------- 1 | /* Copyright Abandoned 1996,1999 TCX DataKonsult AB & Monty Program KB 2 | & Detron HB, 1996, 1999-2004, 2007 MySQL AB. 3 | This file is public domain and comes with NO WARRANTY of any kind 4 | */ 5 | 6 | /* Version numbers for protocol & mysqld */ 7 | 8 | #ifndef _mysql_version_h 9 | #define _mysql_version_h 10 | #ifdef _CUSTOMCONFIG_ 11 | #include 12 | #else 13 | #define PROTOCOL_VERSION 10 14 | #define MYSQL_SERVER_VERSION "5.7.16" 15 | #define MYSQL_VERSION_ID 50716 16 | #define MYSQL_PORT 3306 17 | #define MYSQL_PORT_DEFAULT 0 18 | #define MYSQL_UNIX_ADDR "/tmp/mysql.sock" 19 | #define MYSQL_CONFIG_NAME "my" 20 | #define MYSQL_COMPILATION_COMMENT "MySQL Connector/C (GPL)" 21 | #define LIBMYSQL_VERSION "6.1.11" 22 | #define LIBMYSQL_VERSION_ID 60111 23 | 24 | /* mysqld compile time options */ 25 | #endif /* _CUSTOMCONFIG_ */ 26 | 27 | #ifndef LICENSE 28 | #define LICENSE GPL 29 | #endif /* LICENSE */ 30 | 31 | #endif /* _mysql_version_h */ 32 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/as_args.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this Spermission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_AS_ARGS_HPP 25 | #define SOL_AS_ARGS_HPP 26 | 27 | #include 28 | 29 | namespace sol { 30 | template 31 | struct as_args_t { 32 | T src; 33 | }; 34 | 35 | template 36 | auto as_args(Source&& source) { 37 | return as_args_t { std::forward(source) }; 38 | } 39 | 40 | namespace stack { 41 | template 42 | struct unqualified_pusher> { 43 | int push(lua_State* L, const as_args_t& e) { 44 | int p = 0; 45 | for (const auto& i : e.src) { 46 | p += stack::push(L, i); 47 | } 48 | return p; 49 | } 50 | }; 51 | } // namespace stack 52 | } // namespace sol 53 | 54 | #endif // SOL_AS_ARGS_HPP 55 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/compatibility/compat-5.4.h: -------------------------------------------------------------------------------- 1 | #ifndef NOT_KEPLER_PROJECT_COMPAT54_H_ 2 | #define NOT_KEPLER_PROJECT_COMPAT54_H_ 3 | 4 | #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) 5 | extern "C" { 6 | #endif 7 | #include 8 | #include 9 | #include 10 | #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) 11 | } 12 | #endif 13 | 14 | #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 504 15 | 16 | #if !defined(LUA_ERRGCMM) 17 | /* So Lua 5.4 actually removes this, which breaks sol2... 18 | man, this API is quite unstable...! 19 | */ 20 | # define LUA_ERRGCMM (LUA_ERRERR + 2) 21 | #endif /* LUA_ERRGCMM define */ 22 | 23 | #endif // Lua 5.4 only 24 | 25 | #endif // NOT_KEPLER_PROJECT_COMPAT54_H_ -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/config.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_CONFIG_HPP 25 | #define SOL_CONFIG_HPP 26 | 27 | /* Base, empty configuration file! 28 | 29 | To override, place a file in your include paths of the form: 30 | 31 | 32 | . (your include path here) 33 | | sol (directory, or equivalent) 34 | | config.hpp (your config.hpp file) 35 | 36 | 37 | So that when sol2 includes the file 38 | 39 | 40 | #include 41 | 42 | 43 | it gives you the configuration values you desire. Configuration values can be 44 | seen in the safety.rst of the doc/src, or at 45 | https://sol2.readthedocs.io/en/latest/safety.html ! You can also pass them through 46 | the build system, or the command line options of your compiler. 47 | 48 | */ 49 | 50 | #endif // SOL_CONFIG_HPP 51 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/deprecate.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_DEPRECATE_HPP 25 | #define SOL_DEPRECATE_HPP 26 | 27 | #ifndef SOL_DEPRECATED 28 | #ifdef _MSC_VER 29 | #define SOL_DEPRECATED __declspec(deprecated) 30 | #elif __GNUC__ 31 | #define SOL_DEPRECATED __attribute__((deprecated)) 32 | #else 33 | #define SOL_DEPRECATED [[deprecated]] 34 | #endif // compilers 35 | #endif // SOL_DEPRECATED 36 | 37 | namespace sol { 38 | namespace detail { 39 | template 40 | struct SOL_DEPRECATED deprecate_type { 41 | using type = T; 42 | }; 43 | } 44 | } // namespace sol::detail 45 | 46 | #endif // SOL_DEPRECATE_HPP 47 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/function_types_core.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_FUNCTION_TYPES_CORE_HPP 25 | #define SOL_FUNCTION_TYPES_CORE_HPP 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | namespace sol { 33 | namespace function_detail { 34 | template 35 | int call(lua_State* L) { 36 | Fx& fx = stack::get>(L, upvalue_index(start)); 37 | int nr = fx(L); 38 | if (is_yielding) { 39 | return lua_yield(L, nr); 40 | } 41 | else { 42 | return nr; 43 | } 44 | } 45 | } 46 | } // namespace sol::function_detail 47 | 48 | #endif // SOL_FUNCTION_TYPES_CORE_HPP 49 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/in_place.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_IN_PLACE_HPP 25 | #define SOL_IN_PLACE_HPP 26 | 27 | #include 28 | #include 29 | 30 | namespace sol { 31 | 32 | using in_place_t = std::in_place_t; 33 | constexpr std::in_place_t in_place {}; 34 | constexpr std::in_place_t in_place_of {}; 35 | 36 | template 37 | using in_place_type_t = std::in_place_type_t; 38 | template 39 | constexpr std::in_place_type_t in_place_type {}; 40 | 41 | template 42 | using in_place_index_t = std::in_place_index_t; 43 | template 44 | constexpr in_place_index_t in_place_index {}; 45 | 46 | } // namespace sol 47 | 48 | #endif // SOL_IN_PLACE_HPP 49 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/stack_check.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_STACK_CHECK_HPP 25 | #define SOL_STACK_CHECK_HPP 26 | 27 | #include 28 | #include 29 | 30 | #endif // SOL_STACK_CHECK_HPP 31 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/stack_check_get.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_STACK_CHECK_GET_HPP 25 | #define SOL_STACK_CHECK_GET_HPP 26 | 27 | #include 28 | #include 29 | 30 | #endif // SOL_STACK_CHECK_GET_HPP 31 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/stack_get.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_STACK_GET_HPP 25 | #define SOL_STACK_GET_HPP 26 | 27 | #include 28 | #include 29 | 30 | #endif // SOL_STACK_GET_HPP 31 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/stack_get_qualified.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_STACK_QUALIFIED_GET_HPP 25 | #define SOL_STACK_QUALIFIED_GET_HPP 26 | 27 | #include 28 | 29 | namespace sol { 30 | namespace stack { 31 | 32 | // There are no more enable_ifs that can be used here, 33 | // so this is just for posterity, I guess? 34 | // maybe I'll fill this file in later. 35 | 36 | } 37 | } // namespace sol::stack 38 | 39 | #endif // SOL_STACK_QUALIFIED_GET_HPP 40 | 41 | -------------------------------------------------------------------------------- /dependencies/sol2/include/sol/string_view.hpp: -------------------------------------------------------------------------------- 1 | // sol3 2 | 3 | // The MIT License (MIT) 4 | 5 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 6 | 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | // this software and associated documentation files (the "Software"), to deal in 9 | // the Software without restriction, including without limitation the rights to 10 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | // the Software, and to permit persons to whom the Software is furnished to do so, 12 | // subject to the following conditions: 13 | 14 | // The above copyright notice and this permission notice shall be included in all 15 | // copies or substantial portions of the Software. 16 | 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 19 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 20 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 21 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | #ifndef SOL_STRING_VIEW_HPP 25 | #define SOL_STRING_VIEW_HPP 26 | 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | namespace sol { 35 | template > 36 | using basic_string_view = std::basic_string_view; 37 | 38 | typedef std::string_view string_view; 39 | typedef std::wstring_view wstring_view; 40 | typedef std::u16string_view u16string_view; 41 | typedef std::u32string_view u32string_view; 42 | typedef std::hash string_view_hash; 43 | } // namespace sol 44 | 45 | #endif // SOL_STRING_VIEW_HPP 46 | -------------------------------------------------------------------------------- /doc/C1001.txt: -------------------------------------------------------------------------------- 1 | proxy_base.hpp(66,3): fatal error C1001: Internal compiler error. 2 | (compiler file 'msc1.cpp', line 1588) 3 | 4 | solution: 5 | gutting the macro SOL_PROXY_BASE_IMPL_MSVC_IS_TRASH_I_ -------------------------------------------------------------------------------- /example/Http_Ext.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "HttpServer.h" 6 | #include "EventLoop.h" 7 | #include "HttpConnect.h" 8 | #include "HttpParser.h" 9 | #include 10 | 11 | class HttpExt 12 | { 13 | public: 14 | void printField(const char* p, int len) 15 | { 16 | std::string_view v(p, len); 17 | std::cout << v <<": "; 18 | } 19 | 20 | void printValue(const char* p, int len) 21 | { 22 | std::string_view v(p, len); 23 | std::cout << v << std::endl; 24 | } 25 | }; 26 | 27 | HttpExt httpext; 28 | 29 | int main() 30 | { 31 | EventLoop::Instance()->init(); 32 | HttpServer server(EventLoop::Instance()); 33 | server.listen("127.0.0.1", 80); 34 | 35 | server.addGet("/", [](HttpConnect* conn, std::string_view& data) { 36 | conn->autoMsg("hello world"); 37 | }); 38 | 39 | HttpSettings* setting = getHttpSettings(); 40 | setting->on_message_begin = [](llhttp_t* http)->int { 41 | http->data = &httpext; 42 | return 0; 43 | }; 44 | 45 | setting->on_header_field = [](llhttp_t* http, const char* at, size_t length)->int { 46 | HttpExt* ext = (HttpExt*)(http->data); 47 | ext->printField(at, length); 48 | return 0; 49 | }; 50 | 51 | setting->on_header_value = [](llhttp_t* http, const char* at, size_t length)->int { 52 | HttpExt* ext = (HttpExt*)(http->data); 53 | ext->printValue(at, length); 54 | return 0; 55 | }; 56 | 57 | EventLoop::Instance()->run(); 58 | return 0; 59 | } -------------------------------------------------------------------------------- /example/Redis_Test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include "hiredis.h" 6 | #include "DB_Interface_redis.h" 7 | #include "XLog.h" 8 | #include "RedisResult.h" 9 | #include 10 | #include "RedisCommand.h" 11 | #include 12 | #include "DBThreadPool.h" 13 | #include "Tools.h" 14 | 15 | void select(DBThreadPool * pool) 16 | { 17 | std::shared_ptr command(new RedisCommand("lrange")); 18 | command->pushString("t1"); 19 | command->pushString("0"); 20 | command->pushString("10"); 21 | 22 | std::shared_ptr result(new RedisResult); 23 | 24 | std::shared_ptr task(new DBRedisTask(command, result)); 25 | 26 | task->backfunc = [](int errno_, const char * err, std::shared_ptr result) { 27 | 28 | while (result->fetch()) 29 | { 30 | int32 value; 31 | *result >> value; 32 | printf("%d\n", value); 33 | } 34 | }; 35 | 36 | pool->addTask(task); 37 | } 38 | 39 | void insert(DBThreadPool * pool) 40 | { 41 | std::shared_ptr command(new RedisCommand("lpush")); 42 | command->pushString("t1"); 43 | command->pushInt32(1); 44 | command->pushInt32(22); 45 | command->pushInt32(333); 46 | 47 | std::shared_ptr task(new DBRedisTask(command, std::make_shared())); 48 | task->backfunc = [pool](int errno_, const char* err, std::shared_ptr result) { 49 | select(pool); 50 | }; 51 | 52 | pool->addTask(task); 53 | } 54 | 55 | int main() 56 | { 57 | DBConfig config; 58 | config.device = "redis"; 59 | config.ip = "127.0.0.1"; 60 | config.port = 6379; 61 | 62 | DBThreadPool pool(config); 63 | pool.create(1); 64 | 65 | insert(&pool); 66 | 67 | while (1) 68 | { 69 | Tools::sleep(10); 70 | pool.update(); 71 | } 72 | 73 | system("pause"); 74 | return 0; 75 | } -------------------------------------------------------------------------------- /example/Test_Tcp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/Test_Tcp.cpp -------------------------------------------------------------------------------- /example/Test_Timer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "BaseType.h" 5 | #include "Timer.h" 6 | #include "Tools.h" 7 | 8 | 9 | 10 | int main() 11 | { 12 | Timer::init(); 13 | 14 | 15 | Timer timer1; 16 | Timer timer2; 17 | 18 | timer1.start([](){ 19 | printf("--->30\n"); 20 | },30 * 1000); 21 | 22 | timer2.start([](){ 23 | printf("--->10\n"); 24 | }, 10 * 1000, 10 * 1000); 25 | 26 | Timer * timer3 = new Timer; 27 | timer3->start([&](){ 28 | printf("--->20\n"); 29 | 30 | timer3->stop(); 31 | delete timer3; 32 | 33 | 34 | }, 20 * 1000, 1000); 35 | 36 | 37 | while (1) 38 | { 39 | Tools::sleep(10); 40 | Timer::update(); 41 | } 42 | 43 | system("pause"); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /example/Test_Udp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/Test_Udp.cpp -------------------------------------------------------------------------------- /example/Test_WebSocket.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/Test_WebSocket.cpp -------------------------------------------------------------------------------- /example/cpp_lua/cpp_server.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/cpp_lua/cpp_server.cpp -------------------------------------------------------------------------------- /example/cpp_lua/gen_cpp.bat: -------------------------------------------------------------------------------- 1 | cd ../../tool 2 | serialization_cpp.exe ../example/cpp_lua/types.msg 3 | serialization_cpp.exe ../example/cpp_lua/testmsg.msg -------------------------------------------------------------------------------- /example/cpp_lua/gen_lua.bat: -------------------------------------------------------------------------------- 1 | cd ../../tool 2 | serialization_lua.exe ../example/cpp_lua/types.msg 3 | serialization_lua.exe ../example/cpp_lua/testmsg.msg -------------------------------------------------------------------------------- /example/cpp_lua/lua_client.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe lua_client.lua -------------------------------------------------------------------------------- /example/cpp_lua/lua_client.lua: -------------------------------------------------------------------------------- 1 | require("testmsg") 2 | 3 | event_init() 4 | 5 | -- create server 6 | client = NetClient:new() 7 | client.on_connect = function(conn) 8 | print("on onnect") 9 | end 10 | 11 | client.on_close = function(conn) 12 | print("close") 13 | end 14 | 15 | client.on_msg = function(conn, msgtype, pack) 16 | 17 | msg = testmsg:new(); 18 | msg:read(pack); 19 | 20 | print("id:"..msg.id); 21 | print("play.name :" .. msg.play.name); 22 | print("play.level:" .. msg.play.level); 23 | print("play.msgcount:".. msg.play.msgcount); 24 | 25 | for i = 1, #msg.array, 1 do 26 | print("array: " .. msg.array[i]); 27 | end 28 | 29 | for i = 1, #msg.attrs, 1 do 30 | 31 | print(i.. " attack:" ..msg.attrs[i].attack); 32 | print(i.. " hp:" .. msg.attrs[i].hp); 33 | end 34 | 35 | for i = 1, #msg.vstr, 1 do 36 | 37 | print("vstr: " .. msg.vstr[i]); 38 | end 39 | 40 | print("----------------------------------------"); 41 | 42 | conn:sendPacket(1, pack) 43 | end 44 | 45 | client:connect("127.0.0.1", 3001, false); 46 | 47 | event_run() -------------------------------------------------------------------------------- /example/cpp_lua/testmsg.cpp: -------------------------------------------------------------------------------- 1 | #include "testmsg.h" 2 | #include "ByteBuffer.h" 3 | bool testmsg::read(ByteBuffer * buffer) 4 | { 5 | if(sizeof(id) + buffer->rpos() > buffer->wpos()) return false; 6 | *buffer >> id; 7 | if(play.read(buffer) == false) return false; 8 | int len_array; 9 | if(sizeof(len_array) + buffer->rpos() > buffer->wpos()) return false; 10 | *buffer >> len_array; 11 | for( int i = 0; i< len_array; ++i) { 12 | int32 temp_array; 13 | if(sizeof(temp_array) + buffer->rpos() > buffer->wpos()) return false; 14 | *buffer >> temp_array; 15 | array.push_back(temp_array); 16 | } 17 | int len_attrs; 18 | if(sizeof(len_attrs) + buffer->rpos() > buffer->wpos()) return false; 19 | *buffer >> len_attrs; 20 | for( int i = 0; i< len_attrs; ++i) { 21 | Attr temp_attrs; 22 | if(temp_attrs.read(buffer) == false) return false; 23 | attrs.push_back(temp_attrs); 24 | } 25 | int len_vstr; 26 | if(sizeof(len_vstr) + buffer->rpos() > buffer->wpos()) return false; 27 | *buffer >> len_vstr; 28 | for( int i = 0; i< len_vstr; ++i) { 29 | std::string temp_vstr; 30 | *buffer >> temp_vstr; 31 | vstr.push_back(temp_vstr); 32 | } 33 | return true; 34 | } 35 | void testmsg::write(ByteBuffer * buffer) 36 | { 37 | *buffer << id; 38 | play.write(buffer); 39 | int len_array = array.size(); 40 | *buffer << len_array; 41 | for( int i = 0; i< len_array; ++i) { 42 | *buffer << array[i]; 43 | } 44 | int len_attrs = attrs.size(); 45 | *buffer << len_attrs; 46 | for( int i = 0; i< len_attrs; ++i) { 47 | attrs[i].write(buffer); 48 | } 49 | int len_vstr = vstr.size(); 50 | *buffer << len_vstr; 51 | for( int i = 0; i< len_vstr; ++i) { 52 | *buffer << vstr[i]; 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /example/cpp_lua/testmsg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseType.h" 4 | #include 5 | class ByteBuffer; 6 | 7 | #include "types.h" 8 | struct testmsg 9 | { 10 | public: 11 | ID id; 12 | Player play; 13 | Array array; 14 | std::vector attrs; 15 | std::vector vstr; 16 | bool read(ByteBuffer * buffer); 17 | void write(ByteBuffer * buffer); 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /example/cpp_lua/testmsg.lua: -------------------------------------------------------------------------------- 1 | require("types") 2 | testmsg = {} 3 | testmsg.__index = testmsg 4 | function testmsg:read(buffer) 5 | if 4 + buffer:rpos() > buffer:wpos() then return false end 6 | self.id = buffer:getUint32(); 7 | self.play = Player:new() 8 | if self.play:read(buffer) == false then return false end; 9 | local len_array = 0 10 | local temp_array = nil 11 | if 4 + buffer:rpos() > buffer:wpos() then return false end 12 | len_array = buffer:getInt32(); 13 | for i = 1, len_array, 1 do 14 | if 4 + buffer:rpos() > buffer:wpos() then return false end 15 | temp_array = buffer:getInt32(); 16 | self.array[i] = temp_array 17 | end 18 | local len_attrs = 0 19 | local temp_attrs = nil 20 | if 4 + buffer:rpos() > buffer:wpos() then return false end 21 | len_attrs = buffer:getInt32(); 22 | for i = 1, len_attrs, 1 do 23 | temp_attrs = Attr:new() 24 | if temp_attrs:read(buffer) == false then return false end; 25 | self.attrs[i] = temp_attrs 26 | end 27 | local len_vstr = 0 28 | local temp_vstr = nil 29 | if 4 + buffer:rpos() > buffer:wpos() then return false end 30 | len_vstr = buffer:getInt32(); 31 | for i = 1, len_vstr, 1 do 32 | temp_vstr = buffer:getString(); 33 | self.vstr[i] = temp_vstr 34 | end 35 | return true; 36 | end 37 | function testmsg:write(buffer) 38 | buffer:pushUint32(self.id); 39 | self.play:write(buffer); 40 | local len_array = #self.array 41 | buffer:pushInt32(len_array); 42 | for i = 1, len_array, 1 do 43 | buffer:pushInt32(self.array[i]); 44 | end 45 | local len_attrs = #self.attrs 46 | buffer:pushInt32(len_attrs); 47 | for i = 1, len_attrs, 1 do 48 | self.attrs[i]:write(buffer); 49 | end 50 | local len_vstr = #self.vstr 51 | buffer:pushInt32(len_vstr); 52 | for i = 1, len_vstr, 1 do 53 | buffer:pushString(self.vstr[i]); 54 | end 55 | end 56 | function testmsg:new() 57 | local o = {} 58 | setmetatable(o, testmsg) 59 | o.id = 0 60 | o.play = {} 61 | o.array = {} 62 | o.attrs = {} 63 | o.vstr = {} 64 | return o 65 | end 66 | 67 | 68 | -------------------------------------------------------------------------------- /example/cpp_lua/testmsg.msg: -------------------------------------------------------------------------------- 1 | import types.msg 2 | 3 | struct testmsg 4 | { 5 | ID id 6 | Player play 7 | Array array 8 | vector attrs 9 | vector vstr 10 | 11 | read{ 12 | [id, play, array, attrs, vstr] 13 | } 14 | write{ 15 | [id, play, array, attrs, vstr] 16 | } 17 | } -------------------------------------------------------------------------------- /example/cpp_lua/types.cpp: -------------------------------------------------------------------------------- 1 | #include "types.h" 2 | #include "ByteBuffer.h" 3 | bool Player::read(ByteBuffer * buffer) 4 | { 5 | *buffer >> name; 6 | if(sizeof(level) + buffer->rpos() > buffer->wpos()) return false; 7 | *buffer >> level; 8 | if(level>=30) 9 | { 10 | if(sizeof(msgcount) + buffer->rpos() > buffer->wpos()) return false; 11 | *buffer >> msgcount; 12 | 13 | } 14 | return true; 15 | } 16 | void Player::write(ByteBuffer * buffer) 17 | { 18 | *buffer << name; 19 | *buffer << level; 20 | if(level>=30) 21 | { 22 | *buffer << msgcount; 23 | 24 | } 25 | } 26 | bool Attr::read(ByteBuffer * buffer) 27 | { 28 | if(sizeof(attack) + buffer->rpos() > buffer->wpos()) return false; 29 | *buffer >> attack; 30 | if(sizeof(hp) + buffer->rpos() > buffer->wpos()) return false; 31 | *buffer >> hp; 32 | return true; 33 | } 34 | void Attr::write(ByteBuffer * buffer) 35 | { 36 | *buffer << attack; 37 | *buffer << hp; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /example/cpp_lua/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseType.h" 4 | #include 5 | class ByteBuffer; 6 | 7 | typedef uint32 ID; 8 | typedef std::vector Array; 9 | struct Player 10 | { 11 | public: 12 | std::string name; 13 | int32 level; 14 | int32 msgcount; 15 | bool read(ByteBuffer * buffer); 16 | void write(ByteBuffer * buffer); 17 | }; 18 | struct Attr 19 | { 20 | public: 21 | int32 attack; 22 | int32 hp; 23 | bool read(ByteBuffer * buffer); 24 | void write(ByteBuffer * buffer); 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /example/cpp_lua/types.lua: -------------------------------------------------------------------------------- 1 | Player = {} 2 | Player.__index = Player 3 | function Player:read(buffer) 4 | self.name = buffer:getString(); 5 | if 4 + buffer:rpos() > buffer:wpos() then return false end 6 | self.level = buffer:getInt32(); 7 | if self.level>=30 then 8 | if 4 + buffer:rpos() > buffer:wpos() then return false end 9 | self.msgcount = buffer:getInt32(); 10 | 11 | end 12 | return true; 13 | end 14 | function Player:write(buffer) 15 | buffer:pushString(self.name); 16 | buffer:pushInt32(self.level); 17 | if self.level>=30 then 18 | buffer:pushInt32(self.msgcount); 19 | 20 | end 21 | end 22 | function Player:new() 23 | local o = {} 24 | setmetatable(o, Player) 25 | o.name = "" 26 | o.level = 0 27 | o.msgcount = 0 28 | return o 29 | end 30 | 31 | Attr = {} 32 | Attr.__index = Attr 33 | function Attr:read(buffer) 34 | if 4 + buffer:rpos() > buffer:wpos() then return false end 35 | self.attack = buffer:getInt32(); 36 | if 4 + buffer:rpos() > buffer:wpos() then return false end 37 | self.hp = buffer:getInt32(); 38 | return true; 39 | end 40 | function Attr:write(buffer) 41 | buffer:pushInt32(self.attack); 42 | buffer:pushInt32(self.hp); 43 | end 44 | function Attr:new() 45 | local o = {} 46 | setmetatable(o, Attr) 47 | o.attack = 0 48 | o.hp = 0 49 | return o 50 | end 51 | 52 | 53 | -------------------------------------------------------------------------------- /example/cpp_lua/types.msg: -------------------------------------------------------------------------------- 1 | typedef uint32 ID 2 | typedef vector Array 3 | 4 | struct Player 5 | { 6 | string name 7 | int32 level 8 | int32 msgcount 9 | 10 | read{ 11 | [name, level] 12 | if(level >= 30) 13 | { 14 | [msgcount] 15 | } 16 | } 17 | write{ 18 | [name, level] 19 | if(level >= 30) 20 | { 21 | [msgcount] 22 | } 23 | } 24 | } 25 | 26 | struct Attr 27 | { 28 | int32 attack 29 | int32 hp 30 | 31 | read{ 32 | [attack, hp] 33 | } 34 | write{ 35 | [attack, hp] 36 | } 37 | } -------------------------------------------------------------------------------- /example/cpp_lua_protobuf/client/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/cpp_lua_protobuf/client/main.cpp -------------------------------------------------------------------------------- /example/cpp_lua_protobuf/msgtest.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message Role 4 | { 5 | int32 id = 1; 6 | string name = 2; 7 | int32 money = 3; 8 | repeated int32 tasks = 4; 9 | } 10 | 11 | message Family 12 | { 13 | string name = 1; 14 | int32 lv = 2; 15 | repeated Role roles = 3; 16 | } -------------------------------------------------------------------------------- /example/cpp_lua_protobuf/protoc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/cpp_lua_protobuf/protoc.exe -------------------------------------------------------------------------------- /example/cpp_lua_protobuf/server/msgtest.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/cpp_lua_protobuf/server/msgtest.pb -------------------------------------------------------------------------------- /example/cpp_lua_protobuf/server/server.bat: -------------------------------------------------------------------------------- 1 | start ../../../bin/engine.exe server.lua 2 | pause -------------------------------------------------------------------------------- /example/cpp_lua_protobuf/server/server.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/cpp_lua_protobuf/server/server.lua -------------------------------------------------------------------------------- /example/cpp_lua_protobuf/生成c++.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/example/cpp_lua_protobuf/生成c++.bat -------------------------------------------------------------------------------- /example/cpp_lua_protobuf/生成pb文件.bat: -------------------------------------------------------------------------------- 1 | protoc -o ./server/msgtest.pb msgtest.proto -------------------------------------------------------------------------------- /example/csv_lua/config.csv: -------------------------------------------------------------------------------- 1 | 唯一id,名称,值 2 | id,name,value 3 | 1,hello,10 4 | 2,c++,20 5 | 3,engine,30 6 | -------------------------------------------------------------------------------- /example/csv_lua/csv.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe test.lua 2 | pause -------------------------------------------------------------------------------- /example/csv_lua/test.lua: -------------------------------------------------------------------------------- 1 | local csv = CsvParser:new("config.csv", 2, ',') 2 | 3 | for i = 1, csv:row(), 1 do 4 | local id = csv:getInt32(i, "id") 5 | local name = csv:getString(i, "name") 6 | local value = csv:getInt32(i, "value") 7 | print(id.." | ".. name .. " | ".. value) 8 | end -------------------------------------------------------------------------------- /example/db_blob/blob.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe test.lua -------------------------------------------------------------------------------- /example/db_blob/gen_lua.bat: -------------------------------------------------------------------------------- 1 | cd ../../tool 2 | serialization_lua.exe ../example/db_blob/struct.blob -------------------------------------------------------------------------------- /example/db_blob/struct.blob: -------------------------------------------------------------------------------- 1 | struct test_blob 2 | { 3 | int32 id 4 | string str 5 | vector vec 6 | 7 | read{ 8 | [id, str, vec] 9 | } 10 | write{ 11 | [id, str, vec] 12 | } 13 | } -------------------------------------------------------------------------------- /example/db_blob/struct.lua: -------------------------------------------------------------------------------- 1 | test_blob = {} 2 | test_blob.__index = test_blob 3 | function test_blob:read(buffer) 4 | if 4 + buffer:rpos() > buffer:wpos() then return false end 5 | self.id = buffer:getInt32(); 6 | self.str = buffer:getString(); 7 | local len_vec = 0 8 | local temp_vec = nil 9 | if 4 + buffer:rpos() > buffer:wpos() then return false end 10 | len_vec = buffer:getInt32(); 11 | for i = 1, len_vec, 1 do 12 | if 4 + buffer:rpos() > buffer:wpos() then return false end 13 | temp_vec = buffer:getInt32(); 14 | self.vec[i] = temp_vec 15 | end 16 | return true; 17 | end 18 | function test_blob:write(buffer) 19 | buffer:pushInt32(self.id); 20 | buffer:pushString(self.str); 21 | local len_vec = #self.vec 22 | buffer:pushInt32(len_vec); 23 | for i = 1, len_vec, 1 do 24 | buffer:pushInt32(self.vec[i]); 25 | end 26 | end 27 | function test_blob:new() 28 | local o = {} 29 | setmetatable(o, test_blob) 30 | o.id = 0 31 | o.str = "" 32 | o.vec = {} 33 | return o 34 | end 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/db_blob/test.lua: -------------------------------------------------------------------------------- 1 | require("struct") 2 | 3 | local config = DBConfig:new() 4 | config.device = "mysql" 5 | config.ip = "192.168.1.77" 6 | config.dbname = "jw_test" 7 | config.user = "root" 8 | config.pswd = "1111" 9 | config.port = 3306 10 | 11 | pool = DBThreadPool:new(config) 12 | pool:create(1) 13 | 14 | function select() 15 | local sql = SqlCommand:new("select id, blo from t_blob") 16 | local func = function(errno, err, result) 17 | while(result:fetch()) 18 | do 19 | print("tableid:" .. result:getInt32()) 20 | local pack = BasePacket:new() 21 | if result:readBlob(pack) > 0 then 22 | local st = test_blob:new() 23 | st:read(pack) 24 | print("id:".. st.id .. ", str:" .. st.str) 25 | for i = 1, #st.vec, 1 do 26 | print(st.vec[i]) 27 | end 28 | end 29 | end 30 | end 31 | sql:addToPool(pool, func) 32 | end 33 | 34 | function insert() 35 | local sql = SqlCommand:new("insert into t_blob(id, blo) values(?, ?)") 36 | sql:pushInt32(1) 37 | 38 | local st = test_blob:new() 39 | st.id = 1314 40 | st.str = "hello c++20" 41 | st.vec = {1314,520,666} 42 | local pack = BasePacket:new() 43 | st:write(pack) 44 | sql:pushBlob(pack) 45 | sql:addToPool(pool, function(errno, err,result) 46 | select() 47 | end) 48 | end 49 | 50 | select() 51 | 52 | event_init() 53 | 54 | timer = UTimer:new() 55 | timer:start(function () 56 | pool:update() 57 | end, 10, 10) 58 | 59 | event_run() -------------------------------------------------------------------------------- /example/http_server.lua: -------------------------------------------------------------------------------- 1 | msg = [[ 2 | 3 |

hello world

4 | 5 | ]] 6 | 7 | event_init() 8 | 9 | server = HttpServer:new() 10 | server:listen("127.0.0.1", 80) 11 | server:addGet("/", function(conn, data) 12 | local hp = HttpParam:new(data, '&') 13 | if hp:find("a") and hp:find("b") then 14 | local a = hp:getStr("a") 15 | local b = hp:getStr("b") 16 | print(a.."|"..b) 17 | end 18 | conn:autoMsg(msg) 19 | end) 20 | 21 | 22 | event_run() -------------------------------------------------------------------------------- /example/js_websocket/server.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe server.lua -------------------------------------------------------------------------------- /example/js_websocket/server.lua: -------------------------------------------------------------------------------- 1 | -- init 2 | event_init() 3 | 4 | -- create server 5 | server = WebSocketServer:new() 6 | server.on_accept = function(conn) 7 | print("connect") 8 | end 9 | 10 | server.on_close = function(conn) 11 | print("close") 12 | end 13 | 14 | server.on_msg = function(conn, pack) 15 | print(pack:getInt32()) 16 | print(utf8_gbk(pack:getString())) 17 | print(pack:getInt32()) 18 | 19 | local retpak = WebSocketPacket:new() 20 | retpak:pushString('hello client') 21 | conn:sendPacket(retpak) 22 | end 23 | 24 | server:listen("127.0.0.1", 8080, false) 25 | 26 | event_run() -------------------------------------------------------------------------------- /example/js_websocket/start.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

run websocket

4 | 5 | 6 | -------------------------------------------------------------------------------- /example/js_websocket/websocket.js: -------------------------------------------------------------------------------- 1 | var ws = new WebSocket("ws://localhost:8080"); 2 | ws.onopen = function() 3 | { 4 | var pos = 0; 5 | var msg = "你好 jwEngine"; 6 | var buff = new ArrayBuffer(4 + (msg.length + 1) + 4); 7 | var dv = new DataView(buff); 8 | dv.setInt32(pos, 110, true); 9 | pos += 4; 10 | for (var i=0; i { 28 | var str = "" 29 | var buff = reader.result; 30 | var dv = new DataView(buff); 31 | // c++ char* end is 0 32 | for (var i=0; i < evt.data.size - 1; i++) 33 | { 34 | str += String.fromCharCode(dv.getUint8(i, true)); 35 | } 36 | alert(str) 37 | }; 38 | }; 39 | 40 | ws.onclose = function() 41 | { 42 | alert("close"); 43 | }; 44 | -------------------------------------------------------------------------------- /example/lua_json/json.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe json.lua -------------------------------------------------------------------------------- /example/lua_json/json.lua: -------------------------------------------------------------------------------- 1 | local str = "{\"num\": 11, \"obj\":{\"a\":12, \"b\":13}, \"array\":[1314,520]}" 2 | local buff = JsonBuff:new(str) 3 | local jobj = json_parser(buff) 4 | if jobj then 5 | -- C++ returns the parent class, need convert to subclass 6 | obj = json_to_obj(jobj) 7 | print("num:" .. obj:getInt("num") .. "\n") 8 | 9 | local str = json_write(jobj, true) 10 | print(str) 11 | else 12 | print("parser error:" .. json_error(buff)) 13 | end 14 | 15 | local json = require "jsonlib/json" 16 | 17 | local tab = json.decode(str) -- json to lua table 18 | local jstr = json.encode(tab) -- lua table to json 19 | print(jstr) -------------------------------------------------------------------------------- /example/lua_kcp/client.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe client.lua 2 | pause -------------------------------------------------------------------------------- /example/lua_kcp/client.lua: -------------------------------------------------------------------------------- 1 | event_init() 2 | 3 | -- create server 4 | client = KcpClient:new() 5 | client.on_connect = function(conn, argv) 6 | print("on onnect:".. argv) 7 | end 8 | 9 | client.on_close = function(conn) 10 | print("close") 11 | end 12 | 13 | count = 0 14 | client.on_msg = function(conn, msgtype, pack) 15 | local str = pack:getString() 16 | --print(str) 17 | conn:sendPacket(1, pack) 18 | count = count + 1 19 | end 20 | 21 | client:createSession("127.0.0.1", 3001, false); 22 | 23 | t = UTimer:new() 24 | t:start(function() 25 | print(count) 26 | count = 0 27 | end, 1000,1000) 28 | 29 | event_run() -------------------------------------------------------------------------------- /example/lua_kcp/server.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe server.lua 2 | pause -------------------------------------------------------------------------------- /example/lua_kcp/server.lua: -------------------------------------------------------------------------------- 1 | -- init 2 | event_init() 3 | 4 | -- create server 5 | server = KcpServer:new() 6 | server.on_accept = function(conn) 7 | local pack = KcpPacket:new() 8 | pack:pushString("hello world, hello c++") 9 | conn:sendPacket(1, pack) 10 | end 11 | 12 | server.on_close = function(conn) 13 | print("close") 14 | end 15 | 16 | server.on_msg = function(conn, msgtype, pack) 17 | local str = pack:getString() 18 | --print(str) 19 | conn:sendPacket(1, pack) 20 | end 21 | 22 | server:start("127.0.0.1", 3001, false) 23 | 24 | event_run() -------------------------------------------------------------------------------- /example/lua_tcp/client.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe client.lua 2 | pause -------------------------------------------------------------------------------- /example/lua_tcp/client.lua: -------------------------------------------------------------------------------- 1 | event_init() 2 | 3 | -- create server 4 | client = NetClient:new() 5 | client.on_connect = function(conn, argv) 6 | print("on onnect:".. argv) 7 | end 8 | 9 | client.on_close = function(conn) 10 | print("close") 11 | end 12 | 13 | client.on_msg = function(conn, msgtype, pack) 14 | local str = pack:getString() 15 | print(str) 16 | conn:sendPacket(1, pack) 17 | end 18 | 19 | client:connect("127.0.0.1", 3001, false, 1); 20 | 21 | event_run() -------------------------------------------------------------------------------- /example/lua_tcp/server.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe server.lua 2 | pause -------------------------------------------------------------------------------- /example/lua_tcp/server.lua: -------------------------------------------------------------------------------- 1 | -- init 2 | event_init() 3 | 4 | -- create server 5 | server = NetServer:new() 6 | server.on_accept = function(conn) 7 | local pack = NetPacket:new() 8 | pack:pushString("msg ...") 9 | conn:sendPacket(1, pack) 10 | end 11 | 12 | server.on_close = function(conn) 13 | print("close") 14 | end 15 | 16 | server.on_msg = function(conn, msgtype, pack) 17 | local str = pack:getString() 18 | print(str) 19 | conn:sendPacket(1, pack) 20 | end 21 | 22 | server:listen("127.0.0.1", 3001, false) 23 | 24 | event_run() -------------------------------------------------------------------------------- /example/mysql/createdb.bat: -------------------------------------------------------------------------------- 1 | mysql -uroot -p111111 "+str(type)) 7 | rpack = socket_buffer.NetPacket() 8 | rpack.receive(buff) 9 | print(rpack.getInt32()) 10 | print(rpack.getString()) 11 | print(rpack.getInt16()) 12 | 13 | client = net.TcpClient("127.0.0.1", 3001) 14 | client.set_on_msg(onMsg) 15 | client.start() 16 | 17 | pack = socket_buffer.NetPacket() 18 | pack.pushString("abcdefg") 19 | pack.pushInt32(1314) 20 | pack.pushString("jwEngine") 21 | pack.pushInt32(520) 22 | pack.setHead(100011) 23 | 24 | client.send(pack.getSendData()) 25 | 26 | 27 | while True: 28 | time.sleep(0.1) 29 | client.update() 30 | 31 | 32 | client.close() -------------------------------------------------------------------------------- /example/redis_test.lua: -------------------------------------------------------------------------------- 1 | local config = DBConfig:new() 2 | config.device = "redis" 3 | config.ip = "127.0.0.1" 4 | config.port = 6379 5 | 6 | pool = DBThreadPool:new(config) 7 | pool:create(1) 8 | 9 | func = function(errno, err, result) 10 | if errno ~= 0 then 11 | print(err) 12 | return 13 | end 14 | 15 | while(result:fetch()) 16 | do 17 | local str = result:getString() 18 | -- errorLog(str) 19 | print(str) 20 | end 21 | end 22 | 23 | function exec() 24 | local command = RedisCommand:new("lrange") 25 | command:pushString("t1") 26 | command:pushString("0") 27 | command:pushString("10") 28 | command:addToPool(pool, func) 29 | end 30 | 31 | exec() 32 | event_init() 33 | 34 | timer = UTimer:new() 35 | timer:start(function () 36 | pool:update() 37 | end, 10, 10) 38 | 39 | event_run() -------------------------------------------------------------------------------- /example/rpc/call.lua: -------------------------------------------------------------------------------- 1 | rpcfunc = {} 2 | rpcids = {} 3 | function register(func) 4 | local callid = #rpcfunc + 1 5 | rpcfunc[callid] = func 6 | rpcids[func] = callid 7 | end 8 | 9 | function getcallid(func) 10 | return rpcids[func] 11 | end 12 | 13 | function getcallfu(callid) 14 | return rpcfunc[callid] 15 | end -------------------------------------------------------------------------------- /example/rpc/client.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe client.lua 2 | -------------------------------------------------------------------------------- /example/rpc/client.lua: -------------------------------------------------------------------------------- 1 | require "logic" 2 | 3 | event_init() 4 | 5 | -- create server 6 | client = NetClient:new() 7 | client.on_connect = function(conn, argv) 8 | Logic:onConnect(conn) 9 | end 10 | 11 | client.on_close = function(conn) 12 | Logic:onClose(conn) 13 | end 14 | 15 | client.on_msg = function(conn, msgtype, pack) 16 | Logic:onMsg(conn, msgtype, pack) 17 | end 18 | 19 | client:connect("127.0.0.1", 3001, false, 1); 20 | 21 | event_run() -------------------------------------------------------------------------------- /example/rpc/logic.lua: -------------------------------------------------------------------------------- 1 | require "call" 2 | require "role" 3 | 4 | -- connect id 5 | gconnid = 0 6 | Logic = { 7 | roles = {} 8 | } 9 | 10 | function Logic:onConnect(conn) 11 | gconnid = gconnid + 1 12 | 13 | local role = Role:new() 14 | role.session = conn 15 | conn:setUsernum(gconnid) 16 | self.roles[gconnid] = role 17 | 18 | return role 19 | end 20 | 21 | function Logic:onClose(conn) 22 | local connid = conn:getUsernum() 23 | local role = self.roles[connid] 24 | role.session = nil 25 | self.roles[connid] = nil 26 | end 27 | 28 | function Logic:onMsg(conn, callid, pack) 29 | local connid = conn:getUsernum() 30 | local role = self.roles[connid] 31 | 32 | -- call 33 | local func = getcallfu(callid) 34 | func(role, pack) 35 | end 36 | 37 | -- role id 38 | groleid = 1000; 39 | function role_enter(role) 40 | groleid = groleid + 1 41 | role.roleid = groleid 42 | 43 | -- server exec 44 | print("role[".. groleid .. "] enter server") 45 | 46 | local pack = NetPacket:new() 47 | pack:pushString("sync role[".. groleid .. "] data") 48 | role:call(sync_role, pack) 49 | end 50 | 51 | function sync_role(role, pack) 52 | -- client exec 53 | print(pack:getString()) 54 | 55 | local ret = NetPacket:new() 56 | ret:pushString("hello server") 57 | role:call(msg_one, ret) 58 | end 59 | 60 | function msg_one(role, pack) 61 | -- server exec 62 | print(pack:getString()) 63 | 64 | local ret = NetPacket:new() 65 | ret:pushString("hello client") 66 | role:call(msg_two, ret) 67 | end 68 | 69 | function msg_two(role, pack) 70 | -- client exec 71 | print(pack:getString()) 72 | 73 | local ret = NetPacket:new() 74 | ret:pushString("bye bye!") 75 | role:call(msg_bye, ret) 76 | end 77 | 78 | function msg_bye(role, pack) 79 | -- server exec 80 | print(pack:getString()) 81 | end 82 | 83 | register(sync_role) 84 | register(msg_one) 85 | register(msg_two) 86 | register(msg_bye) -------------------------------------------------------------------------------- /example/rpc/role.lua: -------------------------------------------------------------------------------- 1 | require "call" 2 | 3 | Role = {} 4 | Role.__index = Role 5 | 6 | function Role:new() 7 | local o = {} 8 | setmetatable(o, Role) 9 | o.session = nil 10 | o.roleid = 0 11 | return o 12 | end 13 | 14 | function Role:call(func, pack) 15 | local callid = getcallid(func) 16 | self.session:sendPacket(callid, pack) 17 | end 18 | -------------------------------------------------------------------------------- /example/rpc/server.bat: -------------------------------------------------------------------------------- 1 | start ../../bin/engine.exe server.lua 2 | -------------------------------------------------------------------------------- /example/rpc/server.lua: -------------------------------------------------------------------------------- 1 | require "logic" 2 | 3 | -- init 4 | event_init() 5 | 6 | -- create server 7 | server = NetServer:new() 8 | server.on_accept = function(conn) 9 | role_enter(Logic:onConnect(conn)) 10 | end 11 | 12 | server.on_close = function(conn) 13 | Logic:onClose(conn) 14 | end 15 | 16 | server.on_msg = function(conn, msgtype, pack) 17 | Logic:onMsg(conn, msgtype, pack) 18 | end 19 | 20 | server:listen("127.0.0.1", 3001, false) 21 | 22 | event_run() -------------------------------------------------------------------------------- /libs/libmysqlclient.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/libs/libmysqlclient.a -------------------------------------------------------------------------------- /libs/libmysqlclient.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/libs/libmysqlclient.lib -------------------------------------------------------------------------------- /libs/libmysqlclient.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/libs/libmysqlclient.so -------------------------------------------------------------------------------- /premake/makeclean.bat: -------------------------------------------------------------------------------- 1 | premake5.exe --file=premake.lua clean -------------------------------------------------------------------------------- /premake/makeclean2.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | for /R %%s in (*.vcproj,*.vcproj.*,*.vcxproj,*.vcxproj.*,*.idb,*.pdb,*.sdf,*.suo,*.ncb,*.sln) do ( 3 | echo %%s 4 | del /F /Q %%s 5 | ) 6 | pause 7 | -------------------------------------------------------------------------------- /premake/premake.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | premake5.exe --file=premake.lua vs2017 -------------------------------------------------------------------------------- /premake/premake.sh: -------------------------------------------------------------------------------- 1 | # 1. premake5 生成makefile 2 | # 2. make 编译 3 | ./premake5 --file=premake.lua --cc=gcc gmake 4 | ../make config=release_x64 -------------------------------------------------------------------------------- /premake/premake5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/premake/premake5 -------------------------------------------------------------------------------- /premake/premake5.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/premake/premake5.exe -------------------------------------------------------------------------------- /src/common/BaseType.h: -------------------------------------------------------------------------------- 1 | #ifndef BASETYPE_H 2 | #define BASETYPE_H 3 | 4 | #include "stdint.h" 5 | 6 | typedef int8_t int8; 7 | typedef uint8_t uint8; 8 | 9 | typedef int16_t int16; 10 | typedef uint16_t uint16; 11 | 12 | typedef int32_t int32; 13 | typedef uint32_t uint32; 14 | 15 | typedef int64_t int64; 16 | typedef uint64_t uint64; 17 | 18 | 19 | 20 | #endif 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/common/CommonPool.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/common/CommonPool.h -------------------------------------------------------------------------------- /src/common/CsvParser.cpp: -------------------------------------------------------------------------------- 1 | #include "CsvParser.h" 2 | #include 3 | #include "XLog.h" 4 | 5 | 6 | CsvParser::CsvParser(const char * file, int startline, char sep) : 7 | _sep(sep) 8 | { 9 | std::string line; 10 | 11 | std::ifstream ifile(file); 12 | if (ifile.is_open()) 13 | { 14 | int row = 0; 15 | while (ifile.good()) 16 | { 17 | getline(ifile, line); 18 | if (line == "") 19 | continue; 20 | 21 | if (startline && --startline) 22 | continue; 23 | 24 | row++; 25 | if (row == 1) 26 | { 27 | parseHeader(line); 28 | } 29 | else 30 | { 31 | parseContent(line); 32 | } 33 | } 34 | ifile.close(); 35 | } 36 | else 37 | { 38 | ERROR_LOG("Failed to open %s", file); 39 | } 40 | } 41 | 42 | 43 | CsvParser::~CsvParser() 44 | { 45 | } 46 | 47 | void CsvParser::parseHeader(std::string & line) 48 | { 49 | std::stringstream ss(line); 50 | std::string item; 51 | 52 | while (std::getline(ss, item, _sep)) 53 | _header.push_back(item); 54 | } 55 | 56 | void CsvParser::parseContent(std::string & line) 57 | { 58 | std::stringstream ss(line); 59 | std::string item; 60 | 61 | CsvRow csvrow; 62 | while (std::getline(ss, item, _sep)) 63 | csvrow.push(item); 64 | 65 | _content.push_back(csvrow); 66 | } 67 | 68 | int CsvParser::row() 69 | { 70 | return _content.size(); 71 | } -------------------------------------------------------------------------------- /src/common/CsvParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | # include 4 | #include 5 | 6 | class CsvRow 7 | { 8 | public: 9 | unsigned int size(void) const{ return _values.size(); } 10 | void push(const std::string & title){ _values.push_back(title); } 11 | 12 | template 13 | const T getValue(int idx, T defvalue = T()) const 14 | { 15 | T res = defvalue; 16 | std::stringstream ss; 17 | ss << _values[idx]; 18 | ss >> res; 19 | return res; 20 | } 21 | private: 22 | std::vector _values; 23 | }; 24 | 25 | class CsvParser 26 | { 27 | public: 28 | CsvParser(const char * file, int startline = 1, char sep = '\t'); 29 | ~CsvParser(); 30 | 31 | template 32 | const T getValue(int row, std::string name, T defvalue = T()) const 33 | { 34 | for (unsigned int i = 0; i < _header.size();++i) 35 | { 36 | if (name == _header[i]) 37 | { 38 | const CsvRow & csvrow = _content[row - 1]; 39 | T ret = csvrow.getValue(i, defvalue); 40 | return ret; 41 | } 42 | } 43 | 44 | return T(); 45 | } 46 | 47 | int row(); 48 | 49 | protected: 50 | void parseHeader(std::string & line); 51 | void parseContent(std::string & line); 52 | private: 53 | const char _sep; 54 | std::vector _header; 55 | std::vector _content; 56 | }; 57 | 58 | -------------------------------------------------------------------------------- /src/common/Define.h: -------------------------------------------------------------------------------- 1 | #ifndef _DEFINE_H_ 2 | #define _DEFINE_H_ 3 | 4 | #include "Platform.h" 5 | 6 | #ifdef SYSTEM_WIN 7 | #include 8 | #endif 9 | 10 | #define TRINITY_BIGENDIAN 1 11 | 12 | 13 | 14 | #endif -------------------------------------------------------------------------------- /src/common/EventLoop.cpp: -------------------------------------------------------------------------------- 1 | #include "EventLoop.h" 2 | 3 | void EventLoop::init() 4 | { 5 | mLoop = uv_default_loop(); 6 | } 7 | 8 | int EventLoop::run() 9 | { 10 | return uv_run(mLoop, UV_RUN_DEFAULT); 11 | } 12 | 13 | void EventLoop::stop() 14 | { 15 | uv_stop(mLoop); 16 | } 17 | 18 | void EventLoop::exit() 19 | { 20 | uv_loop_delete(mLoop); 21 | mLoop = NULL; 22 | } 23 | 24 | uv_loop_t * EventLoop::getLoop() 25 | { 26 | return mLoop; 27 | } -------------------------------------------------------------------------------- /src/common/EventLoop.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENT_LOOP_H 2 | #define EVENT_LOOP_H 3 | 4 | #include "libuv/include/uv.h" 5 | #include "Singleton.h" 6 | 7 | class EventLoop : public Singleton 8 | { 9 | public: 10 | void init(); 11 | 12 | int run(); 13 | void stop(); 14 | void exit(); 15 | uv_loop_t* getLoop(); 16 | 17 | private: 18 | uv_loop_t* mLoop; 19 | }; 20 | 21 | 22 | #endif -------------------------------------------------------------------------------- /src/common/HttpParam.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "HttpParam.h" 6 | 7 | HttpParam::HttpParam(std::string_view str_v, char cut) 8 | { 9 | std::vector equal; 10 | splite(str_v, equal, cut); 11 | 12 | for (auto it = equal.begin();it!= equal.end(); ++it) 13 | { 14 | std::string_view & sub = (*it); 15 | 16 | std::vector kys; 17 | splite(sub, kys, '='); 18 | 19 | if (kys.size() == 2) 20 | { 21 | params[kys[0]] = kys[1]; 22 | } 23 | } 24 | } 25 | 26 | 27 | void HttpParam::splite(std::string_view str_view, std::vector & vec_str, char cut) 28 | { 29 | std::string::size_type pos1 = 0, pos2; 30 | while ((pos2 = str_view.find(cut, pos1)) != std::string_view::npos) 31 | { 32 | vec_str.push_back(str_view.substr(pos1, pos2 - pos1)); 33 | pos1 = pos2 + 1; 34 | } 35 | vec_str.push_back(str_view.substr(pos1)); 36 | } 37 | 38 | bool HttpParam::find(std::string_view key) 39 | { 40 | return params.find(key) != params.end(); 41 | } 42 | 43 | std::string_view HttpParam::getStr(std::string_view key) 44 | { 45 | return params[key]; 46 | } 47 | 48 | int HttpParam::getInt(std::string_view key) 49 | { 50 | std::string si(params[key]); 51 | return std::stoi(si); 52 | } 53 | 54 | float HttpParam::getFloat(std::string_view key) 55 | { 56 | std::string sf(params[key]); 57 | return std::stof(sf); 58 | } -------------------------------------------------------------------------------- /src/common/HttpParam.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /************************************************************************ 3 | * @file HttpParam.h 4 | * @brief Parse HTTP parameters 5 | * @author jiangwang 6 | * @data 2020-5-21 7 | * @version 0.1 8 | ************************************************************************/ 9 | 10 | class HttpParam 11 | { 12 | public: 13 | HttpParam(std::string_view str_v, char cut = '&'); 14 | 15 | static void splite(std::string_view str_view, std::vector & vec_str, char cut = '&'); 16 | 17 | bool find(std::string_view key); 18 | std::string_view getStr(std::string_view key); 19 | int getInt(std::string_view key); 20 | float getFloat(std::string_view key); 21 | 22 | private: 23 | std::map params; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /src/common/Objectpool.h: -------------------------------------------------------------------------------- 1 | #ifndef _OBJECT_POOL_H 2 | #define _OBJECT_POOL_H 3 | 4 | #include 5 | #include 6 | #include "XAssert.h" 7 | 8 | template< typename T> 9 | class ObjectPool 10 | { 11 | typedef std::list OBJECTS; 12 | 13 | public: 14 | ObjectPool(int32 maxfreecount = 0x200) : 15 | max_free(maxfreecount), obj_count_(0) 16 | { 17 | 18 | } 19 | 20 | ~ObjectPool(){ 21 | destroy(); 22 | } 23 | 24 | void init(int32 count) 25 | { 26 | max_free = count; 27 | } 28 | 29 | void destroy() 30 | { 31 | typename OBJECTS::iterator iter = objects_.begin(); 32 | for (; iter != objects_.end(); ++iter) 33 | { 34 | (*iter)->setEnabledPoolObject(false); 35 | delete (*iter); 36 | } 37 | 38 | objects_.clear(); 39 | obj_count_ = 0; 40 | } 41 | 42 | T* createObject() 43 | { 44 | if (obj_count_ > 0) 45 | { 46 | T* t = *objects_.begin(); 47 | objects_.pop_front(); 48 | --obj_count_; 49 | t->setEnabledPoolObject(true); 50 | return t; 51 | } 52 | 53 | T* t = newObj(); 54 | t->setEnabledPoolObject(true); 55 | return t; 56 | } 57 | 58 | virtual T * newObj() 59 | { 60 | return new T; 61 | } 62 | 63 | void reclaimObject(T* obj) 64 | { 65 | if (obj == NULL) 66 | { 67 | return; 68 | } 69 | if (!obj->isEnabledPoolObject()) 70 | { 71 | XAssert(0, "The object is already in the pool"); 72 | return; 73 | } 74 | 75 | obj->setEnabledPoolObject(false); 76 | if (obj_count_ >= max_free) 77 | { 78 | delete obj; 79 | } 80 | else 81 | { 82 | objects_.push_back(obj); 83 | ++obj_count_; 84 | } 85 | } 86 | 87 | int32 getObjCount(){ return obj_count_; } 88 | OBJECTS & getObjs() { return objects_; } 89 | private: 90 | int32 max_free; 91 | int32 obj_count_; 92 | OBJECTS objects_; 93 | }; 94 | 95 | 96 | #endif -------------------------------------------------------------------------------- /src/common/Platform.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/common/Platform.h -------------------------------------------------------------------------------- /src/common/PoolObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //include body 4 | #define INCLUDE_POOL_OBJECT\ 5 | public:\ 6 | bool isEnabledPoolObject() const{ return isEnabledPoolObject_; }\ 7 | void setEnabledPoolObject(bool v){ isEnabledPoolObject_ = v; }\ 8 | private:\ 9 | bool isEnabledPoolObject_ = true; 10 | 11 | class PoolObject 12 | { 13 | INCLUDE_POOL_OBJECT 14 | }; -------------------------------------------------------------------------------- /src/common/Singleton.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SRC_UTILS_SINGLETON_H_ 3 | #define SRC_UTILS_SINGLETON_H_ 4 | 5 | template 6 | class Singleton 7 | { 8 | public: 9 | static T* Instance() { 10 | static T _instance; 11 | return &_instance; 12 | } 13 | 14 | protected: 15 | // Disable compiler generated code to prevent default constuction/destruction 16 | // and copy/assignment semantics. 17 | Singleton(){} 18 | ~Singleton(){} 19 | Singleton(Singleton const&){} 20 | Singleton& operator=(Singleton const&){} 21 | }; 22 | 23 | 24 | #endif // SRC_UTILS_SINGLETON_H_ 25 | -------------------------------------------------------------------------------- /src/common/SpinLock.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class SpinLock 6 | { 7 | public: 8 | explicit SpinLock() 9 | { 10 | flag.clear(); 11 | } 12 | 13 | ~SpinLock() 14 | { 15 | } 16 | 17 | void lock() 18 | { 19 | while (flag.test_and_set(std::memory_order_acquire)) 20 | ; 21 | } 22 | 23 | bool try_lock() 24 | { 25 | if (flag.test_and_set(std::memory_order_acquire)) 26 | { 27 | return false; 28 | } 29 | 30 | return true; 31 | } 32 | 33 | void unlock() 34 | { 35 | flag.clear(std::memory_order_release); 36 | } 37 | 38 | protected: 39 | mutable std::atomic_flag flag;// = ATOMIC_FLAG_INIT; 40 | 41 | private: 42 | SpinLock& operator=(const SpinLock& src); 43 | }; -------------------------------------------------------------------------------- /src/common/TQueue.h: -------------------------------------------------------------------------------- 1 | #ifndef X_QUEUE_H 2 | #define X_QUEUE_H 3 | 4 | #include "concurrentqueue/concurrentqueue.h" 5 | 6 | /* 7 | 8 | using namespace moodycamel; 9 | 10 | ReaderWriterQueue q(100); // Reserve space for at least 100 elements up front 11 | 12 | q.enqueue(17); // Will allocate memory if the queue is full 13 | bool succeeded = q.try_enqueue(18); // Will only succeed if the queue has an empty slot (never allocates) 14 | assert(succeeded); 15 | 16 | int number; 17 | succeeded = q.try_dequeue(number); // Returns false if the queue was empty 18 | 19 | assert(succeeded && number == 17); 20 | 21 | // You can also peek at the front item of the queue (consumer only) 22 | int* front = q.peek(); 23 | assert(*front == 18); 24 | succeeded = q.try_dequeue(number); 25 | assert(succeeded && number == 18); 26 | front = q.peek(); 27 | assert(front == nullptr); // Returns nullptr if the queue was empty 28 | 29 | */ 30 | 31 | template 32 | class TQueue 33 | { 34 | public: 35 | TQueue(int maxSize = 15) : 36 | mqueue(maxSize) 37 | { 38 | 39 | } 40 | void push(const T& object) 41 | { 42 | mqueue.enqueue(object); 43 | } 44 | 45 | bool tryPop(T& object) 46 | { 47 | return mqueue.try_dequeue(object); 48 | } 49 | 50 | private: 51 | moodycamel::ConcurrentQueue mqueue; 52 | }; 53 | 54 | #endif -------------------------------------------------------------------------------- /src/common/ThreadPool.cpp: -------------------------------------------------------------------------------- 1 | #include "ThreadPool.h" 2 | #include 3 | 4 | using namespace Thread; 5 | 6 | Task::~Task() 7 | { 8 | 9 | } 10 | 11 | CThread::CThread(ThreadPool * pool) : 12 | _pool(pool), 13 | _thread(CThread::backfunc, this) 14 | { 15 | //_thread.detach(); 16 | } 17 | 18 | CThread::~CThread() 19 | { 20 | 21 | } 22 | 23 | void CThread::backfunc(CThread * t) 24 | { 25 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); 26 | t->onStart(); 27 | while (t->_isrun) 28 | { 29 | TaskPtr task = t->_pool->popWaitTask(); 30 | if (task) 31 | { 32 | t->run(task); 33 | t->_pool->_completeTasks.push(task); 34 | } 35 | else 36 | { 37 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 38 | } 39 | } 40 | t->onEnd(); 41 | } 42 | 43 | void CThread::stop() 44 | { 45 | _isrun = false; 46 | _thread.join(); 47 | } 48 | 49 | void CThread::run(TaskPtr task) 50 | { 51 | task->process(); 52 | }; 53 | 54 | ThreadPool::ThreadPool() 55 | { 56 | 57 | } 58 | 59 | 60 | ThreadPool::~ThreadPool() 61 | { 62 | exit(); 63 | } 64 | 65 | void ThreadPool::create(int count) 66 | { 67 | for (int i = 0; i < count; ++i) 68 | { 69 | CThread * t = createThread(); 70 | if (t) 71 | { 72 | _threads.push_back(t); 73 | } 74 | } 75 | } 76 | void ThreadPool::exit() 77 | { 78 | for (CThread * t : _threads) 79 | { 80 | t->stop(); 81 | deleteThread(t); 82 | } 83 | 84 | _threads.clear(); 85 | } 86 | 87 | void ThreadPool::addTask(TaskPtr task) 88 | { 89 | _waitTasks.push(task); 90 | } 91 | 92 | TaskPtr ThreadPool::popWaitTask() 93 | { 94 | TaskPtr task; 95 | if (!_waitTasks.tryPop(task)) 96 | return NULL; 97 | return task; 98 | } 99 | 100 | void ThreadPool::update() 101 | { 102 | TaskPtr task; 103 | if (!_completeTasks.tryPop(task)) 104 | return; 105 | 106 | task->complete(); 107 | completeTask(task); 108 | } -------------------------------------------------------------------------------- /src/common/ThreadPool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "TQueue.h" 5 | 6 | namespace Thread 7 | { 8 | class Task 9 | { 10 | public: 11 | virtual ~Task(); 12 | virtual void process() = 0; 13 | virtual void complete() = 0; 14 | }; 15 | 16 | typedef std::shared_ptr TaskPtr; 17 | 18 | class ThreadPool; 19 | class CThread 20 | { 21 | public: 22 | CThread(ThreadPool * pool); 23 | virtual ~CThread(); 24 | static void backfunc(CThread * t); 25 | void stop(); 26 | 27 | virtual void run(TaskPtr task); 28 | 29 | protected: 30 | virtual void onStart() {}; 31 | virtual void onEnd() {}; 32 | 33 | protected: 34 | ThreadPool * _pool; 35 | std::thread _thread; 36 | std::atomic _isrun{ true }; 37 | }; 38 | 39 | class ThreadPool 40 | { 41 | friend CThread; 42 | public: 43 | ThreadPool(); 44 | virtual ~ThreadPool(); 45 | 46 | void create(int count); 47 | void exit(); 48 | 49 | void addTask(TaskPtr task); 50 | void update(); 51 | protected: 52 | virtual CThread* createThread() = 0; 53 | virtual void deleteThread(CThread * t) = 0; 54 | virtual void completeTask(TaskPtr task) = 0; 55 | private: 56 | TaskPtr popWaitTask(); 57 | 58 | private: 59 | std::vector _threads; 60 | TQueue _waitTasks; 61 | TQueue _completeTasks; 62 | }; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/common/Timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Heap.h" 4 | #include "BaseType.h" 5 | #include 6 | 7 | class Timer 8 | { 9 | struct TimerNode 10 | { 11 | struct Heap::heap_node m_node; 12 | void * user = NULL; 13 | }; 14 | 15 | //typedef void(*close_timer_cb)(TimerNode* timernode); 16 | 17 | public: 18 | Timer(); 19 | ~Timer(); 20 | 21 | static void init(); 22 | static void update(); 23 | 24 | void start(std::function cb, uint64_t timeout, uint64_t repeat = 0); 25 | void stop(); 26 | 27 | private: 28 | static int compare_fn(const struct Heap::heap_node* a, const struct Heap::heap_node* b); 29 | 30 | private: 31 | TimerNode * m_node = NULL; 32 | uint32 m_time = 0; 33 | uint32 m_repeat = 0; 34 | std::function m_cb; 35 | 36 | static struct Heap::heap gRootHeap; 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /src/common/Tools.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | class Tools 5 | { 6 | public: 7 | static void encrypt(char * buf, char * key); 8 | static std::string format(const char * format, ...); 9 | static void sleep(int ms); 10 | static unsigned long getCurrentThreadID(); 11 | static int binarySearch(int arr[], int len, int findX); 12 | static std::string gbkToUtf8(const char *src_str); 13 | static std::string utf8ToGbk(const char *src_str); 14 | static int charCount(char * pStr, char c); 15 | static void srand(unsigned int); 16 | static int random(int begin, int end); 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /src/common/UTimer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/common/UTimer.h -------------------------------------------------------------------------------- /src/common/XAssert.cpp: -------------------------------------------------------------------------------- 1 | #include "XAssert.h" 2 | #include 3 | #include 4 | #include 5 | 6 | void IAssert(char const* file, int line, char const* function, char const* message, char const* format, ...) 7 | { 8 | va_list args; 9 | va_start(args, format); 10 | 11 | fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s ", file, line, function, message); 12 | vfprintf(stderr, format, args); 13 | fprintf(stderr, "\n"); 14 | fflush(stderr); 15 | 16 | va_end(args); 17 | *((volatile int*)NULL) = 0; 18 | exit(1); 19 | } -------------------------------------------------------------------------------- /src/common/XAssert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void IAssert(char const* file, int line, char const* function, char const* message, char const* format, ...); 4 | 5 | #define XAssert(cond, ...) do { if (!(cond)) IAssert(__FILE__, __LINE__, __FUNCTION__, #cond, ##__VA_ARGS__); } while(0) -------------------------------------------------------------------------------- /src/common/XFile.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/common/XFile.cpp -------------------------------------------------------------------------------- /src/common/XFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class XFile 7 | { 8 | public: 9 | XFile(); 10 | ~XFile(); 11 | 12 | static bool isExist(const char * dir); 13 | static int mkdir(const char * dir); 14 | // Delete empty directory 15 | static int rmdir(const char * dir); 16 | static int createDirectory(const char * dir); 17 | static int writeFile(const char * file, const char * content); 18 | static int readFile(const char * file, std::string & str); 19 | // Read by line 20 | static int readFile(const char *file, std::vector & vec_str); 21 | static int remove(const char * file); 22 | // Walk through all the files in the directory 23 | static int listFiles(const char * dir, std::vector & vec_file); 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /src/common/XLog.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/common/XLog.cpp -------------------------------------------------------------------------------- /src/common/XLog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "SpinLock.h" 6 | 7 | #define LOG_MAX_SIZE 1073741824 8 | 9 | enum LogLevel 10 | { 11 | LL_INFO, 12 | LL_WARNING, 13 | LL_ERROR, 14 | }; 15 | 16 | class XLog 17 | { 18 | class AutoLock; 19 | public: 20 | XLog(); 21 | ~XLog(); 22 | 23 | void init(const char * rootdir, const char * childdir); 24 | void setMaxsize(unsigned int size){ maxsize = size; } 25 | void writeLog(int level, const char * filename, const char * func, int line, const char * format, ...); 26 | private: 27 | void writeFile(int level, const char * filename, const char * func, int line, const char * logstr); 28 | void closefile(); 29 | void print(int level, std::string& str); 30 | private: 31 | FILE * file; 32 | std::string logdir; 33 | std::string childdir; 34 | std::string currdir; 35 | int writeday; 36 | unsigned int maxsize; 37 | unsigned int currsize; 38 | SpinLock _lock; 39 | }; 40 | 41 | class LogStream 42 | { 43 | public: 44 | LogStream(XLog * log, int level, const char * filename, const char * func, int line); 45 | ~LogStream(); 46 | 47 | template 48 | LogStream & operator << (T value) 49 | { 50 | stream << value; 51 | return *this; 52 | } 53 | private: 54 | std::stringstream stream; 55 | XLog * _log; 56 | int _level; 57 | std::string _filename; 58 | std::string _func; 59 | int _line; 60 | }; 61 | 62 | extern XLog commonlog; 63 | 64 | #define INIT_LOG(rootdir, childdir) commonlog.init(rootdir, childdir) 65 | 66 | #define INFO_LOG(...) commonlog.writeLog(LL_INFO , __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 67 | #define WARNING_LOG(...) commonlog.writeLog(LL_WARNING, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 68 | #define ERROR_LOG(...) commonlog.writeLog(LL_ERROR, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) 69 | #define XLOG(level) LogStream(&commonlog, level, __FILE__, __FUNCTION__, __LINE__) 70 | #define XLOG_IF(condition, level) if(condition)\ 71 | LogStream(&commonlog, level, __FILE__, __FUNCTION__, __LINE__) 72 | 73 | -------------------------------------------------------------------------------- /src/common/XTime.h: -------------------------------------------------------------------------------- 1 |  2 | #ifndef XTIME_H 3 | #define XTIME_H 4 | 5 | #include 6 | #include 7 | #include "Platform.h" 8 | #include "BaseType.h" 9 | 10 | #ifdef SYSTEM_WIN 11 | #include 12 | #else 13 | #include 14 | #endif // PLATFORM_WINDOWS 15 | 16 | 17 | class XTime 18 | { 19 | public: 20 | // leap year 21 | static bool isLeapYear(int year); 22 | static int yearMonthDays(int year, int month); 23 | 24 | static const struct tm * getTMStruct(); 25 | static time_t getTime(struct tm * tm_); 26 | static std::string format(const char * fmt = "%Y-%m-%d %H:%M:%S"); 27 | 28 | static void getTimeval(struct timeval * tp); 29 | // msec 30 | static int64 milliStamp(); 31 | // usec 32 | static int64 microStamp(); 33 | // sec 34 | static time_t stamp(); 35 | 36 | static uint32 iclock(); 37 | }; 38 | 39 | #endif -------------------------------------------------------------------------------- /src/common/base64.h: -------------------------------------------------------------------------------- 1 | #ifndef _BASE64_H_ 2 | #define _BASE64_H_ 3 | #include 4 | 5 | std::string base64_encode(unsigned char const* , unsigned int len); 6 | std::string base64_decode(std::string const& s); 7 | #endif 8 | -------------------------------------------------------------------------------- /src/common/sha1.h: -------------------------------------------------------------------------------- 1 | #ifndef _SHA1_H_ 2 | #define _SHA1_H_ 3 | 4 | class SHA1 5 | { 6 | 7 | public: 8 | 9 | SHA1(); 10 | virtual ~SHA1(); 11 | 12 | /* 13 | * Re-initialize the class 14 | */ 15 | void Reset(); 16 | 17 | /* 18 | * Returns the message digest 19 | */ 20 | bool Result(unsigned *message_digest_array); 21 | 22 | /* 23 | * Provide input to SHA1 24 | */ 25 | void Input(const unsigned char *message_array, 26 | unsigned length); 27 | void Input(const char *message_array, 28 | unsigned length); 29 | void Input(unsigned char message_element); 30 | void Input(char message_element); 31 | SHA1& operator<<(const char *message_array); 32 | SHA1& operator<<(const unsigned char *message_array); 33 | SHA1& operator<<(const char message_element); 34 | SHA1& operator<<(const unsigned char message_element); 35 | 36 | private: 37 | 38 | /* 39 | * Process the next 512 bits of the message 40 | */ 41 | void ProcessMessageBlock(); 42 | 43 | /* 44 | * Pads the current message block to 512 bits 45 | */ 46 | void PadMessage(); 47 | 48 | /* 49 | * Performs a circular left shift operation 50 | */ 51 | inline unsigned CircularShift(int bits, unsigned word); 52 | 53 | unsigned H[5]; // Message digest buffers 54 | 55 | unsigned Length_Low; // Message length in bits 56 | unsigned Length_High; // Message length in bits 57 | 58 | unsigned char Message_Block[64]; // 512-bit message blocks 59 | int Message_Block_Index; // Index into message block array 60 | 61 | bool Computed; // Is the digest computed? 62 | bool Corrupted; // Is the message digest corruped? 63 | 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/db/DBResult.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class DBResult 3 | { 4 | public: 5 | DBResult() {}; 6 | virtual ~DBResult() {}; 7 | virtual bool isEmpty() = 0; 8 | virtual bool fetch() = 0; 9 | virtual uint32 getRowCount() = 0; 10 | virtual uint32 getFieldsCount() = 0; 11 | 12 | virtual const char * getData(int & len) = 0; 13 | virtual const char * getData() = 0; 14 | 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /src/db/DB_Interface.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "DB_Interface.h" 3 | 4 | DB_Interface::DB_Interface(const char * ip, unsigned int port): 5 | m_ip(ip), 6 | m_port(port) 7 | { 8 | 9 | } 10 | 11 | DB_Interface::~DB_Interface() 12 | { 13 | 14 | } -------------------------------------------------------------------------------- /src/db/DB_Interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /************************************************************************ 4 | * @file DB_Interface.h 5 | * @brief db interface 6 | * @author jiangwang 7 | * @data 2020-3-31 8 | * @version 0.1 9 | ************************************************************************/ 10 | 11 | class DBResult; 12 | class DB_Interface 13 | { 14 | public: 15 | DB_Interface(const char * ip, unsigned int port); 16 | virtual ~DB_Interface(); 17 | 18 | public: 19 | virtual bool connect() = 0; 20 | virtual bool detach() = 0; 21 | virtual int execute(DBResult * result, const char * cmd, int len = 0) = 0; 22 | virtual const char * getError() = 0; 23 | virtual int getErrno() = 0; 24 | virtual bool ping() = 0; 25 | protected: 26 | std::string m_ip; 27 | unsigned int m_port; 28 | }; -------------------------------------------------------------------------------- /src/db/DB_Interface_mysql.h: -------------------------------------------------------------------------------- 1 | #ifndef DB_INTERFACE_MYSQL_H 2 | #define DB_INTERFACE_MYSQL_H 3 | 4 | #include "DB_Interface.h" 5 | 6 | class MysqlResult; 7 | class SqlPrepare; 8 | class DBInterfaceMysql : public DB_Interface 9 | { 10 | public: 11 | DBInterfaceMysql(const char * host, const char * dbname, const char * user, const char * pswd = "", unsigned int port = 3306); 12 | ~DBInterfaceMysql(); 13 | 14 | virtual bool connect(); 15 | virtual bool detach(); 16 | virtual int execute(DBResult * result, const char * cmd, int len = 0); 17 | 18 | virtual const char * getError(); 19 | virtual int getErrno(); 20 | virtual bool ping(); 21 | 22 | MYSQL * mysql(); 23 | 24 | protected: 25 | MYSQL mMysql_; 26 | 27 | std::string m_dbname; 28 | std::string m_user; 29 | std::string m_pswd; 30 | }; 31 | 32 | namespace MySQL 33 | { 34 | int threadSafe(); 35 | void libraryInit(); 36 | void libraryEnd(); 37 | char const* getLibraryVersion(); 38 | }; 39 | 40 | #endif -------------------------------------------------------------------------------- /src/db/DB_Interface_redis.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /************************************************************************ 3 | * @file DB_Interface_redis.h 4 | * @brief db interface redis 5 | * @author jiangwang 6 | * @data 2020-3-31 7 | * @version 0.1 8 | ************************************************************************/ 9 | 10 | #include "DB_Interface.h" 11 | class RedisCommand; 12 | class DBInterfaceRedis : public DB_Interface 13 | { 14 | public: 15 | DBInterfaceRedis(const char * ip, unsigned int port); 16 | ~DBInterfaceRedis(); 17 | 18 | virtual bool connect(); 19 | virtual bool detach(); 20 | virtual int execute(DBResult * result, const char * cmd, int len = 0); 21 | virtual const char * getError(); 22 | virtual int getErrno(); 23 | virtual bool ping(); 24 | 25 | int execute(RedisCommand * command, DBResult * result); 26 | 27 | protected: 28 | redisContext * m_context; 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /src/db/MysqlResult.cpp: -------------------------------------------------------------------------------- 1 | #include "MysqlResult.h" 2 | 3 | MysqlResult::MysqlResult() 4 | { 5 | pResult = NULL; 6 | pos = 0; 7 | lengths = NULL; 8 | } 9 | 10 | MysqlResult::~MysqlResult() 11 | { 12 | if (pResult) 13 | { 14 | mysql_free_result(pResult); 15 | } 16 | } 17 | 18 | void MysqlResult::setResult(MYSQL_RES * result) { 19 | pResult = result; 20 | if (result) 21 | lengths = mysql_fetch_lengths(pResult); 22 | else 23 | lengths = NULL; 24 | } 25 | 26 | bool MysqlResult::isEmpty() 27 | { 28 | return pResult == NULL; 29 | } 30 | 31 | bool MysqlResult::fetch() { 32 | pos = 0; 33 | return (aRow = mysql_fetch_row(pResult)) != NULL; 34 | } 35 | 36 | uint32 MysqlResult::getRowCount() { 37 | return (uint32)mysql_num_rows(pResult); 38 | } 39 | 40 | uint32 MysqlResult::getFieldsCount() { 41 | return (uint32)mysql_num_fields(pResult); 42 | } 43 | 44 | const char * MysqlResult::getData(int & len) { 45 | len = lengths[pos]; 46 | return aRow[pos++]; 47 | } 48 | 49 | const char * MysqlResult::getData() { 50 | return aRow[pos++]; 51 | } -------------------------------------------------------------------------------- /src/db/MysqlResult.h: -------------------------------------------------------------------------------- 1 | #ifndef DB_RESULT_H 2 | #define DB_RESULT_H 3 | 4 | #include "mysql.h" 5 | #include "XLog.h" 6 | #include "BaseType.h" 7 | #include 8 | #include "DBResult.h" 9 | 10 | class MysqlResult : public DBResult 11 | { 12 | public: 13 | MysqlResult(); 14 | ~MysqlResult(); 15 | 16 | void setResult(MYSQL_RES * result); 17 | 18 | virtual bool isEmpty(); 19 | virtual bool fetch(); 20 | virtual uint32 getRowCount(); 21 | virtual uint32 getFieldsCount(); 22 | 23 | virtual const char * getData(int & len); 24 | virtual const char * getData(); 25 | 26 | template 27 | MysqlResult & operator >> (T & t) 28 | { 29 | if (pos >= getFieldsCount()) 30 | { 31 | ERROR_LOG("mysql row count upper limit"); 32 | return *this; 33 | } 34 | std::istringstream ins(aRow[pos]); 35 | ins >> t; 36 | pos++; 37 | return *this; 38 | } 39 | 40 | private: 41 | 42 | MYSQL_RES * pResult; 43 | MYSQL_ROW aRow; 44 | uint32 pos; 45 | unsigned long *lengths; 46 | }; 47 | 48 | #endif -------------------------------------------------------------------------------- /src/db/RedisCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /************************************************************************ 3 | * @file RedisCommand.h 4 | * @brief redis command param 5 | * @author jiangwang 6 | * @data 2020-4-2 7 | * @version 0.1 8 | ************************************************************************/ 9 | 10 | class BasePacket; 11 | class RedisCommand 12 | { 13 | public: 14 | RedisCommand(const char *cmd); 15 | // push 16 | void pushInt8(int8 value); 17 | void pushUint8(uint8 value); 18 | void pushInt16(int16 value); 19 | void pushUint16(uint16 value); 20 | void pushInt32(int32 value); 21 | void pushUint32(uint32 value); 22 | void pushInt64(int64 value); 23 | void pushUint64(uint64 value); 24 | void pushFloat(float value); 25 | void pushDouble(double value); 26 | void pushString(std::string value); 27 | void pushBlob(BasePacket * packet); 28 | void pushData(std::string_view sv); // lua call 29 | 30 | template 31 | void pushValue(T t) 32 | { 33 | append((const uint8 *)&t, sizeof(t)); 34 | } 35 | 36 | int length(); 37 | const char ** argv(std::vector & vec); 38 | const size_t * argvlen(); 39 | const char * tostr(); 40 | 41 | private: 42 | void append(const uint8 * p, int len); 43 | 44 | private: 45 | std::vector> m_param; 46 | std::vector m_len; 47 | }; 48 | 49 | -------------------------------------------------------------------------------- /src/db/RedisResult.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /************************************************************************ 3 | * @file RedisResult.h 4 | * @brief redis result 5 | * @author jiangwang 6 | * @data 2020-3-31 7 | * @version 0.1 8 | ************************************************************************/ 9 | 10 | #include "XLog.h" 11 | #include "BaseType.h" 12 | #include "DBResult.h" 13 | #include 14 | 15 | class BasePacket; 16 | struct redisReply; 17 | class RedisResult : public DBResult 18 | { 19 | public: 20 | RedisResult(); 21 | ~RedisResult(); 22 | void setResult(redisReply * result); 23 | 24 | virtual bool isEmpty(); 25 | virtual bool fetch(); 26 | virtual uint32 getRowCount(); 27 | virtual uint32 getFieldsCount(); 28 | 29 | virtual const char * getData(int & len); 30 | virtual const char * getData(); 31 | 32 | // base type 33 | template 34 | RedisResult & operator >> (T & t) 35 | { 36 | if (pos >= getFieldsCount()) 37 | { 38 | ERROR_LOG("redis row count upper limit"); 39 | return *this; 40 | } 41 | 42 | // blob 43 | const char * p = m_reply->str ? m_reply->str : m_reply->element[pos]->str; 44 | std::memcpy(&t, p, sizeof(t)); 45 | 46 | pos++; 47 | return *this; 48 | } 49 | 50 | // string type 51 | RedisResult &operator>>(std::string& value); 52 | int readBlob(BasePacket * packet); 53 | std::string_view getStream(); 54 | private: 55 | redisReply * m_reply; 56 | uint32 pos; 57 | }; 58 | 59 | -------------------------------------------------------------------------------- /src/db/SqlPrepare.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /************************************************************************ 3 | * @file SqlPrepare.h 4 | * @brief sql prepare 5 | * @author jiangwang 6 | * @data 2020-3-23 7 | * @version 0.1 8 | ************************************************************************/ 9 | 10 | class BasePacket; 11 | class DBResult; 12 | class SqlPrepare 13 | { 14 | public: 15 | SqlPrepare(const char * sqlstr); 16 | ~SqlPrepare(); 17 | 18 | void clear(); 19 | 20 | // push 21 | void pushInt8(int8 value); 22 | void pushUint8(uint8 value); 23 | void pushInt16(int16 value); 24 | void pushUint16(uint16 value); 25 | void pushInt32(int32 value); 26 | void pushUint32(uint32 value); 27 | void pushInt64(int64 value); 28 | void pushUint64(uint64 value); 29 | void pushFloat(float value); 30 | void pushDouble(double value); 31 | void pushString(std::string value); 32 | void pushBlob(BasePacket * packet); 33 | void pushData(std::string_view sv); // lua call 34 | 35 | void write(void* pData, int len); 36 | 37 | int prepare(MYSQL * mysql); 38 | int execute(DBResult* result = NULL); 39 | protected: 40 | bool _query(MYSQL_RES** pRes); 41 | private: 42 | int m_count; 43 | std::string m_sql; 44 | MYSQL_STMT * m_stmt; 45 | MYSQL_BIND * m_paramBind; 46 | unsigned long * m_paramLengths; 47 | 48 | private: 49 | int m_widx; // write 50 | }; -------------------------------------------------------------------------------- /src/db/SqlResultSet.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/db/SqlResultSet.cpp -------------------------------------------------------------------------------- /src/db/SqlResultSet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class SqlField 7 | { 8 | public: 9 | SqlField() 10 | { 11 | m_buff = NULL; 12 | m_len = 0; 13 | } 14 | 15 | ~SqlField() 16 | { 17 | if (m_buff) 18 | { 19 | delete[] m_buff; 20 | } 21 | } 22 | 23 | void make(const char* pdata, int len) 24 | { 25 | m_len = len; 26 | m_buff = new char[len]; 27 | memcpy(m_buff, pdata, len); 28 | } 29 | 30 | bool isEmpty() 31 | { 32 | return !m_buff; 33 | } 34 | 35 | const char* data() { return m_buff; } 36 | int length() { return m_len; } 37 | 38 | template 39 | T getValue() 40 | { 41 | T val; 42 | memcpy(&val, m_buff, sizeof(T)); 43 | return val; 44 | } 45 | 46 | private: 47 | char* m_buff; 48 | int m_len; 49 | }; 50 | 51 | #include 52 | #include "BaseType.h" 53 | #include "DBResult.h" 54 | 55 | class BasePacket; 56 | class SqlResultSet : public DBResult 57 | { 58 | public: 59 | SqlResultSet(); 60 | ~SqlResultSet(); 61 | 62 | void setResult(MYSQL_STMT* stmt, MYSQL_RES* pResult, uint64 pRowCount, uint32 pFieldCount); 63 | virtual bool fetch(); 64 | virtual bool isEmpty(); 65 | virtual uint32 getRowCount(); 66 | virtual uint32 getFieldsCount(); 67 | virtual const char* getData(int& len); 68 | virtual const char* getData(); 69 | 70 | SqlField* getField(int idx); 71 | bool emptyField(int idx); 72 | 73 | int8 getInt8(); 74 | uint8 getUint8(); 75 | int16 getInt16(); 76 | uint16 getUint16(); 77 | int32 getInt32(); 78 | uint32 getUint32(); 79 | int64 getInt64(); 80 | uint64 getUint64(); 81 | float getFloat(); 82 | double getDouble(); 83 | std::string getString(); 84 | int readBlob(BasePacket* packet); 85 | std::string_view getStrview(); // lua call 86 | 87 | protected: 88 | bool _fetch(MYSQL_STMT * stmt); 89 | private: 90 | std::vector m_fields; 91 | int64 m_currRowIdx; 92 | int32 m_currColIdx; 93 | int64 m_rowCount; 94 | int32 m_fieldCount; 95 | }; 96 | 97 | -------------------------------------------------------------------------------- /src/network/HttpConnect.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/HttpConnect.h -------------------------------------------------------------------------------- /src/network/HttpEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /************************************************************************ 3 | * @file HttpEvent.h 4 | * @brief HttpEvent 5 | * @author jiangwang 6 | * @data 2020-5-20 7 | * @version 0.1 8 | ************************************************************************/ 9 | 10 | class HttpConnect; 11 | class HttpParser; 12 | class HttpEvent 13 | { 14 | public: 15 | virtual void onClose(HttpConnect *conn) = 0; 16 | 17 | virtual void onGet(HttpConnect* conn, std::string_view& path, std::string_view& data) = 0; 18 | virtual void onPost(HttpConnect* conn, std::string_view& path, std::string_view& data) = 0; 19 | virtual void onOther(HttpConnect* conn, HttpParser * parser) = 0; 20 | }; 21 | -------------------------------------------------------------------------------- /src/network/HttpServer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "HttpServer.h" 5 | #include "HttpConnect.h" 6 | #include "CommonPool.h" 7 | 8 | HttpServer::HttpServer(EventLoop * loop): 9 | TcpServer(loop) 10 | { 11 | 12 | } 13 | 14 | TcpSocket * HttpServer::createSocket() 15 | { 16 | HttpConnect * conn = CommPool::create(); 17 | conn->setEvent(this); 18 | return conn; 19 | } 20 | 21 | void HttpServer::onSocket(TcpSocket * connect) 22 | { 23 | 24 | } 25 | 26 | void HttpServer::onClose(HttpConnect *conn) 27 | { 28 | CommPool::reclaim(conn); 29 | } 30 | 31 | void HttpServer::onGet(HttpConnect* conn, std::string_view& path, std::string_view& data) 32 | { 33 | std::string spath(path); 34 | auto it = m_get.find(spath); 35 | if (it != m_get.end()) 36 | { 37 | (it->second)(conn, data); 38 | } 39 | } 40 | 41 | void HttpServer::onPost(HttpConnect* conn, std::string_view& path, std::string_view& data) 42 | { 43 | std::string spath(path); 44 | auto it = m_post.find(spath); 45 | if (it != m_post.end()) 46 | { 47 | (it->second)(conn, data); 48 | } 49 | } 50 | void HttpServer::onOther(HttpConnect* conn, HttpParser* parser) 51 | { 52 | if (m_other) m_other(conn, parser); 53 | } 54 | 55 | void HttpServer::addGet(const char * name, std::function back) 56 | { 57 | m_get[name] = back; 58 | } 59 | void HttpServer::addPost(const char * name, std::function back) 60 | { 61 | m_post[name] = back; 62 | } 63 | 64 | void HttpServer::setOther(std::function back) 65 | { 66 | m_other = back; 67 | } -------------------------------------------------------------------------------- /src/network/HttpServer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TcpServer.h" 3 | #include "HttpEvent.h" 4 | 5 | class EventLoop; 6 | class HttpServer : public TcpServer, public HttpEvent 7 | { 8 | public: 9 | HttpServer(EventLoop * loop); 10 | void addGet(const char * name, std::function back); 11 | void addPost(const char * name, std::function back); 12 | void setOther(std::function back); 13 | protected: 14 | virtual TcpSocket * createSocket(); 15 | virtual void onSocket(TcpSocket * connect); 16 | virtual void onClose(HttpConnect *conn); 17 | virtual void onGet(HttpConnect* conn, std::string_view& path, std::string_view& data); 18 | virtual void onPost(HttpConnect* conn, std::string_view& path, std::string_view& data); 19 | virtual void onOther(HttpConnect* conn, HttpParser* parser); 20 | 21 | private: 22 | std::map> m_get; 23 | std::map> m_post; 24 | std::function m_other; 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /src/network/KcpClient.cpp: -------------------------------------------------------------------------------- 1 | #include "KcpClient.h" 2 | #include "KcpEvent.h" 3 | #include "KcpSession.h" 4 | 5 | 6 | KcpClient::KcpClient(EventLoop * loop, KcpEvent * event_): 7 | UdpClient(loop), 8 | __m_kcpEvent(event_) 9 | { 10 | } 11 | 12 | 13 | KcpClient::~KcpClient() 14 | { 15 | } 16 | 17 | 18 | void KcpClient::createSession(const char * server_ip, int server_port, bool ipv6) 19 | { 20 | connect(server_ip, server_port, ipv6); 21 | 22 | uint8 msg[SESSION_PACKET_SIZE]; 23 | *(uint32 *)msg = 0; 24 | *(uint8 *)(msg + 4) = SETUP_SESSION_CODE; 25 | writeToServer((char *)msg, SESSION_PACKET_SIZE); 26 | } 27 | 28 | void KcpClient::closeSession(KcpSession * session) 29 | { 30 | std::map::iterator it = __m_mapSessions.find(session->getSessionId()); 31 | if (it != __m_mapSessions.end()) 32 | { 33 | __m_mapSessions.erase(session->getSessionId()); 34 | release(session); 35 | } 36 | } 37 | 38 | void KcpClient::onMessage(const sockaddr * addr, const char * buff, ssize_t len) 39 | { 40 | uint32 conv = ikcp_getconv((const void *)buff); 41 | unsigned char code = *(unsigned char*)(buff + 4); 42 | if (len == SESSION_PACKET_SIZE && conv > 0 && code == SETUP_SESSION_CODE) 43 | { 44 | KcpSession * session = __m_kcpEvent->createConnect(); 45 | uint32 ms = __m_kcpEvent->onKcp(session->init(conv, addr, &_udp)); 46 | session->start(ms); 47 | __m_mapSessions[conv] = session; 48 | __m_kcpEvent->onConnect(session); 49 | 50 | } 51 | else 52 | { 53 | std::map::iterator it = __m_mapSessions.find(conv); 54 | if (it != __m_mapSessions.end()) 55 | { 56 | KcpSession * session = it->second; 57 | if (session->recv(buff, len) == 0) { 58 | session->updateKcp(); 59 | }else{ 60 | release(session); 61 | __m_mapSessions.erase(it); 62 | } 63 | } 64 | } 65 | 66 | } 67 | 68 | void KcpClient::release(KcpSession * session) 69 | { 70 | session->destory(); 71 | session->over(); 72 | __m_kcpEvent->onClose(session); 73 | __m_kcpEvent->destroyConnect(session); 74 | } -------------------------------------------------------------------------------- /src/network/KcpClient.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * @file KcpClient.h 3 | * @brief kcp client 4 | * @author jiangwang 5 | * @data 2019-12-13 6 | * @version 0.1 7 | ************************************************************************/ 8 | 9 | #pragma once 10 | 11 | #include "UdpClient.h" 12 | #include "BaseType.h" 13 | #include 14 | 15 | class KcpEvent; 16 | class EventLoop; 17 | class KcpSession; 18 | class KcpClient : public UdpClient 19 | { 20 | public: 21 | KcpClient(EventLoop * loop, KcpEvent * event_); 22 | ~KcpClient(); 23 | 24 | void createSession(const char * server_ip, int server_port, bool ipv6 = false); 25 | void closeSession(KcpSession * session); 26 | 27 | protected: 28 | virtual void onMessage(const sockaddr * addr, const char * buff, ssize_t len); 29 | 30 | private: 31 | void release(KcpSession * session); 32 | private: 33 | KcpEvent * __m_kcpEvent; 34 | std::map __m_mapSessions; 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /src/network/KcpEvent.cpp: -------------------------------------------------------------------------------- 1 | #include "KcpEvent.h" 2 | #include 3 | #include "KcpSession.h" 4 | 5 | KcpEvent::KcpEvent() 6 | { 7 | } 8 | 9 | 10 | KcpEvent::~KcpEvent() 11 | { 12 | } 13 | 14 | KcpSession * KcpEvent::createConnect() 15 | { 16 | return new KcpSession(this, 30 * 1000); 17 | } 18 | 19 | void KcpEvent::destroyConnect(KcpSession * conn) 20 | { 21 | if (conn) 22 | delete conn; 23 | } 24 | 25 | int KcpEvent::onKcp(void* kcp) 26 | { 27 | ikcpcb* _kcp = static_cast(kcp); 28 | // int ikcp_wndsize(ikcpcb *kcp, int sndwnd, int rcvwnd); 29 | ikcp_nodelay(_kcp, 1, 10, 2, 1); 30 | // return update millisecond 31 | return 10; 32 | } -------------------------------------------------------------------------------- /src/network/KcpEvent.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/KcpEvent.h -------------------------------------------------------------------------------- /src/network/KcpServer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * @file KcpServer.h 3 | * @brief kcp server 4 | * @author jiangwang 5 | * @data 2019-12-12 6 | * @version 0.1 7 | ************************************************************************/ 8 | 9 | #pragma once 10 | 11 | #include "UdpServer.h" 12 | #include 13 | #include "BaseType.h" 14 | 15 | class KcpEvent; 16 | class EventLoop; 17 | class KcpSession; 18 | class KcpServer : public UdpServer 19 | { 20 | public: 21 | KcpServer(EventLoop * loop, KcpEvent * event_); 22 | ~KcpServer(); 23 | 24 | void closeSession(KcpSession * session); 25 | void shutdown(); 26 | 27 | protected: 28 | virtual void onMessage(const sockaddr * addr, const char * buff, ssize_t len); 29 | 30 | private: 31 | void release(KcpSession * session); 32 | private: 33 | KcpEvent * __m_kcpEvent; 34 | std::map __m_mapSessions; 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /src/network/KcpSession.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/KcpSession.cpp -------------------------------------------------------------------------------- /src/network/KcpSession.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/KcpSession.h -------------------------------------------------------------------------------- /src/network/NetClient.cpp: -------------------------------------------------------------------------------- 1 | #include "NetClient.h" 2 | #include "NetConnect.h" 3 | #include "NetEvent.h" 4 | 5 | 6 | NetClient::NetClient(EventLoop * loop, NetEvent * nevent) : 7 | TcpClient(loop), 8 | _netevent(nevent) 9 | { 10 | 11 | } 12 | 13 | NetClient::~NetClient(){ 14 | 15 | } 16 | 17 | 18 | TcpSocket * NetClient::createSocket() 19 | { 20 | NetConnect * conn = _netevent->createConnect(); 21 | return (TcpSocket *)conn; 22 | } 23 | 24 | void NetClient::onSocket(TcpSocket * conn, int argv) 25 | { 26 | _netevent->onConnect((NetConnect *)conn, argv); 27 | } -------------------------------------------------------------------------------- /src/network/NetClient.h: -------------------------------------------------------------------------------- 1 | #ifndef TCP_CLIENT_H 2 | #define TCP_CLIENT_H 3 | 4 | 5 | #include "TcpClient.h" 6 | 7 | class NetEvent; 8 | class NetClient : public TcpClient 9 | { 10 | 11 | public: 12 | NetClient(EventLoop * loop, NetEvent * nevent); 13 | 14 | ~NetClient(); 15 | 16 | protected: 17 | virtual TcpSocket * createSocket(); 18 | virtual void onSocket(TcpSocket * conn, int argv); 19 | 20 | private: 21 | NetEvent * _netevent; 22 | }; 23 | 24 | #endif -------------------------------------------------------------------------------- /src/network/NetConnect.h: -------------------------------------------------------------------------------- 1 | #ifndef NET_CONNECT_H 2 | #define NET_CONNECT_H 3 | 4 | #include "TcpSocket.h" 5 | 6 | class NetPacket; 7 | class NetEvent; 8 | class NetConnect : public TcpSocket 9 | { 10 | public: 11 | NetConnect(NetEvent * nevent, uint32 buffersize = MESSAGE_BUFFER_SIZE); 12 | 13 | ~NetConnect(); 14 | 15 | // write data to socket 16 | void sendMsg(uint32 msgtype, NetPacket * pack); 17 | void sendMsg(uint32 msgtype, const char * msg, uint32 len); 18 | // lua call 19 | void sendPacket(uint32 msgtype, NetPacket * pack) { sendMsg(msgtype, pack);} 20 | void sendData(uint32 msgtype, std::string_view view) { sendMsg(msgtype, view.data(), view.size()); } 21 | 22 | protected: 23 | NetPacket* createPacket(); 24 | //virtual void recyclePacket(BasePacket* pack); 25 | 26 | virtual void on_msgbuffer(MessageBuffer * buffer); 27 | virtual void on_clsesocket(); 28 | private: 29 | NetPacket * mReadPacket; 30 | NetEvent * _netevent; 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /src/network/NetEvent.cpp: -------------------------------------------------------------------------------- 1 | #include "NetEvent.h" 2 | #include "NetConnect.h" 3 | 4 | NetEvent::NetEvent() 5 | { 6 | 7 | } 8 | 9 | NetEvent::~NetEvent() 10 | { 11 | 12 | } 13 | 14 | NetConnect * NetEvent::createConnect() 15 | { 16 | return new NetConnect(this, MESSAGE_BUFFER_SIZE); 17 | } 18 | 19 | void NetEvent::destroyConnect(NetConnect * conn) 20 | { 21 | if (conn) 22 | { 23 | delete conn; 24 | } 25 | } -------------------------------------------------------------------------------- /src/network/NetEvent.h: -------------------------------------------------------------------------------- 1 | #ifndef NET_EVENT_H 2 | #define NET_EVENT_H 3 | 4 | class NetConnect; 5 | class NetPacket; 6 | 7 | class NetEvent 8 | { 9 | public: 10 | NetEvent(); 11 | virtual ~NetEvent(); 12 | 13 | virtual NetConnect * createConnect(); 14 | virtual void destroyConnect(NetConnect * conn); 15 | 16 | virtual void onAccept(NetConnect * conn){}; 17 | virtual void onConnect(NetConnect * conn, int argv){}; 18 | virtual void onClose(NetConnect * conn){}; 19 | virtual void onMsg(NetConnect * conn, int msgtype, NetPacket * pack){}; 20 | 21 | }; 22 | 23 | #endif -------------------------------------------------------------------------------- /src/network/NetPacket.cpp: -------------------------------------------------------------------------------- 1 | #include "NetPacket.h" 2 | 3 | NetPacket::NetPacket() 4 | { 5 | zero(); 6 | } 7 | 8 | void NetPacket::zero() 9 | { 10 | this->_storage->resize(MSG_HEAD_SIZE); 11 | _wpos = MSG_HEAD_SIZE; 12 | _rpos = MSG_HEAD_SIZE; 13 | } 14 | 15 | int32 NetPacket::getHeadSize() 16 | { 17 | return MSG_HEAD_SIZE; 18 | } 19 | int32 NetPacket::getMarkLen() 20 | { 21 | // message head mark length 22 | return getValue(MSG_LEN_POS); 23 | } 24 | 25 | int NetPacket::getMsgType() 26 | { 27 | return getValue(MSG_TYPE_POS); 28 | } 29 | 30 | bool NetPacket::isHeadFull() 31 | { 32 | return wpos() >= MSG_HEAD_SIZE; 33 | } 34 | 35 | // send msg call 36 | int32 NetPacket::sendSize() 37 | { 38 | return wpos(); 39 | } 40 | char * NetPacket::sendStream() 41 | { 42 | return (char *)contents(); 43 | } 44 | 45 | void NetPacket::writeHead(int msgtype) 46 | { 47 | setValue(MSG_LEN_POS, getBodySize()); 48 | setValue(MSG_TYPE_POS, msgtype); 49 | } 50 | 51 | uint32 NetPacket::readHead(const uint8 * p, uint32 size) 52 | { 53 | int rsize = MSG_HEAD_SIZE - wpos(); 54 | if (rsize <= 0) 55 | { 56 | return 0; 57 | } 58 | 59 | rsize = size >= rsize ? rsize : size; 60 | 61 | put(wpos(), p, rsize); 62 | _wpos += rsize; 63 | 64 | return rsize; 65 | } -------------------------------------------------------------------------------- /src/network/NetPacket.h: -------------------------------------------------------------------------------- 1 | #ifndef MSG_PACKET_H 2 | #define MSG_PACKET_H 3 | 4 | #include "BasePacket.h" 5 | 6 | #define MSG_LEN_POS 0 7 | #define MSG_TYPE_POS sizeof(uint32) 8 | #define MSG_HEAD_SIZE (sizeof(uint32) + sizeof(uint32)) 9 | 10 | // packet head( msglen:uint32, msgtype:uint32 ) 11 | class NetPacket : public BasePacket 12 | { 13 | 14 | public: 15 | NetPacket(); 16 | 17 | virtual void zero(); 18 | virtual int32 getHeadSize(); 19 | 20 | // read msg call 21 | virtual int32 getMarkLen(); // message head mark length 22 | virtual int getMsgType(); 23 | virtual bool isHeadFull(); 24 | 25 | // send msg call 26 | virtual int32 sendSize(); 27 | virtual char * sendStream(); 28 | 29 | void writeHead(int msgtype); 30 | uint32 readHead(const uint8 * p, uint32 size); 31 | }; 32 | 33 | #endif -------------------------------------------------------------------------------- /src/network/NetServer.cpp: -------------------------------------------------------------------------------- 1 | #include "NetServer.h" 2 | #include "NetConnect.h" 3 | #include "NetEvent.h" 4 | 5 | NetServer::NetServer(EventLoop * loop, NetEvent * nevent) : 6 | TcpServer(loop), 7 | _netevent(nevent) 8 | { 9 | } 10 | 11 | TcpSocket * NetServer::createSocket() 12 | { 13 | NetConnect * conn = _netevent->createConnect(); 14 | return (TcpSocket *)conn; 15 | } 16 | 17 | void NetServer::onSocket(TcpSocket * connect) 18 | { 19 | _netevent->onAccept((NetConnect *)connect); 20 | } -------------------------------------------------------------------------------- /src/network/NetServer.h: -------------------------------------------------------------------------------- 1 | #ifndef NET_SERVER_H 2 | #define NET_SERVER_H 3 | 4 | #include "TcpServer.h" 5 | 6 | class NetConnect; 7 | class NetEvent; 8 | class NetServer : public TcpServer 9 | { 10 | public: 11 | NetServer(EventLoop * loop, NetEvent * nevent); 12 | 13 | protected: 14 | 15 | virtual TcpSocket * createSocket(); 16 | virtual void onSocket(TcpSocket * connect); 17 | 18 | private: 19 | NetEvent * _netevent; 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /src/network/ProtoPacket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | void readProto(T* buff, MSG & msg) 5 | { 6 | const char * data = buff->getBodyData(); 7 | msg.ParseFromArray((const void*)data, buff->getBodySize()); 8 | } 9 | 10 | template 11 | void writeProto(T* buff, MSG & msg) 12 | { 13 | int size = msg.ByteSizeLong(); 14 | buff->setWriteSize(size); 15 | const char* data = buff->getBodyData(); 16 | msg.SerializeToArray((void *)data, size); 17 | } -------------------------------------------------------------------------------- /src/network/TcpClient.cpp: -------------------------------------------------------------------------------- 1 | #include "TcpClient.h" 2 | #include "XLog.h" 3 | #include "EventLoop.h" 4 | 5 | TcpClient::TcpClient(EventLoop * loop) : 6 | mLoop(loop->getLoop()) 7 | { 8 | 9 | } 10 | 11 | 12 | TcpClient::~TcpClient() 13 | { 14 | } 15 | 16 | int TcpClient::connect(const char * ip, int port, bool ipv6, int argv) 17 | { 18 | struct user_connect : public uv_connect_t 19 | { 20 | TcpSocket * conn; 21 | int argv; 22 | }; 23 | 24 | user_connect * user_conn = new user_connect; 25 | user_conn->conn = createSocket(); 26 | user_conn->data = this; 27 | user_conn->argv = argv; 28 | 29 | uv_tcp_init(mLoop, user_conn->conn->getUvTcp()); 30 | 31 | sockaddr_storage iaddr; 32 | if (ipv6) { 33 | uv_ip6_addr(ip, port, (sockaddr_in6*)&iaddr); 34 | } 35 | else { 36 | uv_ip4_addr(ip, port, (sockaddr_in*)&iaddr); 37 | } 38 | 39 | return uv_tcp_connect(user_conn, user_conn->conn->getUvTcp(), (sockaddr*)&iaddr, 40 | [](uv_connect_t* req, int status) { 41 | user_connect *user_conn = (user_connect*)req; 42 | TcpClient * self = (TcpClient *)user_conn->data; 43 | 44 | if (status < 0) { 45 | uv_close((uv_handle_t*)(user_conn->conn->getUvTcp()), NULL); 46 | self->onSocket(NULL, user_conn->argv); 47 | } 48 | else { 49 | user_conn->conn->on_read_start(); 50 | self->onSocket(user_conn->conn, user_conn->argv); 51 | } 52 | 53 | delete user_conn; 54 | }); 55 | } -------------------------------------------------------------------------------- /src/network/TcpClient.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "TcpSocket.h" 4 | 5 | class EventLoop; 6 | class TcpClient 7 | { 8 | public: 9 | TcpClient(EventLoop * loop); 10 | virtual ~TcpClient(); 11 | 12 | virtual int connect(const char * ip, int port, bool ipv6 = false, int argv = 0); 13 | 14 | protected: 15 | virtual TcpSocket * createSocket() = 0; 16 | virtual void onSocket(TcpSocket * conn, int argv) = 0; 17 | protected: 18 | uv_loop_t * mLoop; 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /src/network/TcpServer.cpp: -------------------------------------------------------------------------------- 1 | #include "XLog.h" 2 | #include "TcpServer.h" 3 | #include "EventLoop.h" 4 | 5 | TcpServer::TcpServer(EventLoop * loop) : 6 | mLoop(loop->getLoop()) 7 | { 8 | m_uv_tcp.data = this; 9 | uv_tcp_init(mLoop, &m_uv_tcp); 10 | } 11 | 12 | TcpServer::~TcpServer() 13 | { 14 | 15 | } 16 | 17 | int TcpServer::listen(const char * ip, int port, bool ipv6) 18 | { 19 | 20 | /* 21 | #ifdef USE_IPV6_ADDR 22 | struct sockaddr_in6 mAddr; 23 | uv_ip6_addr(ip, port, &mAddr); 24 | #else 25 | struct sockaddr_in mAddr; 26 | uv_ip4_addr(ip, port, &mAddr); 27 | #endif 28 | */ 29 | sockaddr_storage iaddr; 30 | if (ipv6) { 31 | uv_ip6_addr(ip, port, (sockaddr_in6*)&iaddr); 32 | } 33 | else { 34 | uv_ip4_addr(ip, port, (sockaddr_in*)&iaddr); 35 | } 36 | 37 | uv_tcp_bind(&m_uv_tcp, (const struct sockaddr*)&iaddr, 0); 38 | return uv_listen((uv_stream_t*)&m_uv_tcp, DEFAULT_BACKLOG, on_new_connection); 39 | } 40 | 41 | void TcpServer::shutdown() 42 | { 43 | uv_close((uv_handle_s *)&m_uv_tcp, [](uv_handle_t* handle){ 44 | 45 | }); 46 | } 47 | 48 | void TcpServer::on_new_connection(uv_stream_t *server, int status) 49 | { 50 | if (status < 0) { 51 | ERROR_LOG("New connection error %s\n", uv_strerror(status)); 52 | return; 53 | } 54 | 55 | TcpServer * self = (TcpServer *)server->data; 56 | // new connect 57 | TcpSocket * connect = self->createSocket(); 58 | connect->clear(); 59 | connect->init_uv_tcp(self->mLoop); 60 | if (connect->accept(server) == 0) { 61 | 62 | connect->on_read_start(); 63 | self->onSocket(connect); 64 | } 65 | else { 66 | uv_close((uv_handle_t*)connect->getUvTcp(), NULL); 67 | ERROR_LOG("New connection close %s\n", uv_strerror(status)); 68 | delete connect; 69 | } 70 | } -------------------------------------------------------------------------------- /src/network/TcpServer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/TcpServer.h -------------------------------------------------------------------------------- /src/network/UdpClient.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * @file UdpClient.h 3 | * @brief udp client 4 | * @author jiangwang 5 | * @data 2019-12-12 6 | * @version 0.1 7 | ************************************************************************/ 8 | 9 | #pragma once 10 | #include "libuv/include/uv.h" 11 | 12 | class EventLoop; 13 | class UdpClient 14 | { 15 | public: 16 | UdpClient(EventLoop * loop); 17 | virtual ~UdpClient(); 18 | 19 | //int connect(const char * server_ip, int server_port, int port, bool ipv6 = false); 20 | int connect(const char * server_ip, int server_port, bool ipv6 = false); 21 | int writeToServer(char * buff, int len); 22 | 23 | protected: 24 | virtual void onMessage(const sockaddr * addr, const char * buff, ssize_t len) = 0; 25 | 26 | private: 27 | static void alloc_buffer(uv_handle_t * handle, size_t suggested_size, uv_buf_t * buf); 28 | static void on_read(uv_udp_t * handle, ssize_t nread, const uv_buf_t * rcvbuf, const sockaddr * addr, unsigned flags); 29 | 30 | protected: 31 | uv_udp_t _udp; 32 | sockaddr_storage _server_addr; 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /src/network/UdpPacket.cpp: -------------------------------------------------------------------------------- 1 | #include "UdpPacket.h" 2 | 3 | 4 | UdpPacket::UdpPacket() 5 | { 6 | zero(); 7 | } 8 | 9 | 10 | UdpPacket::~UdpPacket() 11 | { 12 | } 13 | 14 | void UdpPacket::zero() 15 | { 16 | this->_storage->resize(UDP_PACK_HEAD_SIZE); 17 | _wpos = UDP_PACK_HEAD_SIZE; 18 | _rpos = UDP_PACK_HEAD_SIZE; 19 | } 20 | 21 | int32 UdpPacket::getHeadSize() 22 | { 23 | return UDP_PACK_HEAD_SIZE; 24 | } 25 | 26 | void UdpPacket::initSize(int s) 27 | { 28 | if (s > size()) 29 | { 30 | this->_storage->resize(s); 31 | } 32 | } 33 | 34 | int UdpPacket::getMsgType() 35 | { 36 | return getValue(0); 37 | } 38 | 39 | void UdpPacket::writeHead(int msgtype) 40 | { 41 | put(0, msgtype); 42 | } 43 | 44 | void UdpPacket::writeComplete(uint32 size) 45 | { 46 | _wpos += size; 47 | } 48 | 49 | int32 UdpPacket::getMarkLen() 50 | { 51 | // udp There is no need to mark the length 52 | return 0; 53 | } 54 | 55 | // send msg call 56 | int32 UdpPacket::sendSize() 57 | { 58 | return wpos(); 59 | } 60 | 61 | char * UdpPacket::sendStream() 62 | { 63 | return (char *)contents(); 64 | } -------------------------------------------------------------------------------- /src/network/UdpPacket.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * @file UdpPacket.h 3 | * @brief udp message packet 4 | * @author jiangwang 5 | * @data 2019-12-12 6 | * @version 0.1 7 | ************************************************************************/ 8 | 9 | #pragma once 10 | 11 | #include "BasePacket.h" 12 | 13 | #define UDP_PACK_HEAD_SIZE sizeof(uint32) 14 | 15 | class UdpPacket : public BasePacket 16 | { 17 | public: 18 | UdpPacket(); 19 | ~UdpPacket(); 20 | 21 | virtual void zero(); 22 | virtual int32 getHeadSize(); 23 | void initSize(int size); 24 | 25 | // read msg call 26 | virtual int32 getMarkLen(); // message head mark length 27 | virtual int getMsgType(); 28 | 29 | // send msg call 30 | virtual int32 sendSize(); 31 | virtual char * sendStream(); 32 | 33 | void writeHead(int msgtype); 34 | void writeComplete(uint32 size); 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /src/network/UdpServer.cpp: -------------------------------------------------------------------------------- 1 | #include "UdpServer.h" 2 | #include "EventLoop.h" 3 | #include "XLog.h" 4 | 5 | UdpServer::UdpServer(EventLoop * loop) 6 | { 7 | _m_udp.data = this; 8 | uv_udp_init(loop->getLoop(), &_m_udp); 9 | } 10 | 11 | 12 | UdpServer::~UdpServer() 13 | { 14 | } 15 | 16 | int UdpServer::start(const char * ip, int port, bool ipv6) 17 | { 18 | 19 | sockaddr_storage iaddr; 20 | if (ipv6) { 21 | uv_ip6_addr(ip, port, (sockaddr_in6*)&iaddr); 22 | } 23 | else { 24 | uv_ip4_addr(ip, port, (sockaddr_in*)&iaddr); 25 | } 26 | 27 | int errcode = uv_udp_bind(&_m_udp, (const struct sockaddr *)&iaddr, UV_UDP_REUSEADDR); 28 | if (errcode) 29 | { 30 | ERROR_LOG("uv_udp_bind error %s\n", uv_strerror(errcode)); 31 | return -1; 32 | } 33 | 34 | errcode = uv_udp_recv_start(&_m_udp, alloc_buffer, on_read); 35 | if (errcode) 36 | { 37 | ERROR_LOG("uv_udp_recv_start error %s\n", uv_strerror(errcode)); 38 | return -1; 39 | } 40 | 41 | return 0; 42 | } 43 | 44 | void UdpServer::alloc_buffer(uv_handle_t * handle, size_t suggested_size, uv_buf_t * buf) 45 | { 46 | static const int bufflen = 65536; 47 | static char buff[bufflen]; 48 | 49 | buf->base = buff; 50 | buf->len = bufflen; 51 | 52 | } 53 | 54 | void UdpServer::on_read(uv_udp_t * handle, ssize_t nread, const uv_buf_t * rcvbuf, const sockaddr * addr, unsigned flags) 55 | { 56 | UdpServer * server = (UdpServer *)handle->data; 57 | server->onMessage(addr, rcvbuf->base, nread); 58 | } -------------------------------------------------------------------------------- /src/network/UdpServer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * @file UdpServer.h 3 | * @brief udp server 4 | * @author jiangwang 5 | * @data 2019-12-12 6 | * @version 0.1 7 | ************************************************************************/ 8 | 9 | #pragma once 10 | #include "libuv/include/uv.h" 11 | 12 | class EventLoop; 13 | class UdpServer 14 | { 15 | public: 16 | UdpServer(EventLoop * loop); 17 | virtual ~UdpServer(); 18 | 19 | int start(const char * ip, int port, bool ipv6 = false); 20 | 21 | protected: 22 | virtual void onMessage(const sockaddr * addr, const char * buff, ssize_t len) = 0; 23 | 24 | private: 25 | static void alloc_buffer(uv_handle_t * handle, size_t suggested_size, uv_buf_t * buf); 26 | static void on_read(uv_udp_t * handle, ssize_t nread, const uv_buf_t * rcvbuf, const sockaddr * addr, unsigned flags); 27 | 28 | protected: 29 | uv_udp_t _m_udp; 30 | }; 31 | 32 | -------------------------------------------------------------------------------- /src/network/WebSocketConnect.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/WebSocketConnect.h -------------------------------------------------------------------------------- /src/network/WebSocketEvent.cpp: -------------------------------------------------------------------------------- 1 | #include "WebSocketEvent.h" 2 | #include "WebSocketConnect.h" 3 | 4 | 5 | WebSocketEvent::WebSocketEvent() 6 | { 7 | } 8 | 9 | 10 | WebSocketEvent::~WebSocketEvent() 11 | { 12 | } 13 | 14 | 15 | WebSocketConnect * WebSocketEvent::createConnect() 16 | { 17 | return new WebSocketConnect(this); 18 | } 19 | 20 | void WebSocketEvent::destroyConnect(WebSocketConnect * conn) 21 | { 22 | if (conn) 23 | delete conn; 24 | } -------------------------------------------------------------------------------- /src/network/WebSocketEvent.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/WebSocketEvent.h -------------------------------------------------------------------------------- /src/network/WebSocketPacket.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/WebSocketPacket.cpp -------------------------------------------------------------------------------- /src/network/WebSocketPacket.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/WebSocketPacket.h -------------------------------------------------------------------------------- /src/network/WebSocketServer.cpp: -------------------------------------------------------------------------------- 1 | #include "WebSocketServer.h" 2 | #include "WebSocketEvent.h" 3 | 4 | 5 | WebSocketServer::WebSocketServer(EventLoop * loop, WebSocketEvent * wevent): 6 | TcpServer(loop), 7 | __m_event(wevent) 8 | { 9 | } 10 | 11 | 12 | WebSocketServer::~WebSocketServer() 13 | { 14 | } 15 | 16 | 17 | TcpSocket * WebSocketServer::createSocket() 18 | { 19 | return (TcpSocket *)__m_event->createConnect(); 20 | } 21 | 22 | void WebSocketServer::onSocket(TcpSocket * connect) 23 | { 24 | __m_event->onAccept((WebSocketConnect *)connect); 25 | } -------------------------------------------------------------------------------- /src/network/WebSocketServer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/network/WebSocketServer.h -------------------------------------------------------------------------------- /src/script/Lua_Base.cpp: -------------------------------------------------------------------------------- 1 | #include "sol/sol.hpp" 2 | #include "TcpSocket.h" 3 | #include "BasePacket.h" 4 | #include "ByteBuffer.h" 5 | #include "CommonPool.h" 6 | 7 | void init_buffer_pool(int count) 8 | { 9 | CommPool::init(count); 10 | } 11 | 12 | void luabind_basepacket(sol::state & lua) 13 | { 14 | lua["init_buffer_pool"] = &init_buffer_pool; 15 | 16 | lua.new_usertype("BasePacket", 17 | "getInt8", &BasePacket::getInt8, 18 | "getUint8", &BasePacket::getUint8, 19 | "getInt16", &BasePacket::getInt16, 20 | "getUint16", &BasePacket::getUint16, 21 | "getInt32", &BasePacket::getInt32, 22 | "getUint32", &BasePacket::getUint32, 23 | "getInt64", &BasePacket::getInt64, 24 | "getUint64", &BasePacket::getUint64, 25 | "getFloat", &BasePacket::getFloat, 26 | "getDouble", &BasePacket::getDouble, 27 | "getString", &BasePacket::getString, 28 | 29 | "pushInt8", &BasePacket::pushInt8, 30 | "pushUint8", &BasePacket::pushUint8, 31 | "pushInt16", &BasePacket::pushInt16, 32 | "pushUint16", &BasePacket::pushUint16, 33 | "pushInt32", &BasePacket::pushInt32, 34 | "pushUint32", &BasePacket::pushUint32, 35 | "pushInt64", &BasePacket::pushInt64, 36 | "pushUint64", &BasePacket::pushUint64, 37 | "pushFloat", &BasePacket::pushFloat, 38 | "pushDouble", &BasePacket::pushDouble, 39 | "pushString", &BasePacket::pushString, 40 | 41 | "moveData", & BasePacket::moveData, 42 | "wpos", &BasePacket::writePos, 43 | "rpos", &BasePacket::readPos, 44 | "readData", &BasePacket::readData, 45 | "writeData", &BasePacket::writeData); 46 | 47 | 48 | lua.new_usertype("TcpSocket", 49 | "close", &TcpSocket::close, 50 | "localIP", &TcpSocket::localIP, 51 | "localPort", &TcpSocket::localPort, 52 | "remoteIP", &TcpSocket::remoteIP, 53 | "remotePort", &TcpSocket::remotePort, 54 | "setUserdata", &TcpSocket::setUserdata, 55 | "getUserdata", &TcpSocket::getUserdata, 56 | "setUsernum", &TcpSocket::setUsernum, 57 | "getUsernum", &TcpSocket::getUsernum); 58 | } -------------------------------------------------------------------------------- /src/script/Lua_Common.cpp: -------------------------------------------------------------------------------- 1 | #include "sol/sol.hpp" 2 | #include "UTimer.h" 3 | #include "XLog.h" 4 | #include "Tools.h" 5 | #include "XFile.h" 6 | #include "XTime.h" 7 | 8 | class Lua_XLog 9 | { 10 | public: 11 | static void info_log(const char * log) { INFO_LOG(log); } 12 | static void warning_log(const char * log) { WARNING_LOG(log); } 13 | static void error_log(const char * log) { ERROR_LOG(log); } 14 | }; 15 | 16 | void luabind_common(sol::state & lua) 17 | { 18 | // file 19 | lua["writeFile"] = &XFile::writeFile; 20 | lua["isExist"] = &XFile::isExist; 21 | lua["mkdir"] = &XFile::mkdir; 22 | lua["rmdir"] = &XFile::rmdir; 23 | lua["createDir"] = &XFile::createDirectory; 24 | 25 | // log 26 | lua["infoLog"] = &Lua_XLog::info_log; 27 | lua["warningLog"] = &Lua_XLog::warning_log; 28 | lua["errorLog"] = &Lua_XLog::error_log; 29 | 30 | // timer 31 | lua.new_usertype("UTimer", 32 | "start", &UTimer::start, 33 | "stop", &UTimer::stop); 34 | 35 | // tool 36 | lua["sleep"] = &Tools::sleep; 37 | lua["gbk_utf8"] = &Tools::gbkToUtf8; 38 | lua["utf8_gbk"] = &Tools::utf8ToGbk; 39 | lua["srand"] = &Tools::srand; 40 | lua["random"] = &Tools::random; 41 | 42 | // time 43 | lua["isLeapYear"] = &XTime::isLeapYear; 44 | lua["yearMonthDays"] = &XTime::yearMonthDays; 45 | lua["milliStamp"] = &XTime::milliStamp; 46 | lua["microStamp"] = &XTime::microStamp; 47 | lua["stamp"] = &XTime::stamp; 48 | lua["iclock"] = &XTime::iclock; 49 | } -------------------------------------------------------------------------------- /src/script/Lua_CsvFile.cpp: -------------------------------------------------------------------------------- 1 | #include "sol/sol.hpp" 2 | #include "CsvParser.h" 3 | #include 4 | #include "BaseType.h" 5 | 6 | class Lua_CsvParser : public CsvParser 7 | { 8 | public: 9 | Lua_CsvParser(const char * file, int startline = 1, char sep = '\t'): 10 | CsvParser(file, startline, sep) 11 | { 12 | 13 | } 14 | 15 | //------->get 16 | int8 getInt8(int row, const char * name) { return getValue (row, name); } 17 | uint8 getUint8(int row, const char * name) { return getValue (row, name); } 18 | int16 getInt16(int row, const char * name) { return getValue (row, name); } 19 | uint16 getUint16(int row, const char * name) { return getValue (row, name); } 20 | int32 getInt32(int row, const char * name) { return getValue (row, name); } 21 | uint32 getUint32(int row, const char * name) { return getValue (row, name); } 22 | int64 getInt64(int row, const char * name) { return getValue (row, name); } 23 | uint64 getUint64(int row, const char * name) { return getValue (row, name); } 24 | float getFloat(int row, const char * name) { return getValue (row, name); } 25 | double getDouble(int row, const char * name) { return getValue (row, name); } 26 | std::string getString(int row, const char * name) { return getValue (row, name); } 27 | }; 28 | 29 | void luabind_csvpar(sol::state & lua) 30 | { 31 | lua.new_usertype("CsvParser", 32 | sol::constructors(), 33 | "getInt8", &Lua_CsvParser::getInt8, 34 | "getUint8", &Lua_CsvParser::getUint8, 35 | "getInt16", &Lua_CsvParser::getInt16, 36 | "getUint16", &Lua_CsvParser::getUint16, 37 | "getInt32", &Lua_CsvParser::getInt32, 38 | "getUint32", &Lua_CsvParser::getUint32, 39 | "getInt64", &Lua_CsvParser::getInt64, 40 | "getUint64", &Lua_CsvParser::getUint64, 41 | "getFloat", &Lua_CsvParser::getFloat, 42 | "getDouble", &Lua_CsvParser::getDouble, 43 | "getString", &Lua_CsvParser::getString, 44 | 45 | "row", &Lua_CsvParser::row); 46 | } -------------------------------------------------------------------------------- /src/script/Lua_EventLoop.cpp: -------------------------------------------------------------------------------- 1 | #include "EventLoop.h" 2 | #include "sol/sol.hpp" 3 | 4 | /* 5 | class EventLoop : public Singleton 6 | { 7 | public: 8 | void init(); 9 | 10 | int run(); 11 | void stop(); 12 | void exit(); 13 | uv_loop_t* getLoop(); 14 | 15 | private: 16 | uv_loop_t* mLoop; 17 | }; 18 | */ 19 | 20 | 21 | class Lua_EventLoop 22 | { 23 | public: 24 | static void init() { EventLoop::Instance()->init(); } 25 | static void run() { EventLoop::Instance()->run(); } 26 | static void stop() { EventLoop::Instance()->stop(); } 27 | static void exit() { EventLoop::Instance()->exit(); } 28 | }; 29 | 30 | 31 | 32 | void luabind_eventloop(sol::state & lua) 33 | { 34 | //lua["eventobj"] = EventLoop::Instance(); 35 | lua["event_init"] = &Lua_EventLoop::init; 36 | lua["event_run"] = &Lua_EventLoop::run; 37 | lua["event_stop"] = &Lua_EventLoop::stop; 38 | lua["event_exit"] = &Lua_EventLoop::exit; 39 | } -------------------------------------------------------------------------------- /src/script/Lua_HttpServer.cpp: -------------------------------------------------------------------------------- 1 | #include "sol/sol.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "HttpParam.h" 8 | #include "HttpServer.h" 9 | #include "HttpConnect.h" 10 | #include "EventLoop.h" 11 | 12 | class Lua_HttpServer : public HttpServer 13 | { 14 | public: 15 | Lua_HttpServer() : 16 | HttpServer(EventLoop::Instance()) 17 | { 18 | 19 | } 20 | }; 21 | 22 | void luabind_httpserver(sol::state & lua) 23 | { 24 | lua.new_usertype("HttpParam", 25 | sol::constructors(), 26 | "find", &HttpParam::find, 27 | "getStr", &HttpParam::getStr, 28 | "getInt", &HttpParam::getInt, 29 | "getFloat", &HttpParam::getFloat); 30 | 31 | lua.new_usertype("HttpConnect", 32 | sol::base_classes, sol::bases(), 33 | "sendMsg", &HttpConnect::sendData, 34 | "autoMsg", &HttpConnect::autoMsg); 35 | 36 | lua.new_usertype("HttpServer", 37 | "listen", &Lua_HttpServer::listen, 38 | "shutdown", &Lua_HttpServer::shutdown, 39 | "addGet", &Lua_HttpServer::addGet, 40 | "addPost", &Lua_HttpServer::addPost); 41 | } -------------------------------------------------------------------------------- /src/script/Lua_WebSockServer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sol/sol.hpp" 3 | 4 | #include "WebSocketEvent.h" 5 | #include "WebSocketServer.h" 6 | #include "WebSocketPacket.h" 7 | #include "WebSocketConnect.h" 8 | #include "EventLoop.h" 9 | 10 | class Lua_WebSocketServer : public WebSocketServer, public WebSocketEvent 11 | { 12 | public: 13 | Lua_WebSocketServer() : 14 | WebSocketServer(EventLoop::Instance(), this) 15 | { 16 | 17 | } 18 | 19 | protected: 20 | 21 | 22 | virtual void onAccept(WebSocketConnect * conn) { 23 | on_accept(conn); 24 | }; 25 | virtual void onClose(WebSocketConnect * conn) { 26 | on_close(conn); 27 | }; 28 | virtual void onMsg(WebSocketConnect * conn, WebSocketPacket * pack) { 29 | on_msg(conn, pack); 30 | }; 31 | 32 | public: 33 | std::function on_accept; 34 | std::function on_close; 35 | std::function on_msg; 36 | }; 37 | 38 | void luabind_websocket(sol::state & lua) 39 | { 40 | lua.new_usertype("WebSocketConnect", 41 | sol::base_classes, sol::bases(), 42 | "sendPacket", &WebSocketConnect::sendPacket, 43 | "sendMsg", &WebSocketConnect::sendData); 44 | 45 | lua.new_usertype("WebSocketServer", 46 | "listen", &Lua_WebSocketServer::listen, 47 | "shutdown", &Lua_WebSocketServer::shutdown, 48 | "on_accept", &Lua_WebSocketServer::on_accept, 49 | "on_close", &Lua_WebSocketServer::on_close, 50 | "on_msg", &Lua_WebSocketServer::on_msg); 51 | 52 | lua.new_usertype("WebSocketPacket", 53 | sol::base_classes, sol::bases()); 54 | } -------------------------------------------------------------------------------- /src/script/main.cpp: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | #include "lua/lua.h" 3 | #include "lua/lauxlib.h" 4 | #include "lua/lualib.h" 5 | } 6 | 7 | #include 8 | #include 9 | 10 | #include "sol/sol.hpp" 11 | #include "pb.h" 12 | 13 | extern void luabind_netserver(sol::state & lua); 14 | extern void luabind_kcpserver(sol::state & lua); 15 | extern void luabind_websocket(sol::state & lua); 16 | extern void luabind_eventloop(sol::state & lua); 17 | extern void luabind_mysql(sol::state & lua); 18 | extern void luabind_redis(sol::state & lua); 19 | extern void luabind_basepacket(sol::state & lua); 20 | extern void luabind_common(sol::state & lua); 21 | extern void luabind_csvpar(sol::state & lua); 22 | extern void luabind_json(sol::state & lua); 23 | extern void luabind_httpserver(sol::state & lua); 24 | 25 | 26 | void init_lua_pb(lua_State* L) 27 | { 28 | luaL_requiref(L, "pb", luaopen_pb, 0); 29 | luaL_requiref(L, "pb.slice", luaopen_pb_slice, 0); 30 | luaL_requiref(L, "pb.buffer", luaopen_pb_buffer, 0); 31 | luaL_requiref(L, "pb.conv", luaopen_pb_conv, 0); 32 | } 33 | 34 | int main(int argc, char* argv[]) 35 | { 36 | sol::state lua; 37 | lua.open_libraries(); 38 | 39 | // bind c++ && lua 40 | luabind_netserver(lua); 41 | luabind_kcpserver(lua); 42 | luabind_websocket(lua); 43 | luabind_eventloop(lua); 44 | luabind_mysql(lua); 45 | luabind_redis(lua); 46 | luabind_basepacket(lua); 47 | luabind_common(lua); 48 | luabind_csvpar(lua); 49 | luabind_json(lua); 50 | luabind_httpserver(lua); 51 | 52 | //lua.script_file(argv[1]); 53 | init_lua_pb(lua.lua_state()); 54 | 55 | if (luaL_dofile(lua.lua_state(), argv[1]) == 1) { 56 | if (lua_isstring(lua.lua_state(), -1)) { 57 | printf("load lua file error:%s\n", lua_tostring(lua.lua_state(), -1)); 58 | } 59 | } 60 | 61 | system("pause"); 62 | return 0; 63 | } -------------------------------------------------------------------------------- /src/serialization/Common.cpp: -------------------------------------------------------------------------------- 1 | #include "Common.h" 2 | #include "Token.h" 3 | #include "Fio.h" 4 | #include 5 | 6 | Common::Common() 7 | { 8 | } 9 | 10 | 11 | Common::~Common() 12 | { 13 | } 14 | 15 | bool Common::testToken(Token * pToken, int token) 16 | { 17 | if (pToken->getToken() == token) 18 | { 19 | pToken->nextToken(); 20 | return true; 21 | } 22 | 23 | return false; 24 | } 25 | 26 | bool Common::checkToken(Token * pToken, int token) 27 | { 28 | if (pToken->getToken() == token) 29 | { 30 | return true; 31 | } 32 | 33 | return false; 34 | } 35 | 36 | bool Common::matching(Token * pToken, int token) 37 | { 38 | if (pToken->getToken() == token) 39 | { 40 | pToken->nextToken(); 41 | return true; 42 | } 43 | 44 | error(pToken); 45 | return false; 46 | } 47 | 48 | int Common::error(Token * pToken) 49 | { 50 | std::string errstr(pToken->getBuffer()->lastPointer(), pToken->getBuffer()->currPointer() - pToken->getBuffer()->lastPointer()); 51 | printf("%s (%d) '%s' syntax error near.\n", pToken->getBuffer()->getFileName().c_str(), pToken->getBuffer()->getLine(), errstr.c_str()); 52 | 53 | assert(0); 54 | return 0; 55 | } -------------------------------------------------------------------------------- /src/serialization/Common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Token; 4 | class Common 5 | { 6 | public: 7 | Common(); 8 | ~Common(); 9 | 10 | static bool testToken(Token * pToken, int token); 11 | static bool checkToken(Token * pToken, int token); 12 | static bool matching(Token * pToken, int token); 13 | static int error(Token * pToken); 14 | }; 15 | 16 | #define P_TOKEN pToken() 17 | 18 | #define TEST_TOKEN(token) Common::testToken(P_TOKEN, token) 19 | #define CHECK_TOKEN(token) Common::checkToken(P_TOKEN, token) 20 | #define MATCH_TOKEN(token) Common::matching(P_TOKEN, token) 21 | #define NEXT_TOKEN P_TOKEN->nextToken() 22 | #define TOKEN_ERROR Common::error(P_TOKEN) -------------------------------------------------------------------------------- /src/serialization/Event.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Event.h -------------------------------------------------------------------------------- /src/serialization/Fio.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Fio.cpp -------------------------------------------------------------------------------- /src/serialization/Fio.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Fio.h -------------------------------------------------------------------------------- /src/serialization/Generate.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Generate.h -------------------------------------------------------------------------------- /src/serialization/GenerateLua.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/GenerateLua.h -------------------------------------------------------------------------------- /src/serialization/Keyword.cpp: -------------------------------------------------------------------------------- 1 | #include "Keyword.h" 2 | 3 | 4 | std::map Keyword::__m_keywords = { 5 | { "if", eKw_IF }, 6 | { "else", eKw_ELSE }, 7 | { "struct", eKw_STRUCT }, 8 | { "typedef", eKw_TYPEDEF}, 9 | { "vector", eKw_VECTOR }, 10 | { "read", eKw_READ }, 11 | { "write", eKw_WRITE }, 12 | { "import", eKw_IMPORT }, 13 | { "int8", eKw_INT8 }, 14 | { "uint8", eKw_UINT8 }, 15 | { "int16", eKw_INT16 }, 16 | { "uint16", eKw_UINT16 }, 17 | { "int32", eKw_INT32 }, 18 | { "uint32", eKw_UINT32 }, 19 | { "int64", eKw_INT64 }, 20 | { "uint64", eKw_UINT64 }, 21 | { "float", eKw_FLOAT }, 22 | { "double", eKw_DOUBLE }, 23 | { "string", eKw_STRING }, 24 | }; 25 | 26 | Keyword::Keyword() 27 | { 28 | } 29 | 30 | 31 | Keyword::~Keyword() 32 | { 33 | } 34 | 35 | int Keyword::getKeyword(const char * name) 36 | { 37 | auto it = __m_keywords.find(name); 38 | if (it == __m_keywords.end()) 39 | return 0; 40 | return it->second; 41 | } 42 | 43 | bool Keyword::isBaseType(int value) 44 | { 45 | switch (value) 46 | { 47 | case eKw_INT8: 48 | case eKw_UINT8: 49 | case eKw_INT16: 50 | case eKw_UINT16: 51 | case eKw_INT32: 52 | case eKw_UINT32: 53 | case eKw_INT64: 54 | case eKw_UINT64: 55 | case eKw_FLOAT: 56 | case eKw_DOUBLE: 57 | return true; 58 | 59 | default: 60 | return false; 61 | 62 | } 63 | } 64 | 65 | bool Keyword::isStrType(int value) 66 | { 67 | return value == eKw_STRING; 68 | } -------------------------------------------------------------------------------- /src/serialization/Keyword.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Keyword.h -------------------------------------------------------------------------------- /src/serialization/Parser.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Parser.cpp -------------------------------------------------------------------------------- /src/serialization/Parser.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Parser.h -------------------------------------------------------------------------------- /src/serialization/Token.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Token.cpp -------------------------------------------------------------------------------- /src/serialization/Token.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/Token.h -------------------------------------------------------------------------------- /src/serialization/Typedef.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Typedef.h" 3 | 4 | std::map Typedef::typedef_; // typedef int32 ID 5 | std::set Typedef::custom_type; // struct name 6 | 7 | 8 | void Typedef::addTypeInfo(const char * name, TypeInfo & info) 9 | { 10 | typedef_[name] = info; 11 | } 12 | 13 | TypeInfo * Typedef::getTypeInfo(const char * name) 14 | { 15 | auto it = typedef_.find(name); 16 | if (it != typedef_.end()) 17 | { 18 | return &(it->second); 19 | } 20 | 21 | return NULL; 22 | } 23 | 24 | bool Typedef::isVector(const char * name) 25 | { 26 | TypeInfo * info = getTypeInfo(name); 27 | if (!info) 28 | return false; 29 | 30 | if (info->type == 0) 31 | return false; 32 | 33 | return true; 34 | } 35 | 36 | bool Typedef::isStruct(const char * name) 37 | { 38 | return custom_type.find(name) != custom_type.end(); 39 | } 40 | 41 | void Typedef::addStruct(const char * key) 42 | { 43 | custom_type.insert(std::set::value_type(key)); 44 | } -------------------------------------------------------------------------------- /src/serialization/Typedef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class TypeInfo 7 | { 8 | public: 9 | // 0: base 1:vector 10 | int type = 0; 11 | 12 | //base 13 | int value; 14 | std::string name; 15 | 16 | // vector [typedef vector VEC] 17 | std::string vec_name; 18 | }; 19 | 20 | 21 | class Typedef 22 | { 23 | public: 24 | 25 | static void addStruct(const char * key); 26 | static bool isStruct(const char * name); 27 | 28 | static void addTypeInfo(const char * name, TypeInfo & info); 29 | static TypeInfo * getTypeInfo(const char * name); 30 | static bool isVector(const char * name); 31 | private: 32 | static std::map typedef_; // typedef int32 ID 33 | static std::set custom_type; // struct name 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /src/serialization/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/main.cpp -------------------------------------------------------------------------------- /src/serialization/test.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/src/serialization/test.cpp -------------------------------------------------------------------------------- /src/utils/HttpParser.cpp: -------------------------------------------------------------------------------- 1 | #include "HttpParser.h" 2 | 3 | HttpSettings::HttpSettings() 4 | { 5 | llhttp_settings_init(this); 6 | 7 | this->on_url = [](llhttp_t* _, const char* at, size_t length)->int { 8 | HttpParser* parser = (HttpParser*)(_); 9 | return parser->getUrl()->parse(at, length); 10 | }; 11 | } 12 | 13 | HttpSettings http_settings; 14 | 15 | HttpSettings* getHttpSettings() 16 | { 17 | return &http_settings; 18 | } 19 | 20 | HttpParser::HttpParser() 21 | { 22 | 23 | } 24 | 25 | void HttpParser::zero() 26 | { 27 | llhttp_init(this, HTTP_REQUEST, &http_settings); 28 | } 29 | 30 | #include 31 | bool HttpParser::parser(const char* buf, int len) 32 | { 33 | enum llhttp_errno err = llhttp_execute(this, buf, len); 34 | if (err != HPE_OK) 35 | { 36 | fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err), llhttp_t::reason); 37 | return false; 38 | } 39 | 40 | return true; 41 | } 42 | -------------------------------------------------------------------------------- /src/utils/HttpParser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "llhttp.h" 4 | #include "ParseUrl.h" 5 | 6 | // 7 | struct HttpSettings : public llhttp_settings_t 8 | { 9 | public: 10 | HttpSettings(); 11 | }; 12 | 13 | HttpSettings* getHttpSettings(); 14 | 15 | class HttpParser : public llhttp_t 16 | { 17 | public: 18 | HttpParser(); 19 | void zero(); 20 | 21 | bool parser(const char* buf, int len); 22 | uint64_t contentLen() { return llhttp_t::content_length; } 23 | uint8_t method() { return llhttp_t::method; } 24 | bool isClose() { return llhttp_should_keep_alive(this) == 0; } 25 | ParseUrl* getUrl() { return &m_url; } 26 | llhttp_t* getParser() { return this; } 27 | private: 28 | ParseUrl m_url; 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /src/utils/JsonReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace jwEngine 6 | { 7 | class JBaseObj; 8 | class JsonReader; 9 | class JsonBuff 10 | { 11 | friend JsonReader; 12 | public: 13 | JsonBuff(const char *str) { p = (char *)str; } 14 | ~JsonBuff() { if (obj != nullptr) { delete obj; obj = nullptr; } } 15 | 16 | // delete function 17 | JsonBuff(JsonBuff &) = delete; 18 | void operator =(JsonBuff &) = delete; 19 | 20 | const char *skip() { while (p && *p && (unsigned char)*p <= 32) p++; return p; } 21 | const char *curr() { return p; } 22 | const char *go(int len = 1) { p += len; return p; } 23 | private: 24 | char * p; 25 | JBaseObj * obj = nullptr; 26 | }; 27 | 28 | class JsonReader 29 | { 30 | public: 31 | 32 | JsonReader & operator | (JsonReader & r) { 33 | return *this; 34 | } 35 | 36 | //read 37 | static JBaseObj * parser(JsonBuff * buff); 38 | static std::string getError(JsonBuff * buff); 39 | 40 | static std::string write(JBaseObj * obj,bool layout = true); 41 | private: 42 | static bool readStr(std::string & outstr, JsonBuff * buff); 43 | static JBaseObj * readBase(JsonBuff * buff); 44 | static JBaseObj * readArray(JsonBuff * buff); 45 | static JBaseObj * readObj(JsonBuff * buff); 46 | static JBaseObj * reader(JsonBuff * buff); 47 | }; 48 | } -------------------------------------------------------------------------------- /src/utils/ParseUrl.cpp: -------------------------------------------------------------------------------- 1 | #include "ParseUrl.h" 2 | #include "http_parser.h" 3 | 4 | 5 | ParseUrl::ParseUrl() 6 | { 7 | m_buff = NULL; 8 | m_url = (struct http_parser_url*)malloc(sizeof(struct http_parser_url)); 9 | http_parser_url_init(m_url); 10 | } 11 | 12 | ParseUrl::~ParseUrl() 13 | { 14 | if (m_url) { 15 | free(m_url); 16 | m_url = NULL; 17 | } 18 | } 19 | 20 | int ParseUrl::parse(const char* buf, int len) 21 | { 22 | m_buff = buf; 23 | return http_parser_parse_url(buf, len, 0, m_url); 24 | } 25 | 26 | bool ParseUrl::haveParam() 27 | { 28 | return ((m_url->field_set & (1 << UF_QUERY)) != 0); 29 | } 30 | 31 | std::string_view ParseUrl::getPath() 32 | { 33 | return std::string_view(m_buff + m_url->field_data[UF_PATH].off, m_url->field_data[UF_PATH].len); 34 | } 35 | std::string_view ParseUrl::getParam() 36 | { 37 | return std::string_view(m_buff + m_url->field_data[UF_QUERY].off, m_url->field_data[UF_QUERY].len); 38 | } -------------------------------------------------------------------------------- /src/utils/ParseUrl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct http_parser_url; 6 | class ParseUrl 7 | { 8 | public: 9 | ParseUrl(); 10 | ~ParseUrl(); 11 | 12 | int parse(const char * buf, int len); 13 | bool haveParam(); 14 | std::string_view getPath(); 15 | std::string_view getParam(); 16 | 17 | private: 18 | struct http_parser_url * m_url; 19 | const char * m_buff; 20 | }; -------------------------------------------------------------------------------- /tool/serialization_cpp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/tool/serialization_cpp.exe -------------------------------------------------------------------------------- /tool/serialization_lua.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jwcpp/jwEngine/a02f21f6615cfc658e2321ca73fd38426b284378/tool/serialization_lua.exe --------------------------------------------------------------------------------