添加监听失败处理

This commit is contained in:
aozhiwei 2019-08-31 14:24:49 +08:00
parent 82bbd8bdbb
commit 4120ac569f
3 changed files with 25 additions and 4 deletions

View File

@ -5,6 +5,7 @@
#include <a8/tcplistener.h> #include <a8/tcplistener.h>
#include "framework/cpp/netmsghandler.h" #include "framework/cpp/netmsghandler.h"
#include "framework/cpp/msgqueue.h"
#include "app.h" #include "app.h"
#include "GGListener.h" #include "GGListener.h"
@ -79,6 +80,10 @@ static void CreateGameClientSocket(a8::TcpSession **p)
static void GSListeneron_error(a8::TcpListener*, int type, int errorid) static void GSListeneron_error(a8::TcpListener*, int type, int errorid)
{ {
a8::UdpLog::Instance()->Debug("GGListeneron_error %d %d", {type, errorid}); a8::UdpLog::Instance()->Debug("GGListeneron_error %d %d", {type, errorid});
f8::MsgQueue::Instance()->PostMsg_r(IM_GGListenerError,
a8::XParams()
.SetParam1(errorid)
);
} }
void GGListener::Init() void GGListener::Init()
@ -90,6 +95,12 @@ void GGListener::Init()
tcp_listener_->bind_address = "0.0.0.0"; tcp_listener_->bind_address = "0.0.0.0";
tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("listen_port")->AsXValue(); tcp_listener_->bind_port = JsonDataMgr::Instance()->GetConf()->At("listen_port")->AsXValue();
tcp_listener_->Open(); tcp_listener_->Open();
f8::MsgQueue::Instance()->RegisterCallBack(IM_GGListenerError,
[] (const a8::XParams& param)
{
GGListener::Instance()->OnListenError(param.param1);
});
} }
void GGListener::UnInit() void GGListener::UnInit()
@ -145,3 +156,9 @@ long long GGListener::GetSentBytesNum()
{ {
return tcp_listener_->sent_bytes_num; return tcp_listener_->sent_bytes_num;
} }
void GGListener::OnListenError(int errorid)
{
a8::XPrintf("GGListeneron_error %d %d", {type, errorid});
App::Instance()->terminated = true;
}

View File

@ -8,14 +8,14 @@ namespace a8
class GGListener : public a8::Singleton<GGListener> class GGListener : public a8::Singleton<GGListener>
{ {
private: private:
GGListener() {}; GGListener() {};
friend class a8::Singleton<GGListener>; friend class a8::Singleton<GGListener>;
public: public:
enum { HID = HID_GGListener }; enum { HID = HID_GGListener };
public: public:
void Init(); void Init();
void UnInit(); void UnInit();
@ -44,6 +44,9 @@ class GGListener : public a8::Singleton<GGListener>
long long GetSentNodeNum(); long long GetSentNodeNum();
long long GetSentBytesNum(); long long GetSentBytesNum();
private: private:
void OnListenError(int errorid);
private:
a8::TcpListener *tcp_listener_ = nullptr; a8::TcpListener *tcp_listener_ = nullptr;
}; };

View File

@ -14,6 +14,7 @@ enum InnerMesssage_e
IM_BSConnDisconnect, IM_BSConnDisconnect,
IM_LoadConfig, IM_LoadConfig,
IM_HttpResponse, IM_HttpResponse,
IM_GGListenerError
}; };
//网络处理对象 //网络处理对象