├── .gitattributes
├── uv-cpp
├── project
│ ├── cmake
│ │ └── build.sh
│ ├── vs2017
│ │ ├── rpc
│ │ │ └── rpc.vcxproj.user
│ │ ├── DNS
│ │ │ └── DNS.vcxproj.user
│ │ ├── pingpong
│ │ │ └── pingpong.vcxproj.user
│ │ ├── clients
│ │ │ └── clients.vcxproj.user
│ │ ├── helloworld
│ │ │ └── helloworld.vcxproj.user
│ │ ├── all_example
│ │ │ └── all_example.vcxproj.user
│ │ ├── create_lib
│ │ │ └── create_lib.vcxproj.user
│ │ ├── echo_server
│ │ │ └── echo_server.vcxproj.user
│ │ ├── http_client
│ │ │ └── http_client.vcxproj.user
│ │ ├── http_server
│ │ │ └── http_server.vcxproj.user
│ │ └── radix_tree
│ │ │ └── radix_tree.vcxproj.user
│ └── codeblocks_linux
│ │ ├── dns
│ │ └── dns.cbp
│ │ ├── clients
│ │ └── clients.cbp
│ │ ├── helloworld
│ │ └── helloworld.cbp
│ │ ├── radix_tree
│ │ └── radix_tree.cbp
│ │ ├── echo_server
│ │ └── echo_server.cbp
│ │ ├── http_client
│ │ └── http_client.cbp
│ │ ├── http_server
│ │ └── http_server.cbp
│ │ └── create_lib
│ │ └── create_lib.cbp
├── .gitattributes
├── libuv1.30.0
│ ├── lib
│ │ ├── gcc8.3.0
│ │ │ ├── libuv.a
│ │ │ ├── libuv.so
│ │ │ ├── libuv.so.1
│ │ │ ├── libuv.so.1.0.0
│ │ │ ├── pkgconfig
│ │ │ │ └── libuv.pc
│ │ │ └── libuv.la
│ │ └── win_sdk10.0.10240
│ │ │ ├── Debug
│ │ │ └── libuv.lib
│ │ │ └── Release
│ │ │ └── libuv.lib
│ └── include
│ │ └── uv
│ │ ├── threadpool.h
│ │ ├── os390.h
│ │ ├── posix.h
│ │ ├── aix.h
│ │ ├── bsd.h
│ │ ├── linux.h
│ │ ├── version.h
│ │ ├── android-ifaddrs.h
│ │ └── sunos.h
├── doc
│ ├── README.md
│ ├── en
│ │ ├── ListBuffer.md
│ │ ├── CycleBuffer.md
│ │ ├── Idle.md
│ │ ├── Async.md
│ │ ├── GlobalConfig.md
│ │ ├── Signal.md
│ │ ├── DnsGet.md
│ │ ├── TimerWheel.md
│ │ ├── Timer.md
│ │ ├── Udp.md
│ │ ├── EventLoop.md
│ │ ├── TcpAccepter.md
│ │ ├── PacketBuffer.md
│ │ ├── SocketAddr.md
│ │ ├── Packet.md
│ │ ├── LogWriter.md
│ │ ├── TcpClient.md
│ │ └── TcpConnection.md
│ └── cn
│ │ ├── CycleBuffer.md
│ │ ├── ListBuffer.md
│ │ ├── Idle.md
│ │ ├── Async.md
│ │ ├── GlobalConfig.md
│ │ ├── Signal.md
│ │ ├── Timer.md
│ │ ├── TimerWheel.md
│ │ ├── DnsGet.md
│ │ ├── Udp.md
│ │ ├── EventLoop.md
│ │ ├── TcpAccepter.md
│ │ ├── PacketBuffer.md
│ │ ├── Packet.md
│ │ ├── SocketAddr.md
│ │ ├── LogWriter.md
│ │ ├── TcpClient.md
│ │ └── TcpConnection.md
├── examples
│ ├── pingpang
│ │ ├── EchoServer.h
│ │ ├── main.cpp
│ │ ├── EchoServer.cpp
│ │ └── Clinet.h
│ ├── all_example
│ │ ├── EchoServer.h
│ │ ├── Clinet.h
│ │ └── EchoServer.cpp
│ ├── clients_cross_thread
│ │ ├── Client.h
│ │ ├── Client.cpp
│ │ └── main.cpp
│ ├── dns
│ │ └── main.cpp
│ ├── rpc
│ │ ├── RpcCtrl.h
│ │ ├── RpcServer.cpp
│ │ ├── RpcServer.h
│ │ ├── main.cpp
│ │ ├── RpcClient.h
│ │ ├── RpcCtrl.cpp
│ │ ├── RpcClient.cpp
│ │ └── protocol.h
│ ├── echo_server
│ │ └── main.cpp
│ ├── helloworld
│ │ └── main.cpp
│ ├── echo_client
│ │ └── main.cpp
│ ├── http_client
│ │ └── main.cpp
│ └── boost_asio_echo_client
│ │ └── main.cpp
├── uv
│ ├── include
│ │ ├── uv11.h
│ │ ├── Idle.h
│ │ ├── Async.h
│ │ ├── Signal.h
│ │ ├── DnsGet.h
│ │ ├── GlobalConfig.h
│ │ ├── ListBuffer.h
│ │ ├── TcpAccepter.h
│ │ ├── Timer.h
│ │ ├── EventLoop.h
│ │ ├── Udp.h
│ │ ├── http
│ │ │ ├── HttpClient.h
│ │ │ ├── HttpCommon.h
│ │ │ ├── HttpServer.h
│ │ │ ├── Response.h
│ │ │ └── Request.h
│ │ ├── SocketAddr.h
│ │ ├── CycleBuffer.h
│ │ ├── PacketBuffer.h
│ │ ├── LogWriter.h
│ │ ├── TcpClient.h
│ │ ├── TcpServer.h
│ │ └── TimerWheel.h
│ ├── GlobalConfig.cpp
│ ├── Idle.cpp
│ ├── ListBuffer.cpp
│ ├── Async.cpp
│ ├── Timer.cpp
│ ├── DnsGet.cpp
│ ├── Signal.cpp
│ ├── EventLoop.cpp
│ └── TcpAccepter.cpp
├── CMakeLists.txt
└── LICENSE
├── src
└── orca
│ ├── core
│ ├── MailBoxThread.cpp
│ ├── Define.h
│ ├── net
│ │ ├── TcpPacket.cpp
│ │ ├── Protocol.h
│ │ ├── TcpPacket.h
│ │ ├── ActorServer.h
│ │ ├── ActorClient.h
│ │ └── ActorServer.cpp
│ ├── Address.h
│ ├── Mail.h
│ ├── MailBoxThread.h
│ ├── MessageTraits.h
│ ├── Assert.h
│ ├── Mailbox.h
│ ├── MessagePack.h
│ └── MailboxPage.h
│ ├── base
│ ├── queue
│ │ └── BlockQueue.h
│ ├── error
│ │ ├── ErrorInfo.cpp
│ │ ├── ErrorInfo.h
│ │ └── ErrorHandle.h
│ ├── SpinLock
│ │ ├── SpinLock.h
│ │ └── SpinLock.cpp
│ ├── condition
│ │ ├── Condition.cpp
│ │ └── Condition.h
│ └── thread
│ │ ├── ThreadPool.h
│ │ ├── ThreadPool.cpp
│ │ ├── Thread.h
│ │ └── Thread.cpp
│ └── orca.h
├── examples
├── pingpong
│ ├── MessageType.h
│ └── main.cpp
├── remoteActorMessage
│ ├── main.cpp
│ └── MessageType.h
├── messageTypeRegister
│ ├── MessageType.h
│ └── main.cpp
├── README.md
├── errorhandle
│ └── errorhandle.cpp
├── helloworld
│ └── helloworld.cpp
└── sendByName
│ └── SendByName.cpp
├── project
└── vs2017
│ ├── SendByName
│ └── SendByName.vcxproj.user
│ ├── helloworld
│ └── helloworld.vcxproj.user
│ ├── pingpong
│ └── pingpong.vcxproj.user
│ ├── errorhandle
│ └── errorhandle.vcxproj.user
│ ├── MessageTypeRegister
│ └── MessageTypeRegister.vcxproj.user
│ └── RemoteActorMessage
│ └── RemoteActorMessage.vcxproj.user
├── LICENSE
├── README.md
└── CMakeLists.txt
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.h linguist-language=C++
--------------------------------------------------------------------------------
/uv-cpp/project/cmake/build.sh:
--------------------------------------------------------------------------------
1 | cmake ../../
2 | make
3 |
4 |
--------------------------------------------------------------------------------
/src/orca/core/MailBoxThread.cpp:
--------------------------------------------------------------------------------
1 | #include "MessagePack.h"
2 |
3 |
--------------------------------------------------------------------------------
/uv-cpp/.gitattributes:
--------------------------------------------------------------------------------
1 | *.h linguist-language=C++
2 | *.lua linguist-language=C++
--------------------------------------------------------------------------------
/src/orca/core/Define.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/src/orca/core/Define.h
--------------------------------------------------------------------------------
/examples/pingpong/MessageType.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/examples/pingpong/MessageType.h
--------------------------------------------------------------------------------
/src/orca/core/net/TcpPacket.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/src/orca/core/net/TcpPacket.cpp
--------------------------------------------------------------------------------
/src/orca/base/queue/BlockQueue.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/src/orca/base/queue/BlockQueue.h
--------------------------------------------------------------------------------
/examples/remoteActorMessage/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/examples/remoteActorMessage/main.cpp
--------------------------------------------------------------------------------
/examples/remoteActorMessage/MessageType.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/examples/remoteActorMessage/MessageType.h
--------------------------------------------------------------------------------
/uv-cpp/libuv1.30.0/lib/gcc8.3.0/libuv.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/uv-cpp/libuv1.30.0/lib/gcc8.3.0/libuv.a
--------------------------------------------------------------------------------
/uv-cpp/libuv1.30.0/lib/gcc8.3.0/libuv.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/uv-cpp/libuv1.30.0/lib/gcc8.3.0/libuv.so
--------------------------------------------------------------------------------
/examples/messageTypeRegister/MessageType.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/examples/messageTypeRegister/MessageType.h
--------------------------------------------------------------------------------
/uv-cpp/libuv1.30.0/lib/gcc8.3.0/libuv.so.1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/uv-cpp/libuv1.30.0/lib/gcc8.3.0/libuv.so.1
--------------------------------------------------------------------------------
/uv-cpp/libuv1.30.0/lib/gcc8.3.0/libuv.so.1.0.0:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/uv-cpp/libuv1.30.0/lib/gcc8.3.0/libuv.so.1.0.0
--------------------------------------------------------------------------------
/uv-cpp/libuv1.30.0/lib/win_sdk10.0.10240/Debug/libuv.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/uv-cpp/libuv1.30.0/lib/win_sdk10.0.10240/Debug/libuv.lib
--------------------------------------------------------------------------------
/uv-cpp/libuv1.30.0/lib/win_sdk10.0.10240/Release/libuv.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wlgq2/orca/HEAD/uv-cpp/libuv1.30.0/lib/win_sdk10.0.10240/Release/libuv.lib
--------------------------------------------------------------------------------
/uv-cpp/doc/README.md:
--------------------------------------------------------------------------------
1 | API's document, [中文][1] or [English][2].
2 |
3 | [1]: https://github.com/wlgq2/uv-cpp/tree/master/doc/cn
4 | [2]: https://github.com/wlgq2/uv-cpp/tree/master/doc/en
5 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/rpc/rpc.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/DNS/DNS.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/project/vs2017/SendByName/SendByName.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/project/vs2017/helloworld/helloworld.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/project/vs2017/pingpong/pingpong.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/pingpong/pingpong.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/project/vs2017/errorhandle/errorhandle.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/clients/clients.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/helloworld/helloworld.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/ListBuffer.md:
--------------------------------------------------------------------------------
1 | # ListBuffer : PacketBuffer
2 | 链表数据缓存,PacketBuffer接口的一种实现。
3 | ```C++
4 | ListBuffer()
5 | ```
6 | 构造函数。
7 |
8 | ```C++
9 | virtual ~ListBuffer()
10 | ```
11 | 析构函数。
12 |
13 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/all_example/all_example.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/create_lib/create_lib.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/echo_server/echo_server.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/http_client/http_client.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/http_server/http_server.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/project/vs2017/radix_tree/radix_tree.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/CycleBuffer.md:
--------------------------------------------------------------------------------
1 | # CycleBuffer : PacketBuffer
2 | 循环数据缓存,PacketBuffer 接口的一种实现。
3 | ```C++
4 | CycleBuffer()
5 | ```
6 | 构造函数。
7 |
8 | ```C++
9 | virtual ~CycleBuffer()
10 | ```
11 | 析构函数。
12 |
13 |
--------------------------------------------------------------------------------
/project/vs2017/MessageTypeRegister/MessageTypeRegister.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/project/vs2017/RemoteActorMessage/RemoteActorMessage.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # tutorial
2 | ** **
3 | * `Helloworld`:基本发送/接收本地消息操作。
4 | * `SendByName`:通过Actor Name发送消息。
5 | * `MessageTypeRegister`:注册自定义消息类型(需要实现相应接口)。
6 | * `Errorhandle`:注册错误回调处理操作。
7 | * `pingpang`:消息ping-pong操作。
8 | * `RemoteActorMessage`:网络消息通信。
9 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/ListBuffer.md:
--------------------------------------------------------------------------------
1 | # ListBuffer : PacketBuffer
2 | List buffer ,an implementation of the PacketBuffer interface.
3 | ```C++
4 | ListBuffer()
5 | ```
6 | Constructor.
7 |
8 | ```C++
9 | virtual ~ListBuffer()
10 | ```
11 | Destructor.
12 |
13 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/CycleBuffer.md:
--------------------------------------------------------------------------------
1 | # CycleBuffer : PacketBuffer
2 | Cycle buffer ,an implementation of the PacketBuffer interface.
3 | ```C++
4 | CycleBuffer()
5 | ```
6 | Constructor.
7 |
8 | ```C++
9 | virtual ~CycleBuffer()
10 | ```
11 | Destructor.
12 |
13 |
--------------------------------------------------------------------------------
/src/orca/orca.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_ORCA_H
2 | #define ORCA_ORCA_H
3 |
4 | #include "core/Define.h"
5 | #include "core/Actor.h"
6 | #include "core/Framework.h"
7 | #include "core/MessagePack.h"
8 | #include "base/error/ErrorHandle.h"
9 |
10 | #endif // ! ORCA_ORCA_H
11 |
12 |
--------------------------------------------------------------------------------
/src/orca/core/Address.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_ADDRESS_H
2 | #define ORCA_ADDRESS_H
3 |
4 | #include
5 |
6 | namespace orca
7 | {
8 | namespace core
9 | {
10 |
11 | struct Address
12 | {
13 | uint32_t framework;
14 | uint32_t page;
15 | uint32_t index;
16 | };
17 | }
18 | }
19 | #endif // ! ORCA_ADDRESS_H
20 |
21 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/Idle.md:
--------------------------------------------------------------------------------
1 | # Idle
2 | 空闲事件,在每次EventLoop事件中都被调用。
3 |
4 | ```C++
5 | Idle(EventLoop* loop)
6 | ```
7 | 构造函数
8 | * EventLoop* loop : EventLoop对象句柄。
9 |
10 | ```C++
11 | virtual ~Idle()
12 | ```
13 | 析构函数
14 |
15 | ```C++
16 | void setCallback(DefaultCallback callback)
17 | ```
18 | 注册一个回调函数到eventloop中执行。
19 | * DefaultCallback callback : 注册运行回调函数。
20 |
--------------------------------------------------------------------------------
/src/orca/core/Mail.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_MAIL_H
2 | #define ORCA_MAIL_H
3 |
4 | #include
5 |
6 | namespace orca
7 | {
8 |
9 | namespace core
10 | {
11 |
12 | template
13 | struct Mail
14 | {
15 | Address from;
16 | Address destination;
17 | std::shared_ptr message;
18 | };
19 | }
20 | }
21 | #endif // ! ORCA_MAIL_H
22 |
23 |
--------------------------------------------------------------------------------
/src/orca/core/MailBoxThread.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_MAILBOX_THREAD_H
2 | #define ORCA_MAILBOX_THREAD_H
3 |
4 | class MailBoxThread
5 | {
6 | public:
7 | MailBoxThread();
8 | ~MailBoxThread();
9 |
10 | private:
11 |
12 | };
13 |
14 | MailBoxThread::MailBoxThread()
15 | {
16 | }
17 |
18 | MailBoxThread::~MailBoxThread()
19 | {
20 | }
21 | #endif // ! ORCA_MAILBOX_THREAD
22 |
23 |
--------------------------------------------------------------------------------
/uv-cpp/libuv1.30.0/lib/gcc8.3.0/pkgconfig/libuv.pc:
--------------------------------------------------------------------------------
1 | prefix=/mnt/hgfs/share/uv130
2 | exec_prefix=${prefix}
3 | libdir=${exec_prefix}/lib
4 | includedir=${prefix}/include
5 |
6 | Name: libuv
7 | Version: 1.30.0
8 | Description: multi-platform support library with a focus on asynchronous I/O.
9 | URL: http://libuv.org/
10 |
11 | Libs: -L${libdir} -luv -lrt -lpthread -lnsl -ldl
12 | Cflags: -I${includedir}
13 |
--------------------------------------------------------------------------------
/src/orca/base/error/ErrorInfo.cpp:
--------------------------------------------------------------------------------
1 | #include "ErrorInfo.h"
2 |
3 | using namespace orca::base;
4 |
5 | orca::base::ErrorInfo::ErrorInfo(ErrorId id, std::string info)
6 | :id_(id),
7 | info_(info)
8 | {
9 | }
10 |
11 | ErrorInfo::ErrorId orca::base::ErrorInfo::getErrorId()
12 | {
13 | return id_;
14 | }
15 |
16 | std::string& orca::base::ErrorInfo::getErrorInfo()
17 | {
18 | return info_;
19 | }
20 |
--------------------------------------------------------------------------------
/src/orca/core/net/Protocol.h:
--------------------------------------------------------------------------------
1 | #ifndef CORE_PROCOTOL_H
2 | #define CORE_PROCOTOL_H
3 |
4 |
5 | namespace orca
6 | {
7 | namespace core
8 | {
9 | class Protocol
10 | {
11 | public:
12 | enum MessageType
13 | {
14 | ReqFrameworkId = 1,
15 | RespFrameworkId,
16 | ActorMessage,
17 | HeartBeatMessage
18 | };
19 |
20 | };
21 | }
22 | }
23 | #endif // ! CORE_PROCOTOL_H
24 |
25 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/Idle.md:
--------------------------------------------------------------------------------
1 | # Idle
2 |
3 | Idle handles will run the given callback once per loop iteration.
4 |
5 | ```C++
6 | Idle(EventLoop* loop)
7 | ```
8 | Constructor.
9 | * EventLoop* loop : EventLoop's handle.
10 |
11 | ```C++
12 | virtual ~Idle()
13 | ```
14 | Destructor.
15 |
16 | ```C++
17 | void setCallback(DefaultCallback callback)
18 | ```
19 | Set the idle callback function run in eventloop.
20 | * DefaultCallback callback : callback function.
21 |
--------------------------------------------------------------------------------
/uv-cpp/examples/pingpang/EchoServer.h:
--------------------------------------------------------------------------------
1 | #ifndef ECHOSERVER_H
2 | #define ECHOSERVER_H
3 |
4 | #include "uv/include/uv11.h"
5 | #include
6 |
7 | class EchoServer :public uv::TcpServer
8 | {
9 | public:
10 | EchoServer(uv::EventLoop* loop);
11 |
12 | uint64_t Cnt();
13 | void clearCnt();
14 | private :
15 | std::atomic cnt;
16 | void newMessage(uv::TcpConnectionPtr connection,const char* buf,ssize_t size);
17 | };
18 |
19 | #endif // ECHOSERVER_H
20 |
--------------------------------------------------------------------------------
/src/orca/base/SpinLock/SpinLock.h:
--------------------------------------------------------------------------------
1 | #ifndef SPIN_LOCK_H
2 | #define SPIN_LOCK_H
3 |
4 | #include
5 | namespace orca
6 | {
7 | namespace base
8 | {
9 |
10 | class SpinLock
11 | {
12 | public:
13 | enum
14 | {
15 | Unlocked,
16 | Locked
17 | };
18 |
19 | SpinLock();
20 | void lock();
21 | void unlock();
22 | private:
23 | std::atomic locked_;
24 | };
25 | }
26 | }
27 | #endif // ! SPIN_LOCK_H
28 |
29 |
--------------------------------------------------------------------------------
/src/orca/base/condition/Condition.cpp:
--------------------------------------------------------------------------------
1 | #include "Condition.h"
2 |
3 | void orca::base::Condition::notifyAll()
4 | {
5 | std::unique_lock lock(mutex_);
6 | condition_.notify_all();
7 | }
8 |
9 | void orca::base::Condition::notify()
10 | {
11 | std::unique_lock lock(mutex_);
12 | condition_.notify_one();
13 | }
14 |
15 | void orca::base::Condition::wait(ConditionCallback callback)
16 | {
17 | std::unique_lock lock(mutex_);
18 | condition_.wait(lock, callback);
19 | }
20 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/Async.md:
--------------------------------------------------------------------------------
1 | # Async
2 | 异步接口,用于跨线程调用函数。
3 |
4 | ```C++
5 | Async(EventLoop* loop)
6 | ```
7 | 构造函数
8 | * EventLoop* loop : EventLoop对象句柄。
9 |
10 | ```C++
11 | virtual ~Async()
12 | ```
13 | 析构函数
14 |
15 | ```C++
16 | void runInThisLoop(DefaultCallback callback)
17 | ```
18 | 注册一个回调函数到eventloop中执行。
19 | * DefaultCallback callback : 注册运行回调函数。
20 |
21 | ```C++
22 | void close(DefaultCallback callback)
23 | ```
24 | 关闭async接口。回调函数被执行时,对象可以被安全释放。
25 | * DefaultCallback callback : 关闭完成后的回调函数。
26 |
27 |
--------------------------------------------------------------------------------
/src/orca/base/SpinLock/SpinLock.cpp:
--------------------------------------------------------------------------------
1 | #include "SpinLock.h"
2 |
3 | #include
4 | using namespace orca::base;
5 |
6 | SpinLock::SpinLock()
7 | :locked_(Unlocked)
8 | {
9 | }
10 |
11 | void SpinLock::lock()
12 | {
13 | while (true)
14 | {
15 | int old(Unlocked);
16 | if (locked_.compare_exchange_strong(old, Locked))
17 | {
18 | return;
19 | }
20 | std::this_thread::yield();
21 | }
22 | }
23 |
24 | void SpinLock::unlock()
25 | {
26 | locked_.store(Unlocked);
27 | }
28 |
--------------------------------------------------------------------------------
/src/orca/base/condition/Condition.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_CONDITION_H
2 | #define ORCA_CONDITION_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | namespace orca
9 | {
10 | namespace base
11 | {
12 |
13 | class Condition
14 | {
15 | public:
16 | using ConditionCallback = std::function;
17 |
18 | void notifyAll();
19 | void notify();
20 | void wait(ConditionCallback callback);
21 | private:
22 | std::mutex mutex_;
23 | std::condition_variable condition_;
24 | };
25 | }
26 | }
27 | #endif
--------------------------------------------------------------------------------
/uv-cpp/examples/all_example/EchoServer.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2018-4-18
7 |
8 | Description: https://github.com/wlgq2/uv-cpp
9 | */
10 |
11 | #ifndef ECHOSERVER_H
12 | #define ECHOSERVER_H
13 |
14 | #include "uv/include/uv11.h"
15 |
16 |
17 | class EchoServer :public uv::TcpServer
18 | {
19 | public:
20 | EchoServer(uv::EventLoop* loop);
21 | private :
22 | void newMessage(uv::TcpConnectionPtr connection,const char* buf,ssize_t size);
23 | };
24 |
25 | #endif // ECHOSERVER_H
26 |
--------------------------------------------------------------------------------
/src/orca/core/MessageTraits.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_MESSAGE_TRAITS_H
2 | #define ORCA_MESSAGE_TRAITS_H
3 |
4 | #include
5 |
6 | namespace orca
7 | {
8 | namespace core
9 | {
10 |
11 | template
12 | struct MessageTraits
13 | {
14 | static const char* Enter(T& object)
15 | {
16 | return object.enter();
17 | }
18 | };
19 |
20 | template<>
21 | struct MessageTraits
22 | {
23 | static const char* Enter(std::string& object)
24 | {
25 | return (object.c_str());
26 | }
27 | };
28 | }
29 | }
30 | #endif
31 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/GlobalConfig.md:
--------------------------------------------------------------------------------
1 | # GlobalConfig
2 | 全局变量及配置。
3 | ```C++
4 | static BufferMode BufferModeStatus
5 | ```
6 | 使用数据缓存模式,NoBuffer、CycleBuffer、ListBuffer。默认为NoBuffer。
7 |
8 | ```C++
9 | static uint64_t CycleBufferSize
10 | ```
11 | 循环缓存数据大小,默认32KB。
12 |
13 | ```C++
14 | static ReadBufferPacketFunc ReadBufferPacket
15 | ```
16 | Packet数据包解析读取函数,默认为Packet::readFromBuffer。
17 |
18 | ```C++
19 | static ReadBufferStringFunc ReadBufferString
20 | ```
21 | String数据包解析读取函数,默认为空。
22 |
23 | ```C++
24 | static ReadBufferVoidFunc ReadBufferVoid
25 | ```
26 | 自定义数据包解析读取函数,默认为空。
27 |
--------------------------------------------------------------------------------
/uv-cpp/uv/include/uv11.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2020-4-13
7 |
8 | Description: https://github.com/wlgq2/uv-cpp
9 | */
10 |
11 | #ifndef UV_UV11_H
12 | #define UV_UV11_H
13 |
14 | #define UV_CPP_VERSION "1.4.8"
15 |
16 | #include "Async.h"
17 | #include "Signal.h"
18 | #include "TcpServer.h"
19 | #include "TcpClient.h"
20 | #include "LogWriter.h"
21 | #include "Packet.h"
22 | #include "Udp.h"
23 | #include "Idle.h"
24 | #include "GlobalConfig.h"
25 | #include "DnsGet.h"
26 | #include "http/HttpClient.h"
27 | #include "http/HttpServer.h"
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/Signal.md:
--------------------------------------------------------------------------------
1 | # Signal
2 | libuv信号封装。
3 |
4 | ```C++
5 | Signal(EventLoop* loop,int sig, SignalHandle handle = nullptr);
6 | ```
7 | 构造函数。
8 | * EventLoop* loop : event loop句柄。
9 | * int sig : 信号值。
10 | * SignalHandle handle : 信号回调函数。
11 |
12 | ```C++
13 | void close(DefaultCallback callback);
14 | ```
15 | 关闭信号回调。
16 | * DefaultCallback callback : 关闭完成回调函数。
17 |
18 | ```C++
19 | virtual ~Signal();
20 | ```
21 | 析构函数。
22 |
23 |
24 | ```C++
25 | void setHandle(SignalHandle handle);
26 | ```
27 | 设置回调函数。
28 | * SignalHandle handle :信号回调函数。
29 |
30 |
31 | ```C++
32 | static void Ignore(int sig);
33 | ```
34 | 忽略某个信号,仅linux环境下有效。
35 | * int sig : 信号值。
36 |
37 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/Async.md:
--------------------------------------------------------------------------------
1 | # Async
2 | Asynchronous interface, used to across threads.
3 |
4 | ```C++
5 | Async(EventLoop* loop)
6 | ```
7 | Constructor.
8 | * EventLoop* loop : EventLoop's handle.
9 |
10 | ```C++
11 | virtual ~Async()
12 | ```
13 | Destructor.
14 |
15 | ```C++
16 | void runInThisLoop(DefaultCallback callback)
17 | ```
18 | Register a callback function run in eventloop.
19 | * DefaultCallback callback : callback function.
20 |
21 | ```C++
22 | void close(DefaultCallback callback)
23 | ```
24 | Close async object. The async's object can be released safely when the callback function is called,
25 |
26 | * DefaultCallback callback : Is called when the close is complete.
27 |
28 |
--------------------------------------------------------------------------------
/src/orca/core/net/TcpPacket.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2017, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2020-7-26
7 |
8 | Description:
9 | */
10 | #ifndef ORCA_TCP_PACKET_H
11 | #define ORCA_TCP_PACKET_H
12 |
13 | #include "../../../../uv-cpp/uv/include/uv11.h"
14 |
15 | namespace orca
16 | {
17 | namespace core
18 | {
19 | class TcpPacket :public uv::Packet
20 | {
21 | public :
22 | void packWithType(const char* data, uint16_t size);
23 | const char* getData();
24 | static int ReadTcpBuffer(uv::PacketBuffer* packetbuf, void* out);
25 | public:
26 | uint64_t messageType_;
27 | };
28 |
29 | }
30 | }
31 | #endif // ! ORCA_ACTOR_SERVER_H
32 |
33 |
--------------------------------------------------------------------------------
/uv-cpp/uv/include/Idle.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2019-9-11
7 |
8 | Description: https://github.com/wlgq2/uv-cpp
9 | */
10 |
11 | #ifndef UV_IDLE_H
12 | #define UV_IDLE_H
13 |
14 | #include "EventLoop.h"
15 |
16 | namespace uv
17 | {
18 |
19 | class Idle
20 | {
21 | public:
22 | Idle(EventLoop* loop);
23 | virtual ~Idle();
24 |
25 |
26 | void setCallback(DefaultCallback callback);
27 |
28 | private:
29 | uv_idle_t* idle_;
30 |
31 | DefaultCallback callback_;
32 |
33 | private:
34 | void onCallback();
35 | static void idleCallback(uv_idle_t *handle);
36 | };
37 |
38 | }
39 | #endif
40 |
--------------------------------------------------------------------------------
/examples/errorhandle/errorhandle.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 |
5 | REGISTER_MESSAGE_TYPE(std::string);
6 |
7 | void errorHandle(orca::base::ErrorInfo info)
8 | {
9 | std::cout << "error id : " << info.getErrorId() << std::endl;
10 | std::cout << "error message: " << info.getErrorInfo() << std::endl;
11 | }
12 |
13 | int main(int argc, char** args)
14 | {
15 | //actor framework.
16 | orca::Framework framework;
17 |
18 | framework.RegisterErrorHandle(std::bind(&errorHandle,std::placeholders::_1));
19 |
20 | orca::base::ErrorHandle::Instance()->error(orca::base::ErrorInfo::UndefinedError,"undefine error");
21 | framework.loop();
22 |
23 | }
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/Timer.md:
--------------------------------------------------------------------------------
1 | # Timer
2 | 定时器类。
3 |
4 | ```C++
5 | Timer(EventLoop* loop, uint64_t timeout, uint64_t repeat, TimerCallback callback)
6 | ```
7 | 构造函数。
8 | * EventLoop* loop : Event loop句柄。
9 | * int64_t timeout : 第一次超时时间,单位毫秒。
10 | * uint64_t repeat : 定时器周期,单位毫秒,为零为不重复。
11 | * TimerCallback callback : 定时器回调函数。
12 |
13 | ```C++
14 | virtual ~Timer()
15 | ```
16 | 析构函数。
17 |
18 | ```C++
19 | void start()
20 | ```
21 | 开始定时器。
22 |
23 | ```C++
24 | void close(TimerCloseComplete callback)
25 | ```
26 | 关闭定时器。
27 | * TimerCloseComplete callback : 关闭完成回调函数,可安全析构定时器对象。
28 | * TimerCloseComplete : void(Timer*)。
29 |
30 | ```C++
31 | void setTimerRepeat(uint64_t ms)
32 | ```
33 | 修改定时器周期。
34 | * uint64_t ms : 定时器周,单位毫秒。
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/TimerWheel.md:
--------------------------------------------------------------------------------
1 | # TimerWheel template
2 | 时间轮类。
3 |
4 | ```C++
5 | TimerWheel(EventLoop* loop)
6 | ```
7 | 构造函数。
8 | * EventLoop* loop : Event loop句柄。
9 |
10 | ```C++
11 | TimerWheel(EventLoop* loop,unsigned int timeout)
12 | ```
13 | 构造函数。
14 | * EventLoop* loop : Event loop句柄。
15 | * unsigned int timeout : 超时时间,单位秒。
16 |
17 | ```C++
18 | void setTimeout(unsigned int seconds)
19 | ```
20 | 设置超时时间,单位秒。
21 | * unsigned int timeout : 超时时间,单位秒。
22 |
23 | ```C++
24 | int getTimeout()
25 | ```
26 | 返回超时时间。
27 | * 返回值 : 超时时间,单位秒。
28 |
29 | ```C++
30 | void start()
31 | ```
32 | 开始时间轮。
33 |
34 | ```C++
35 | void insert(std::shared_ptr value)
36 | ```
37 | 插入时间轮对象。
38 | * std::shared_ptr value : 时间轮元素对象。
--------------------------------------------------------------------------------
/uv-cpp/examples/clients_cross_thread/Client.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2018-4-18
7 |
8 | Description: https://github.com/wlgq2/uv-cpp
9 | */
10 |
11 | #ifndef CLIENT_H
12 | #define CLIENT_H
13 |
14 |
15 | #include
16 | #include "uv/include/uv11.h"
17 |
18 |
19 | class Client : public uv::TcpClient
20 | {
21 | public:
22 | Client(uv::EventLoop* loop);
23 |
24 | void connectToServer(uv::SocketAddr& addr);
25 | void reConnect();
26 | void onConnect(ConnectStatus status);
27 | void newMessage(const char* buf,ssize_t size);
28 |
29 | private:
30 | std::shared_ptr sockAddr;
31 | };
32 | #endif
33 |
--------------------------------------------------------------------------------
/uv-cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # CMakeLists.txt
2 | # Copyright (C) orcaer@yeah.net. All rights reserved.
3 | # Last modified: 2019-9-3
4 |
5 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
6 |
7 | PROJECT(uv_cpp)
8 |
9 | INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/
10 | ${PROJECT_SOURCE_DIR}/libuv1.30.0/include)
11 |
12 | AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/uv SOURCES)
13 | AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/uv/http SOURCES)
14 |
15 | LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/libuv1.30.0/lib/gcc8.3.0)
16 |
17 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -O2")
18 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2")
19 |
20 |
21 | MESSAGE("building...")
22 |
23 | ADD_LIBRARY (${PROJECT_NAME} STATIC ${SOURCES} )
24 | TARGET_LINK_LIBRARIES(${PROJECT_NAME} "libuv.a" -pthread)
25 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/DnsGet.md:
--------------------------------------------------------------------------------
1 | # DnsGet
2 | DNS查询接口
3 |
4 | ```C++
5 | DNSGet(uv::EventLoop* loop)
6 | ```
7 | 构造函数
8 | * EventLoop* loop : EventLoop对象句柄。
9 |
10 | ```C++
11 | void setOnDNSCallback(OnGetIPAddrCallback callback)
12 | ```
13 |
设置获取DNS回调函数
14 | OnGetIPAddrCallback 函数原型: void (int statue, std::string& ip)
15 |
int status : 状态码,获取成功则为0。
16 |
std::string& ip : 返回域名ip地址
17 |
18 |
19 | ```C++
20 | int GetIP(std::string& hostname, std::string service = "")
21 | ```
22 |
23 | 获取ip地址。
24 | * std::string& hostname : 域名, "www.google.com"
25 | * std::string service : 服务命, "http"、"ftp"、"80"……
26 | * 返回值 : 成功则为0。
27 |
28 | ```C++
29 | int GetIP(std::string&& hostname, std::string service = "");
30 | ```
31 | 同上。
32 |
33 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/GlobalConfig.md:
--------------------------------------------------------------------------------
1 | # GlobalConfig
2 | Global variable and setting.
3 | ```C++
4 | static BufferMode BufferModeStatus
5 | ```
6 | Data cache mode used,NoBuffer、CycleBuffer、ListBuffer.The default is NoBuffer.
7 |
8 | ```C++
9 | static uint64_t CycleBufferSize
10 | ```
11 | Cycle buffer size,The default is 32KB.
12 |
13 | ```C++
14 | static ReadBufferPacketFunc ReadBufferPacket
15 | ```
16 | Packet data parsing and reading function,The default is Packet::readFromBuffer.
17 |
18 | ```C++
19 | static ReadBufferStringFunc ReadBufferString
20 | ```
21 | String data packet parsing and reading function,The default is Null.
22 |
23 | ```C++
24 | static ReadBufferVoidFunc ReadBufferVoid
25 | ```
26 | Customized data packet parsing and reading function,The default is Null.
27 |
--------------------------------------------------------------------------------
/src/orca/base/thread/ThreadPool.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_THREAD_POOL_H
2 | #define ORCA_THREAD_POOL_H
3 |
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | #include "Thread.h"
10 | namespace orca
11 | {
12 |
13 | namespace base
14 | {
15 |
16 | class ThreadPool
17 | {
18 | public:
19 | using ProcessorType = std::function;
20 | ThreadPool();
21 | virtual ~ThreadPool();
22 | using ThreadPtr = std::shared_ptr;
23 |
24 | void registerPorcess(ProcessorType process);
25 |
26 | void start(unsigned int cnt);
27 | void join();
28 | private:
29 | ProcessorType processor_;
30 | std::vector threads_;
31 |
32 |
33 | void run();
34 | };
35 |
36 | }
37 | }
38 | #endif // ! ORCA_THREAD_POOL
39 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/Udp.md:
--------------------------------------------------------------------------------
1 | # Udp
2 | Udp类。
3 |
4 | ```C++
5 | Udp(EventLoop* loop)
6 | ```
7 | 构造函数。
8 | * EventLoop* loop : Event loop句柄。
9 |
10 | ```C++
11 | virtual ~Udp()
12 | ```
13 | 析构函数。
14 |
15 | ```C++
16 | int bindAndRead(SocketAddr& addr)
17 | ```
18 | 绑定地址并开始读数据。
19 | * SocketAddr& addr : 绑定地址。
20 | * 返回值 : 0为成功。
21 |
22 | ```C++
23 | int send(SocketAddr& to, const char* buf, unsigned size)
24 | ```
25 | 发送数据。
26 | * SocketAddr& to : 发送地址。
27 | * const char* buf : 发送数据缓存。
28 | * unsigned size : 发送数据长度。
29 | * 返回值 : 0 为成功。
30 |
31 | ```C++
32 | void close(DefaultCallback callback)
33 | ```
34 | 关闭Udp。
35 | * DefaultCallback callback : 关闭完成回调函数。
36 |
37 | ```C++
38 | void setMessageCallback(OnUdpMessageCallback callback)
39 | ```
40 | 设置消息回调函数。
41 | * OnUdpMessageCallback callback : 新消息回调函数。
--------------------------------------------------------------------------------
/uv-cpp/examples/dns/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 |
5 | void onGetIp(int status, std::string& ip)
6 | {
7 | if (status < 0)
8 | {
9 | uv::LogWriter::Instance()->error(uv::EventLoop::GetErrorMessage(status));
10 | return;
11 | }
12 | std::cout << ip << std::endl;
13 | }
14 |
15 | int main(int argc, char** args)
16 | {
17 | uv::EventLoop* loop = new uv::EventLoop();
18 |
19 | uv::DNSGet dnsGet(loop);
20 |
21 | dnsGet.setOnDNSCallback(std::bind(&onGetIp, std::placeholders::_1, std::placeholders::_2));
22 |
23 | int rst = dnsGet.GetIP("www.github.com");
24 |
25 | if (rst != 0)
26 | {
27 | uv::LogWriter::Instance()->error(uv::EventLoop::GetErrorMessage(rst));
28 | }
29 | loop->run();
30 | delete loop;
31 | }
32 |
--------------------------------------------------------------------------------
/uv-cpp/examples/rpc/RpcCtrl.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2019-9-20
7 |
8 | Description: https://github.com/wlgq2/uv-cpp
9 | */
10 |
11 |
12 | #ifndef RPC_CTRL_H
13 | #define RPC_CTRL_H
14 |
15 |
16 | #include
17 | #include
18 | #include
19 |
20 | #include "RpcClient.h"
21 |
22 |
23 |
24 | class RpcCtrl
25 | {
26 | public:
27 | RpcCtrl(uv::SocketAddr& addr);
28 | virtual ~RpcCtrl();
29 |
30 | void sum(Req& req,Resp& resp);
31 | void onResp(Resp& resp);
32 |
33 | private:
34 | void backRun();
35 |
36 | private:
37 | RpcClient* client_;
38 | uv::SocketAddr addr_;
39 | Resp resp_;
40 | std::mutex mutex_;
41 | std::condition_variable condition_;
42 | bool ready_;
43 | };
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/uv-cpp/uv/GlobalConfig.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2019-10-25
7 |
8 | Description: https://github.com/wlgq2/uv-cpp
9 | */
10 |
11 | #include
12 |
13 | #include "include/GlobalConfig.h"
14 | #include "include/Packet.h"
15 |
16 | using namespace uv;
17 | using namespace std;
18 | //默认不使用buffer
19 | GlobalConfig::BufferMode GlobalConfig::BufferModeStatus = GlobalConfig::BufferMode::NoBuffer;
20 |
21 | //默认循环buffer容量32Kb。
22 | uint64_t GlobalConfig::CycleBufferSize = 1024 << 5;
23 |
24 | //默认包解析函数
25 | ReadBufferStringFunc GlobalConfig::ReadBufferString = nullptr;
26 | ReadBufferPacketFunc GlobalConfig::ReadBufferPacket = std::bind(&Packet::readFromBuffer, placeholders::_1, placeholders::_2);;
27 | ReadBufferVoidFunc GlobalConfig::ReadBufferVoid = nullptr;
28 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/Signal.md:
--------------------------------------------------------------------------------
1 | # Signal
2 | libuv signal.
3 |
4 | ```C++
5 | Signal(EventLoop* loop,int sig, SignalHandle handle = nullptr);
6 | ```
7 | Constructor.
8 | * EventLoop* loop : event loop's handle.
9 | * int sig : signal value.
10 | * SignalHandle handle : the signal callback,called when received.
11 |
12 |
13 | ```C++
14 | virtual ~Signal();
15 | ```
16 | Destructor.
17 |
18 |
19 | ```C++
20 | void close(DefaultCallback callback);
21 | ```
22 | Close signal event.
23 | * DefaultCallback callback : callback called after close completion.
24 |
25 |
26 |
27 | ```C++
28 | void setHandle(SignalHandle handle);
29 | ```
30 | Set singal callback.
31 | * SignalHandle handle :the signal callback.
32 |
33 |
34 | ```C++
35 | static void Ignore(int sig);
36 | ```
37 | Ignore a signal, only valid in Linux.
38 | * int sig : signal value.
39 |
40 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/EventLoop.md:
--------------------------------------------------------------------------------
1 | # EventLoop
2 | 事件轮询类,单线程。
3 |
4 | ```C++
5 | EventLoop()
6 | ```
7 | 构造函数
8 |
9 | ```C++
10 | ~EventLoop()
11 | ```
12 | 析构函数
13 |
14 | ```C++
15 | static EventLoop* DefaultLoop()
16 | ```
17 | 获取单例Loop
18 |
19 | ```C++
20 | int run()
21 | ```
22 | 阻塞运行loop
23 |
24 | ```C++
25 | int runNoWait()
26 | ```
27 | 非阻塞运行loop
28 |
29 | ```C++
30 | bool isRunInLoopThread()
31 | ```
32 | 判定当前是否在loop线程中
33 | * 返回 true:当前为loop线程 false: 当前不为loop线程
34 |
35 | ```C++
36 | void runInThisLoop(const DefaultCallback func)
37 | ```
38 | 注册回调函数到loop线程中执行,确保每次注册的函数都能被执行。
39 | * const DefaultCallback func 回调函数
40 |
41 | ```C++
42 | uv_loop_t* handle()
43 | ```
44 | 返回libuv的loop句柄
45 |
46 | ```C++
47 | static const char* GetErrorMessage(int status)
48 | ```
49 |
获取错误信息
50 | * int status 错误码
51 |
52 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/DnsGet.md:
--------------------------------------------------------------------------------
1 | # DnsGet
2 | DNS utility.
3 |
4 | ```C++
5 | DNSGet(uv::EventLoop* loop)
6 | ```
7 | Constructor.
8 | * EventLoop* loop : EventLoop's handle.
9 |
10 | ```C++
11 | void setOnDNSCallback(OnGetIPAddrCallback callback)
12 | ```
13 |
Set DNS callback function.
14 | OnGetIPAddrCallback function format : void (int statue, std::string& ip)
15 |
int status : will 0 while successed.
16 | std::string& ip : hostname's ip address
17 |
18 |
19 | ```C++
20 | int GetIP(std::string& hostname, std::string service = "")
21 | ```
22 | Get hostname's ip address.
23 | * std::string& hostname : hostname, like "www.google.com"
24 | * std::string service : service, like "http"、"ftp"、"80"……
25 | * return : return 0 while successed.
26 |
27 | ```C++
28 | int GetIP(std::string&& hostname, std::string service = "");
29 | ```
30 | The same.
31 |
32 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/TimerWheel.md:
--------------------------------------------------------------------------------
1 | # TimerWheel template
2 | Time wheel.
3 |
4 | ```C++
5 | TimerWheel(EventLoop* loop)
6 | ```
7 | Constructor.
8 | * EventLoop* loop : Event loop's handle.
9 |
10 | ```C++
11 | TimerWheel(EventLoop* loop,unsigned int timeout)
12 | ```
13 | Constructor.
14 | * EventLoop* loop : Event loop's handle.
15 | * unsigned int timeout : Timeout of seconds.
16 |
17 | ```C++
18 | void setTimeout(unsigned int seconds)
19 | ```
20 | Set timeout of seconds.
21 | * unsigned int timeout : Timeout of seconds.
22 |
23 | ```C++
24 | int getTimeout()
25 | ```
26 | Get timeout of seconds.
27 | * Return : Timeout of seconds.
28 |
29 | ```C++
30 | void start()
31 | ```
32 | Start time wheel.
33 |
34 | ```C++
35 | void insert(std::shared_ptr value)
36 | ```
37 | Insert element of time wheel.
38 | * std::shared_ptr value : Elements of the time wheel.
--------------------------------------------------------------------------------
/uv-cpp/uv/Idle.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2019-9-10
7 |
8 | Description: uv-cpp
9 | */
10 |
11 | #include "include/Idle.h"
12 |
13 | using namespace uv;
14 |
15 | Idle::Idle(EventLoop* loop)
16 | :idle_(new uv_idle_t())
17 | {
18 | idle_->data = this;
19 | uv_idle_init(loop->handle(), idle_);
20 | uv_idle_start(idle_, idleCallback);
21 | }
22 |
23 | Idle::~Idle()
24 | {
25 | uv_idle_stop(idle_);
26 | delete idle_;
27 | }
28 |
29 | void Idle::onCallback()
30 | {
31 | if (callback_)
32 | callback_();
33 | }
34 |
35 | void Idle::setCallback(DefaultCallback callback)
36 | {
37 | callback_ = callback;
38 | }
39 |
40 | void Idle::idleCallback(uv_idle_t* handle)
41 | {
42 | Idle* ptr = static_cast(handle->data);
43 | ptr->onCallback();
44 | }
45 |
--------------------------------------------------------------------------------
/uv-cpp/doc/en/Timer.md:
--------------------------------------------------------------------------------
1 | # Timer
2 | uv timer.
3 |
4 | ```C++
5 | Timer(EventLoop* loop, uint64_t timeout, uint64_t repeat, TimerCallback callback)
6 | ```
7 | Constructor.
8 | * EventLoop* loop : Event loop's handle.
9 | * int64_t timeout : The first timeout of milliseconds.
10 | * uint64_t repeat : Timer timeout period, do't repeat if it is zero.
11 | * TimerCallback callback : Timer callback function.
12 |
13 | ```C++
14 | virtual ~Timer()
15 | ```
16 | Destructor.
17 |
18 | ```C++
19 | void start()
20 | ```
21 | Strat timer.
22 |
23 | ```C++
24 | void close(TimerCloseComplete callback)
25 | ```
26 | Close timer.
27 | * TimerCloseComplete callback : Callback function after close completion, timer object can be safely destroyed in callback.
28 | * TimerCloseComplete : void(Timer*)。
29 |
30 | ```C++
31 | void setTimerRepeat(uint64_t ms)
32 | ```
33 | Modify the timer period.
34 | * uint64_t ms : Timer timeout period of milliseconds.
--------------------------------------------------------------------------------
/src/orca/base/thread/ThreadPool.cpp:
--------------------------------------------------------------------------------
1 | #include "ThreadPool.h"
2 |
3 | using namespace std;
4 | using namespace orca::base;
5 |
6 |
7 | ThreadPool::ThreadPool()
8 | {
9 | }
10 |
11 | ThreadPool::~ThreadPool()
12 | {
13 | threads_.clear();
14 | }
15 |
16 |
17 | void ThreadPool::run()
18 | {
19 | while (true)
20 | {
21 | processor_();
22 | }
23 | }
24 |
25 |
26 | void ThreadPool::start(unsigned int cnt)
27 | {
28 | for (unsigned int i = 0; i < cnt; i++)
29 | {
30 | ThreadPtr ptr = std::make_shared(std::bind(&ThreadPool::run, this));
31 | threads_.push_back(ptr);
32 | ptr->start();
33 | }
34 | }
35 |
36 | void orca::base::ThreadPool::join()
37 | {
38 | for (auto thread : threads_)
39 | {
40 | thread->join();
41 | }
42 | }
43 |
44 | void ThreadPool::registerPorcess(ProcessorType process)
45 | {
46 | processor_ = process;
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/uv-cpp/examples/pingpang/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | #include "EchoServer.h"
5 | #include "Clinet.h"
6 |
7 |
8 | using namespace uv;
9 |
10 |
11 |
12 | int main(int argc, char** args)
13 | {
14 | //定义事件分发器类
15 | EventLoop* loop = EventLoop::DefaultLoop();
16 |
17 | uv::GlobalConfig::BufferModeStatus = uv::GlobalConfig::CycleBuffer;
18 | SocketAddr addr1("0.0.0.0", 10002, SocketAddr::Ipv4);
19 |
20 |
21 | EchoServer server(loop);
22 | server.setTimeout(60);
23 | server.bindAndListen(addr1);
24 |
25 | SocketAddr addr2("127.0.0.1", 10002);
26 |
27 | Client client(loop);
28 | client.connectToServer(addr2);
29 |
30 |
31 | Timer timer(loop, 1000, 1000,
32 | [&server](Timer*)
33 | {
34 | std::cout << "cnt:"<run();
41 | delete loop;
42 | }
43 |
--------------------------------------------------------------------------------
/src/orca/base/error/ErrorInfo.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_BASE_ERROR_INFO_H
2 | #define ORCA_BASE_ERROR_INFO_H
3 |
4 | #include
5 |
6 | namespace orca
7 | {
8 | namespace base
9 | {
10 | class ErrorInfo
11 | {
12 | public:
13 | enum ErrorId
14 | {
15 | UVWriteFail = -2048,
16 | UVConnectFail,
17 | UVDisconnectFromServer,
18 | UVSigPipe,
19 |
20 | UndefinedError = -1024,
21 | NoFindActorName,
22 | ActorNameTooLong,
23 | NoFindActorAddr,
24 | ReDefineActorName,
25 | MessagePackNull,
26 | PackMessageError,
27 | NoFindRemoteFramework,
28 |
29 | RepeatedRemoteFrameworkID,
30 | };
31 | ErrorInfo(ErrorId id,std::string info);
32 |
33 | ErrorId getErrorId();
34 | std::string& getErrorInfo();
35 |
36 | private:
37 | ErrorId id_;
38 | std::string info_;
39 | };
40 | }
41 | }
42 | #endif // ! ORCA_BASE_ERROR_INFO_H
43 |
44 |
--------------------------------------------------------------------------------
/uv-cpp/uv/include/Async.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2019-2-21
7 |
8 | Description: https://github.com/wlgq2/uv-cpp
9 | */
10 |
11 | #ifndef UV_ASYNC_H
12 | #define UV_ASYNC_H
13 |
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #include "EventLoop.h"
20 |
21 |
22 | namespace uv
23 | {
24 |
25 | class Async : public std::enable_shared_from_this
26 | {
27 | public:
28 |
29 |
30 | Async(EventLoop* loop);
31 | virtual ~Async();
32 |
33 | void runInThisLoop(DefaultCallback callback);
34 |
35 |
36 | void close(DefaultCallback callback);
37 | private:
38 | std::mutex mutex_;
39 | uv_async_t* handle_;
40 | std::queue callbacks_;
41 |
42 | void process();
43 | static void Callback(uv_async_t* handle);
44 |
45 | };
46 |
47 |
48 | using AsyncPtr = std::shared_ptr;
49 |
50 | }
51 | #endif
52 |
--------------------------------------------------------------------------------
/uv-cpp/doc/cn/TcpAccepter.md:
--------------------------------------------------------------------------------
1 | # TcpAccepter
2 | Tcp监听类,监听接收tcp连接。
3 |
4 | ```C++
5 | TcpAccepter(EventLoop* loop, bool tcpNoDelay)
6 | ```
7 | 构造函数。
8 | * EventLoop* loop : Event loop句柄。
9 | * bool tcpNoDelay : Nagle 算法, true : 不延迟 false : 延迟。
10 |
11 | ```C++
12 | virtual ~TcpAccepter()
13 | ```
14 | 析构函数。
15 |
16 | ```C++
17 | int bind(SocketAddr& addr)
18 | ```
19 | 绑定ip地址及端口。
20 | * SocketAddr& addr : ip及端口信息。
21 | * 返回值 : 0为成功。
22 |
23 | ```C++
24 | int listen()
25 | ```
26 | 监听地址及端口。
27 | * 返回值 : 0为成功。
28 |
29 | ```C++
30 | bool isListen()
31 | ```
32 | 是否监听状态。
33 | * 返回值 : 是否在监听状态。
34 |
35 | ```C++
36 | bool isTcpNoDelay()
37 | ```
38 | 是否开启no_delay.
39 | * 返回值 : 开启不延时。
40 |
41 | ```C++
42 | EventLoop* Loop()
43 | ```
44 | 返回Event loop句柄。
45 | * 返回值 : EventLoop句柄。
46 |
47 | ```C++
48 | void setNewConnectinonCallback( NewConnectionCallback callback)
49 | ```
50 | 设置新连接回调函数。
51 | * NewConnectionCallback callback : 新连接回调函数。
52 | * NewConnectionCallback : void(EventLoop* ,UVTcpPtr)。
--------------------------------------------------------------------------------
/uv-cpp/examples/rpc/RpcServer.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright © 2017-2019, orcaer@yeah.net All rights reserved.
3 |
4 | Author: orcaer@yeah.net
5 |
6 | Last modified: 2019-10-20
7 |
8 | Description: https://github.com/wlgq2/uv-cpp
9 | */
10 |
11 | #include "RpcServer.h"
12 |
13 | using namespace uv;
14 | using namespace std;
15 |
16 | RpcServer::RpcServer(EventLoop* loop)
17 | :TcpServer(loop)
18 | {
19 | setMessageCallback(std::bind(&RpcServer::onMessage,this,placeholders::_1,placeholders::_2,placeholders::_3));
20 | }
21 |
22 | RpcServer::~RpcServer()
23 | {
24 |
25 | }
26 |
27 | void RpcServer::onMessage(uv::TcpConnectionPtr connection,const char* buf,ssize_t size)
28 | {
29 | Req req;
30 | if (0 == req.unpack(buf, (int)size))
31 | {
32 | Resp resp;
33 | sum(req, resp);
34 | sendProtocol(connection, resp);
35 | }
36 | }
37 |
38 | void RpcServer::sum(Req& req, Resp& resp)
39 | {
40 | resp.param = 0;
41 | for (auto param : req.params)
42 | {
43 | resp.param += param;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/examples/messageTypeRegister/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "MessageType.h"
3 |
4 | class ActorTest :public orca::Actor
5 | {
6 | public:
7 | ActorTest(orca::Framework* framework,std::string name = "")
8 | :Actor(framework, name)
9 | {
10 | registerHandler(std::bind(&ActorTest::handle,this,std::placeholders::_1,std::placeholders::_2));
11 | }
12 | void handle(orca::MessagePack& pack, orca::Address& from)
13 | {
14 | std::cout << (char*)(pack.enter()) << std::endl;
15 | }
16 | };
17 |
18 | int main(int argc, char** args)
19 | {
20 | //actor framework.
21 | orca::Framework framework;
22 | //arctor object.
23 | ActorTest actor1(&framework);
24 | ActorTest actor2(&framework);
25 | //message pack.
26 | char data[] = "a message of my customize type";
27 | orca::MessagePack message;
28 | message.create(data,(int)sizeof(data));
29 |
30 | //actor1->actor2 send message.
31 | actor1.send(message,actor2.getAddress());
32 | framework.loop();
33 |
34 | }
--------------------------------------------------------------------------------
/src/orca/core/net/ActorServer.h:
--------------------------------------------------------------------------------
1 | #ifndef ORCA_ACTOR_SERVER_H
2 | #define ORCA_ACTOR_SERVER_H
3 |
4 | #include