Skip to content

Commit eb4a961

Browse files
committed
不需要子分派器的设计。
1 parent 5426e70 commit eb4a961

13 files changed

+22
-129
lines changed

kbe/src/lib/network/bundle_broadcast.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ BundleBroadcast::BundleBroadcast(NetworkInterface & networkInterface,
5151
ERROR_MSG(fmt::format("BundleBroadcast::BundleBroadcast: init socket is error, {}\n",
5252
kbe_strerror()));
5353

54-
networkInterface_.mainDispatcher().breakProcessing();
54+
networkInterface_.dispatcher().breakProcessing();
5555
}
5656
else
5757
{
@@ -122,7 +122,7 @@ bool BundleBroadcast::broadcast(uint16 port)
122122
ERROR_MSG(fmt::format("BundleBroadcast::broadcast: Couldn't broadcast socket, port {}, {}\n",
123123
port, kbe_strerror()));
124124

125-
networkInterface_.mainDispatcher().breakProcessing();
125+
networkInterface_.dispatcher().breakProcessing();
126126
return false;
127127
}
128128

kbe/src/lib/network/channel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ bool Channel::waitSend()
629629
//-------------------------------------------------------------------------------------
630630
EventDispatcher & Channel::dispatcher()
631631
{
632-
return pNetworkInterface_->mainDispatcher();
632+
return pNetworkInterface_->dispatcher();
633633
}
634634

635635
//-------------------------------------------------------------------------------------

kbe/src/lib/network/event_dispatcher.cpp

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ EventDispatcher::EventDispatcher() :
4141
lastStatisticsGathered_(0),
4242
pFrequentTasks_(new Tasks),
4343
pErrorReporter_(NULL),
44-
pTimers_(new Timers64),
45-
pCouplingToParent_(NULL)
44+
pTimers_(new Timers64)
4645

4746
{
4847
pPoller_ = EventPoller::create();
@@ -73,53 +72,6 @@ EventPoller* EventDispatcher::createPoller()
7372
return pPoller_;
7473
}
7574

76-
//-------------------------------------------------------------------------------------
77-
void EventDispatcher::attach(EventDispatcher & childDispatcher)
78-
{
79-
childDispatcher.attachTo(*this);
80-
childDispatchers_.push_back(&childDispatcher);
81-
}
82-
83-
//-------------------------------------------------------------------------------------
84-
void EventDispatcher::attachTo(EventDispatcher & parentDispatcher)
85-
{
86-
KBE_ASSERT(pCouplingToParent_ == NULL);
87-
pCouplingToParent_ = new DispatcherCoupling(parentDispatcher, *this);
88-
89-
int fd = pPoller_->getFileDescriptor();
90-
91-
if (fd != -1)
92-
{
93-
parentDispatcher.registerFileDescriptor(fd, pPoller_);
94-
parentDispatcher.registerWriteFileDescriptor(fd, pPoller_);
95-
}
96-
}
97-
98-
//-------------------------------------------------------------------------------------
99-
void EventDispatcher::detach(EventDispatcher & childDispatcher)
100-
{
101-
childDispatcher.detachFrom(*this);
102-
103-
ChildDispatchers & d = childDispatchers_;
104-
d.erase(std::remove(d.begin(), d.end(), &childDispatcher), d.end());
105-
}
106-
107-
//-------------------------------------------------------------------------------------
108-
void EventDispatcher::detachFrom(EventDispatcher & parentDispatcher)
109-
{
110-
int fd = pPoller_->getFileDescriptor();
111-
112-
if (fd != -1)
113-
{
114-
parentDispatcher.deregisterFileDescriptor(fd);
115-
parentDispatcher.deregisterWriteFileDescriptor(fd);
116-
}
117-
118-
KBE_ASSERT(pCouplingToParent_ != NULL);
119-
delete pCouplingToParent_;
120-
pCouplingToParent_ = NULL;
121-
}
122-
12375
//-------------------------------------------------------------------------------------
12476
bool EventDispatcher::registerFileDescriptor(int fd,
12577
InputNotificationHandler * handler)

kbe/src/lib/network/event_dispatcher.hpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ class EventDispatcher
5858
INLINE void setWaitBreakProcessing();
5959
bool processingBroken()const;
6060

61-
void attach(EventDispatcher & childDispatcher);
62-
void detach(EventDispatcher & childDispatcher);
63-
6461
void addFrequentTask(Task * pTask);
6562
bool cancelFrequentTask(Task * pTask);
6663

@@ -125,37 +122,9 @@ class EventDispatcher
125122
ErrorReporter * pErrorReporter_;
126123
Timers64* pTimers_;
127124
EventPoller* pPoller_;
128-
DispatcherCoupling * pCouplingToParent_;
129125
};
130126

131127

132-
class DispatcherCoupling : public Task
133-
{
134-
public:
135-
DispatcherCoupling(EventDispatcher & mainDispatcher,
136-
EventDispatcher & childDispatcher) :
137-
mainDispatcher_(mainDispatcher),
138-
childDispatcher_(childDispatcher)
139-
{
140-
mainDispatcher.addFrequentTask(this);
141-
}
142-
143-
~DispatcherCoupling()
144-
{
145-
mainDispatcher_.cancelFrequentTask(this);
146-
}
147-
148-
private:
149-
bool process()
150-
{
151-
childDispatcher_.processOnce();
152-
return true;
153-
}
154-
155-
EventDispatcher & mainDispatcher_;
156-
EventDispatcher & childDispatcher_;
157-
};
158-
159128
}
160129
}
161130

kbe/src/lib/network/network_interface.cpp

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace KBEngine {
3838
namespace Mercury
3939
{
4040
const int NetworkInterface::RECV_BUFFER_SIZE = 16 * 1024 * 1024; // 16MB
41-
const char * NetworkInterface::USE_KBEMACHINED = "kbemachined";
41+
const char * NetworkInterface::USE_KBEMACHINED = "kbemachine";
4242

4343
//-------------------------------------------------------------------------------------
4444
NetworkInterface::NetworkInterface(Mercury::EventDispatcher * pMainDispatcher,
@@ -49,8 +49,7 @@ NetworkInterface::NetworkInterface(Mercury::EventDispatcher * pMainDispatcher,
4949
extEndpoint_(),
5050
intEndpoint_(),
5151
channelMap_(),
52-
pDispatcher_(new EventDispatcher),
53-
pMainDispatcher_(NULL),
52+
pDispatcher_(pMainDispatcher),
5453
pExtensionData_(NULL),
5554
pExtListenerReceiver_(NULL),
5655
pIntListenerReceiver_(NULL),
@@ -85,10 +84,7 @@ NetworkInterface::NetworkInterface(Mercury::EventDispatcher * pMainDispatcher,
8584
KBE_ASSERT(good() && "NetworkInterface::NetworkInterface: no available port, "
8685
"please check for kbengine_defs.xml!\n");
8786

88-
if (pMainDispatcher != NULL)
89-
{
90-
this->attach(*pMainDispatcher);
91-
}
87+
pDelayedChannels_->init(this->dispatcher(), this);
9288
}
9389

9490
//-------------------------------------------------------------------------------------
@@ -112,36 +108,19 @@ NetworkInterface::~NetworkInterface()
112108
}
113109
}
114110

115-
this->detach();
116111
this->closeSocket();
117112

118-
SAFE_RELEASE(pDispatcher_);
113+
if (pDispatcher_ != NULL)
114+
{
115+
pDelayedChannels_->fini(this->dispatcher());
116+
pDispatcher_ = NULL;
117+
}
118+
119119
SAFE_RELEASE(pDelayedChannels_);
120120
SAFE_RELEASE(pExtListenerReceiver_);
121121
SAFE_RELEASE(pIntListenerReceiver_);
122122
}
123123

124-
//-------------------------------------------------------------------------------------
125-
void NetworkInterface::attach(EventDispatcher & mainDispatcher)
126-
{
127-
KBE_ASSERT(pMainDispatcher_ == NULL);
128-
pMainDispatcher_ = &mainDispatcher;
129-
mainDispatcher.attach(this->dispatcher());
130-
131-
pDelayedChannels_->init(this->mainDispatcher(), this);
132-
}
133-
134-
//-------------------------------------------------------------------------------------
135-
void NetworkInterface::detach()
136-
{
137-
if (pMainDispatcher_ != NULL)
138-
{
139-
pDelayedChannels_->fini(this->mainDispatcher());
140-
pMainDispatcher_->detach(this->dispatcher());
141-
pMainDispatcher_ = NULL;
142-
}
143-
}
144-
145124
//-------------------------------------------------------------------------------------
146125
void NetworkInterface::closeSocket()
147126
{

kbe/src/lib/network/network_interface.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ class NetworkInterface : public TimerHandler
5656
uint32 intrbuffer = 0, uint32 intwbuffer = 0);
5757

5858
~NetworkInterface();
59-
60-
void attach(EventDispatcher & mainDispatcher);
61-
void detach();
6259

6360
INLINE const Address & extaddr() const;
6461
INLINE const Address & intaddr() const;
@@ -83,8 +80,7 @@ class NetworkInterface : public TimerHandler
8380
void pChannelDeregisterHandler(ChannelDeregisterHandler * pHandler)
8481
{ pChannelDeregisterHandler_ = pHandler; }
8582

86-
EventDispatcher & dispatcher() { return *pDispatcher_; }
87-
EventDispatcher & mainDispatcher() { return *pMainDispatcher_; }
83+
EventDispatcher & dispatcher() { return *pDispatcher_; }
8884

8985
/* 外部网点和内部网点 */
9086
EndPoint & extEndpoint() { return extEndpoint_; }
@@ -136,7 +132,6 @@ class NetworkInterface : public TimerHandler
136132
ChannelMap channelMap_;
137133

138134
EventDispatcher * pDispatcher_;
139-
EventDispatcher * pMainDispatcher_;
140135

141136
void * pExtensionData_;
142137

kbe/src/lib/server/componentbridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Componentbridge::~Componentbridge()
111111
//-------------------------------------------------------------------------------------
112112
Mercury::EventDispatcher & Componentbridge::dispatcher()
113113
{
114-
return networkInterface_.mainDispatcher();
114+
return networkInterface_.dispatcher();
115115
}
116116

117117
//-------------------------------------------------------------------------------------

kbe/src/lib/server/serverapp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ void ServerApp::onShutdownBegin()
106106
#endif
107107

108108
mainDispatcher_.setWaitBreakProcessing();
109-
networkInterface_.dispatcher().setWaitBreakProcessing();
110109
}
111110

112111
//-------------------------------------------------------------------------------------
@@ -118,7 +117,6 @@ void ServerApp::onShutdown(bool first)
118117
void ServerApp::onShutdownEnd()
119118
{
120119
mainDispatcher_.breakProcessing();
121-
networkInterface_.dispatcher().breakProcessing();
122120
}
123121

124122
//-------------------------------------------------------------------------------------

kbe/src/server/baseapp/base_messages_forward_handler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pBase_(pBase),
3232
completed_(false),
3333
startForward_(false)
3434
{
35-
Baseapp::getSingleton().networkInterface().mainDispatcher().addFrequentTask(this);
35+
Baseapp::getSingleton().networkInterface().dispatcher().addFrequentTask(this);
3636
}
3737

3838
//-------------------------------------------------------------------------------------
@@ -42,7 +42,7 @@ BaseMessagesForwardHandler::~BaseMessagesForwardHandler()
4242
bufferedSendToCellappMessages_.size()));
4343

4444
if(!completed_)
45-
Baseapp::getSingleton().networkInterface().mainDispatcher().cancelFrequentTask(this);
45+
Baseapp::getSingleton().networkInterface().dispatcher().cancelFrequentTask(this);
4646

4747
std::vector<Mercury::Bundle*>::iterator iter = bufferedSendToCellappMessages_.begin();
4848
for(; iter != bufferedSendToCellappMessages_.end(); iter++)

kbe/src/server/baseapp/initprogress_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ InitProgressHandler::InitProgressHandler(Mercury::NetworkInterface & networkInte
3636
Task(),
3737
networkInterface_(networkInterface)
3838
{
39-
networkInterface.mainDispatcher().addFrequentTask(this);
39+
networkInterface.dispatcher().addFrequentTask(this);
4040
}
4141

4242
//-------------------------------------------------------------------------------------

kbe/src/server/baseapp/restore_entity_handler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ canRestore_(false)
5151
RestoreEntityHandler::~RestoreEntityHandler()
5252
{
5353
if(inProcess_)
54-
networkInterface_.mainDispatcher().cancelFrequentTask(this);
54+
networkInterface_.dispatcher().cancelFrequentTask(this);
5555

5656
std::vector<RestoreData>::iterator restoreSpacesIter = otherRestoredSpaces_.begin();
5757
for(; restoreSpacesIter != otherRestoredSpaces_.end(); restoreSpacesIter++)
@@ -98,7 +98,7 @@ void RestoreEntityHandler::pushEntity(ENTITY_ID id)
9898
if(!inProcess_)
9999
{
100100
inProcess_ = true;
101-
networkInterface_.mainDispatcher().addFrequentTask(this);
101+
networkInterface_.dispatcher().addFrequentTask(this);
102102
}
103103

104104
tickReport_ = timestamp();

kbe/src/server/baseapp/sync_entitystreamtemplate_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ SyncEntityStreamTemplateHandler::SyncEntityStreamTemplateHandler(Mercury::Networ
3636
Task(),
3737
networkInterface_(networkInterface)
3838
{
39-
networkInterface.mainDispatcher().addFrequentTask(this);
39+
networkInterface.dispatcher().addFrequentTask(this);
4040

4141
MemoryStream accountDefMemoryStream;
4242

kbe/src/server/dbmgr/sync_app_datas_handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ networkInterface_(networkInterface),
4444
lastRegAppTime_(0),
4545
apps_()
4646
{
47-
networkInterface.mainDispatcher().addFrequentTask(this);
47+
networkInterface.dispatcher().addFrequentTask(this);
4848
}
4949

5050
//-------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)