relation/server/imserver/WSListener.h
aozhiwei 0c8a248450 1
2020-07-10 10:40:18 +08:00

61 lines
1.4 KiB
C++

#pragma once
#include "framework/cpp/netmsghandler.h"
#include "perfmonitor.h"
//gate listener
namespace a8
{
class TcpListener;
}
namespace ss
{
class SS_Ping;
}
class WSListener : public a8::Singleton<WSListener>
{
private:
WSListener() {};
friend class a8::Singleton<WSListener>;
public:
enum { HID = HID_WSListener };
public:
void Init();
void UnInit();
template <typename T>
void SendProxyMsg(int sockhandle, T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
f8::Net_SendProxyMsg(tcp_listener_, sockhandle, 0, 0, msgid, msg);
++PerfMonitor::Instance()->send_ws_count;
#ifdef DEBUG
f8::DumpMsgToLog(msg, "<<<<<<<WSL ");
#endif
}
template <typename T>
void SendToClient(int sockhandle, unsigned int seqid, T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
f8::Net_SendProxyMsg(tcp_listener_, sockhandle, seqid, 0, msgid, msg);
++PerfMonitor::Instance()->send_ws_count;
#ifdef DEBUG
f8::DumpMsgToLog(msg, "<<<<<<<WSL ");
#endif
}
void SendText(unsigned short sockhandle, const std::string& text);
void ForceCloseClient(unsigned short sockhandle);
void MarkClient(unsigned short sockhandle, bool is_active);
void _SS_Ping(f8::MsgHdr& hdr, const ss::SS_Ping& msg);
private:
a8::TcpListener *tcp_listener_ = nullptr;
};