2
3
4
5
22
23
39
40
41
42
43
44
45
48 const std::string& name ,
55
56
60
61
62
66
67
68
72
73
74
78
79
80
84
85
86
90
91
92
96
97
98
99 bool Connected()
const {
return m_State == State::Connected; }
102
103
104
105 void Send(
const std::string& buffer);
108
109
113
114
115
118 m_ConnectionCallback = cb;
122
123
124
127 m_MessageCallback = cb;
131
132
133
136 m_WriteCompleteCallback = cb;
140
141
142
149
150
151
154 m_CloseCallback = cb;
165
166
170
171
175
176
180
181
185
186
187
188
189 void SendInLoop(
const char* message, size_t len);
192
193
199
200
204
205
209
210
214
215
219
220
224
225
229
230
234
235
239
240
244
245
249
250
254
255
259
260
264
265
#define DELEGATE_ONE_PARAM(name, p0)
Use this macro to instance a Delegate Class. One Parameter Specific.
#define DELEGATE_TWO_PARAM(name, p0, p1)
Use this macro to instance a Delegate Class. Two Parameter Specific.
#define SPICES_PROFILE_ZONE
size_t size()
Get size of Agents.
bool empty()
Determine if this Delegate is empty;.
std::shared_ptr< scl::linked_unordered_map< uint64_t, Agent > > m_Agents
Map of Agent Function Pointer.
bool Bind(std::function< void(Args...)> func)
Bind Function pointer to delegate.
virtual ~Delegate_Basic()=default
Destructor Function.
Delegate_Basic()
Constructor Function.
void Broadcast(Args &&... args)
Execute all function pointer.
bool UnBind(std::function< void(Args...)> func)
UnBind Function pointer from delegate.
Basic Class of Delegate. Instance inherited from it and use delegate feature.
void Listen()
Listen accept socket.
std::shared_ptr< Channel > m_AcceptChannel
Acceptor Channel.
Socket m_AcceptSocket
Acceptor Socket.
void HandleRead() const
On Read Event Callback.
Acceptor(const Acceptor &)=delete
Copy Constructor Function.
bool IsListening() const
Determine if this is in listening. @reutrn Returns true if is in listening.
void SetConnectionCallback(const ConnectionCallback &cb)
Set ConnectionCallback.
Acceptor(const InetAddress &listenAddress, bool reusePort)
Constructor Function.
ConnectionCallback m_ConnectionCallback
ConnectionCallback.
bool m_IsListening
Boolean of whether is in listening.
virtual ~Acceptor()
Destructor Function.
Acceptor & operator=(const Acceptor &)=delete
Copy Assignment Operation.
Wrapper of Channel and Socket, As the entrance of comm.
Wrapper of readwrite buffer.
~Channel()=default
Destructor Function.
void Update()
Update this Channel state to Poller.
void SetErrorCallback(EventCallback cb)
Set Error Event Callback.
EventCallback m_ReadCallback
Read Event Callback.
bool IsReading() const
Determine whether the event is a Read Event.
EventLoop * m_Loop
This channel interested EventLoop.
void SetWriteCallback(EventCallback cb)
Set Write Event Callback.
Channel(const Channel &)=delete
Copy Constructor Function.
Channel(SOCKET fd, EventLoop *loop)
Constructor Function.
EventCallback m_WriteCallback
Write Event Callback.
void SetCloseCallback(EventCallback cb)
Set Close Event Callback.
void SetRevents(int revt)
Set this REvents type.
void DisableReading()
Disable Read event.
void DisableAll()
Disable All event.
Channel & operator=(const Channel &)=delete
Copy Assignment Operation.
std::optional< std::weak_ptr< void > > m_Tie
int Events() const
Get this Events type.
EventCallback m_ErrorCallback
Error Event Callback.
void HandleEvent() const
Handle happened events on fd.
void HandleEventsWithGuard() const
Internal handle happened events on fd.
void Tie(const std::shared_ptr< void > &obj)
void EnableWriting()
Enable Write event.
SOCKET Fd() const
Get this SOCKET.
void SetPollState(PollState state)
Set Poll State.
bool IsWriting() const
Determine whether the event is a Write Event.
void DisableWriting()
Disable Write event.
int m_Revents
Current happened event type.
void EnableReading()
Enable Read event.
PollState GetPollState() const
Get Poll State.
EventFlags m_Events
This SOCKET interested Events type.
SOCKET m_Fd
This channel interested SOCKET.
EventCallback m_CloseCallback
Close Event Callback.
void Remove()
Remove this Channel state from Poller.
PollState m_PollState
This channel PollState.
bool IsNoneEvent() const
Determine whether the event is a None Event.
void SetReadCallback(EventCallback cb)
Set Read Event Callback.
Wrapper of SOCKET'S Event.
ThreadPool of Multiple threading EventLoop.
EventLoopThreadWrapper()
Constructor Function.
virtual ~EventLoopThreadWrapper()
Destructor Function.
static EventLoop *& GetInst(InetAddress *address=nullptr)
Get EventLoop Instance. @reutrn Returns EventLoop Instance.
EventLoop * instance
This thread EventLoop instance.
Wrapper of Instance/Delete ThreadCache in thread.
EventLoop & operator=(const EventLoop &)=delete
Copy Assignment Operation.
void HandleWakeUp()
Handle WakeUp notify by read one byte data.
std::vector< Functor > m_PendingFunctors
Delay functors.
void DoPendingFunctors()
Execute all pending functors.
std::shared_ptr< Poller > m_Poller
Poller instance.
std::atomic_bool m_IsCallingPendingFunctors
True if is execute pending functors.
std::atomic_bool m_IsLooping
True if is in Looping.
bool HasChannel(Channel *channel) const
Determine if channel is inside poller.
std::mutex m_Mutex
Mutex for PendingFunctors.
EventLoop(const EventLoop &)=delete
Copy Constructor Function.
std::atomic_bool m_IsQuit
True if is quit from Looping.
EventLoop(InetAddress *address=nullptr)
Constructor Function.
void WakeUp()
WakeUp a thread, which wait on recv, by sending one byte data.
std::unique_ptr< Channel > m_WeakupChannel
Wakeup Channel.
void Loop()
Start Event Loop.
bool IsInLoopThread() const
Determine if current thread is in eventloop thread.
void RunInLoop(Functor cb)
Push functor to pending functors.
~EventLoop()
Destructor Function.
Socket m_WakeupFd
Wakeup Socket.
DWORD m_ThreadId
Thread's identify, which is running this EventLoop.
void QueueInLoop(Functor cb)
Execute functor in EventLoop thread.
void UpdateChannel(Channel *channel) const
Update channel state with poller.
void Quit()
Quit from Event Loop.
ChannelList m_ActiveChannels
Channels with events.
void RemoveChannel(Channel *channel) const
Remove channel from poller.
Wrapper of Poller and wakeup socket to acceptor(SubLoop).
const Version GetVersion() const
Get Http Version.
std::string GetHeader(const std::string &name) const
Get a Header from this HttpRequest.
HttpResponse(bool close)
Constructor Function.
void AppendToBuffer(Buffer *output)
Append this response to Buffer.
bool CloseConnection() const
Get CloseConnection.
HttpServer & operator=(const HttpServer &)=delete
Copy Assignment Operation.
HttpServer(const HttpServer &)=delete
Copy Constructor Function.
void OnRequest(const TcpConnectionPtr &connection, const HttpRequest &request)
HttpCallback m_HttpCallback
virtual ~HttpServer()=default
Destructor Function.
void OnConnection(const TcpConnectionPtr &connection)
HttpServer(const InetAddress &listenAddress, int idleSeconds, TcpServer::Option option=TcpServer::Option::NoReusePort)
Constructor Function.
void Start(int threadSize) const
Start ThreadPool and call listen on acceptor.
WeakConnectionList m_ConnectionList
void OnMessage(const TcpConnectionPtr &connection, Buffer *buf)
This class is Wrapper of current socket address.
Inherit from this and Implement Specific Poller.
Socket(const Socket &)=delete
Copy Constructor Function.
void SetReuseAddress(bool on) const
Set socket reuse address option.
void SetTcpNoDelay(bool on) const
Set socket Tcp no delay option.
void Connect(InetAddress *connectAddress) const
Connect to socket.
Socket & operator=(const Socket &)=delete
Copy Assignment Operation.
SOCKET m_SocketFd
This socket fd.
void Send(const std::string &data) const
Send data to server.
SOCKET Accept(InetAddress *peerAddress) const
Accept connection on socket.
Socket()=default
Constructor Function.
void BindAddress(const InetAddress &localAddress) const
Bind address to socket.
void Create()
Create Non Blocking Socket.
virtual ~Socket()
Destructor Function.
std::string Receive() const
Receive data from server.
SOCKET Fd()
Get this socket fd.
Socket(SOCKET socketFd)
Constructor Function.
const SOCKET Fd() const
Get this socket fd.
void SetKeepAlive(bool on) const
Set socket keep alive option.
void SetReusePort(bool on) const
Set socket reuse port option.
void ShutDownWrite() const
Disable writen in socket.
void Listen() const
Listen on socket.
This class is Wrapper of socket.
const InetAddress & LocalAddress() const
Get this TcpConnection LocalAddress.
void HandleWrite()
Handle Write event.
void SetWriteCompleteCallback(const DelegateWriteCompleteCallback &cb)
Set WriteCompleteCallback.
std::atomic< State > m_State
TcpConnection state.
DelegateHighWaterMarkCallback m_HighWaterMarkCallback
DelegateHighWaterMarkCallback.
std::unique_ptr< Socket > m_Socket
TcpConnection socket.
void SetMessageCallback(const DelegateMessageCallback &cb)
Set MessageCallback.
TcpConnection & operator=(const TcpConnection &)=delete
Copy Assignment Operation.
InetAddress m_PeerAddress
TcpConnection PeerAddress.
InetAddress m_LocalAddress
TcpConnection LocalAddress.
std::string m_Name
TcpConnection name.
void SetConnectionCallback(const DelegateConnectionCallback &cb)
Set ConnectionCallback.
void HandleClose()
Handle Close event.
void ConnectEstablished()
TcpConnection(EventLoop *ioLoop, const std::string &name, SOCKET socketFd, const InetAddress &localAddress, const InetAddress &peerAddress)
Constructor Function.
void HandleRead()
Handle Read event.
Buffer m_OutputBuffer
Output Buffer.
DelegateCloseCallback m_CloseCallback
DelegateCloseCallback.
Buffer m_InputBuffer
Input Buffer.
DelegateWriteCompleteCallback m_WriteCompleteCallback
DelegateWriteCompleteCallback.
DelegateMessageCallback m_MessageCallback
DelegateMessageCallback.
void SetCloseCallback(const DelegateCloseCallback &cb)
Set CloseCallback.
DelegateConnectionCallback m_ConnectionCallback
DelegateConnectionCallback.
void SetHighWaterMarkCallback(const DelegateHighWaterMarkCallback &cb)
Set HighWaterMarkCallback.
void HandleError() const
Handle Error event.
std::unique_ptr< Channel > m_Channel
TcpConnection channel.
void SendInLoop(const char *message, size_t len)
Send message to socket.
void SetState(State state)
void Send(const std::string &buffer)
Send message to socket.
const InetAddress & PeerAddress() const
Get this TcpConnection PeerAddress.
bool Connected() const
Determined if this TcpConnection is connected.
EventLoop * GetLoop() const
Get this TcpConnection IO EventLoop.
void ShutDown()
ShutDown socket.
EventLoop * m_IoLoop
io Loop from TcpServer::NewConnection.
TcpConnection(const TcpConnection &)=delete
Copy Constructor Function.
virtual ~TcpConnection()
Destructor Function.
void ShutDownInLoop() const
ShutDown socket.
const std::string & GetName() const
Get this TcpConnection name.
Combine of Socket Connection data.
void SetThreadInitCallback(const ThreadInitCallback &cb)
Set Thread initialize Call back.
void AddMessageCallback(const DelegateMessageCallback::Agent &cb)
Add Message Call back.
void Start(int threadSize) const
Start ThreadPool and call listen on acceptor.
std::shared_ptr< EventLoopThreadPool > m_ThreadPool
ThreadPool.
void NewConnection(SOCKET socketFd, const InetAddress &peerAddress)
Handle New Connection to Acceptor.
void RemoveConnectionInLoop(const TcpConnectionPtr &connection)
Remove a TcpConnection InLoop.
TcpServer(const TcpServer &)=delete
Copy Constructor Function.
ConnectionMap m_Connections
All TcpConnections.
DelegateWriteCompleteCallback m_WriteCompleteCallback
WriteCompleteCallback.
void RemoveConnection(const TcpConnectionPtr &connection)
Remove a TcpConnection.
TcpServer(const InetAddress &listenAddress, Option option=Option::NoReusePort)
Constructor Function.
TcpServer & operator=(const TcpServer &)=delete
Copy Assignment Operation.
ThreadInitCallback m_ThreadInitCallback
ThreadInitCallback.
std::unique_ptr< Acceptor > m_Acceptor
Acceptor.
std::string m_IpPort
TcpServer Ip and Port.
void AddConnectionCallback(const DelegateConnectionCallback::Agent &cb)
Add Connection Call back.
virtual ~TcpServer()
Destructor Function.
DelegateConnectionCallback m_ConnectionCallback
ConnectionCallback.
int m_NextConnectedId
Next Connection id.
DelegateMessageCallback m_MessageCallback
MessageCallback.
void AddWriteCompleteCallback(const DelegateWriteCompleteCallback::Agent &cb)
Add WriteComplete Call back.
The container combines hashmap and list together. Used in the case that we want iter a hashmap in ord...