SpiecsEngine
 
Loading...
Searching...
No Matches
Channel.cpp
Go to the documentation of this file.
1/**
2* @file Channel.cpp.
3* @brief The Channel Class Implementation.
4* @author Spices & Muduo.
5*/
6
7#include "Pchheader.h"
8#include "Channel.h"
9#include "EventLoop.h"
10
11namespace Spices {
12
13namespace Net {
14
15 Channel::Channel(SOCKET fd, EventLoop* loop)
16 : m_Fd(fd)
17 , m_Loop(loop)
19 , m_Revents(0)
21 {}
22
23 void Channel::HandleEvent() const
24 {
25 if (m_Tie.has_value())
26 {
27 if (m_Tie.value().lock())
28 {
30 }
31 }
32 else
33 {
35 }
36 }
37
38 void Channel::Tie(const std::shared_ptr<void>& obj)
39 {
40 m_Tie = obj;
41 }
42
44 {
46 }
47
49 {
51 }
52
54 {
55 // Close event.
56 if ((m_Revents & EPOLLHUP) && !(m_Revents & EPOLLIN))
57 {
58 if (m_CloseCallback)
59 {
60 m_CloseCallback();
61 }
62 }
63
64 // Error event.
65 if (m_Revents & EPOLLERR)
66 {
67 if (m_ErrorCallback)
68 {
69 m_ErrorCallback();
70 }
71 }
72
73 // Read event.
74 if (m_Revents & (EPOLLIN | EPOLLPRI))
75 {
76 if (m_ReadCallback)
77 {
78 m_ReadCallback();
79 }
80 }
81
82 // Write event.
83 if (m_Revents & EPOLLOUT)
84 {
85 if (m_WriteCallback)
86 {
87 m_WriteCallback();
88 }
89 }
90 }
91
92}
93
94}
void Update()
Update this Channel state to Poller.
Definition Channel.cpp:48
EventLoop * m_Loop
This channel interested EventLoop.
Definition Channel.h:237
Channel(SOCKET fd, EventLoop *loop)
Constructor Function.
Definition Channel.cpp:15
void HandleEvent() const
Handle happened events on fd.
Definition Channel.cpp:23
void HandleEventsWithGuard() const
Internal handle happened events on fd.
Definition Channel.cpp:53
void Tie(const std::shared_ptr< void > &obj)
Definition Channel.cpp:38
int m_Revents
Current happened event type.
Definition Channel.h:247
EventFlags m_Events
This SOCKET interested Events type.
Definition Channel.h:242
void Remove()
Remove this Channel state from Poller.
Definition Channel.cpp:43
PollState m_PollState
This channel PollState.
Definition Channel.h:252
Wrapper of SOCKET'S Event.
Definition Channel.h:27
void UpdateChannel(Channel *channel) const
Update channel state with poller.
void RemoveChannel(Channel *channel) const
Remove channel from poller.
Wrapper of Poller and wakeup socket to acceptor(SubLoop).
Definition EventLoop.h:28