1
This commit is contained in:
parent
a8cb80fd26
commit
56f576e60d
@ -190,8 +190,8 @@ namespace a8
|
|||||||
clients_mutex.unlock();
|
clients_mutex.unlock();
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
if (master->on_create_client_socket) {
|
if (master->on_create_client_socket_) {
|
||||||
master->on_create_client_socket(&session);
|
master->on_create_client_socket_(&session);
|
||||||
if (session) {
|
if (session) {
|
||||||
if (!session->AllocRecvBuf()) {
|
if (!session->AllocRecvBuf()) {
|
||||||
delete session;
|
delete session;
|
||||||
|
@ -18,7 +18,6 @@ namespace a8
|
|||||||
class TcpListener
|
class TcpListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::function<void (a8::TcpSession**)> on_create_client_socket;
|
|
||||||
std::function<void (const char*, int, bool&)> on_client_connect;
|
std::function<void (const char*, int, bool&)> on_client_connect;
|
||||||
std::function<void (a8::TcpListener*, a8::TCPLISTENER_E, int)> on_error;
|
std::function<void (a8::TcpListener*, a8::TCPLISTENER_E, int)> on_error;
|
||||||
std::string bind_address;
|
std::string bind_address;
|
||||||
@ -35,6 +34,15 @@ namespace a8
|
|||||||
void Open();
|
void Open();
|
||||||
void Close();
|
void Close();
|
||||||
bool IsActive();
|
bool IsActive();
|
||||||
|
template <typename T>
|
||||||
|
void RegisterSessionClass()
|
||||||
|
{
|
||||||
|
on_create_client_socket_ =
|
||||||
|
[] (a8::TcpSession** p)
|
||||||
|
{
|
||||||
|
*p = new T;
|
||||||
|
};
|
||||||
|
}
|
||||||
bool SendClientMsg(unsigned short sockhandle, const char *buff, int buffLen);
|
bool SendClientMsg(unsigned short sockhandle, const char *buff, int buffLen);
|
||||||
void BroadcastMsg(const char* buff, int bufflen);
|
void BroadcastMsg(const char* buff, int bufflen);
|
||||||
|
|
||||||
@ -42,6 +50,7 @@ namespace a8
|
|||||||
void MarkClient(unsigned short sockhandle, bool is_active);
|
void MarkClient(unsigned short sockhandle, bool is_active);
|
||||||
int GetClientSocketCount();
|
int GetClientSocketCount();
|
||||||
int GetPoolSocketCount();
|
int GetPoolSocketCount();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void LockClients();
|
void LockClients();
|
||||||
@ -50,6 +59,7 @@ namespace a8
|
|||||||
|
|
||||||
a8::TcpSession* GetClientSession(unsigned short handle);
|
a8::TcpSession* GetClientSession(unsigned short handle);
|
||||||
private:
|
private:
|
||||||
|
std::function<void (a8::TcpSession**)> on_create_client_socket_;
|
||||||
a8::TcpListenerImpl* impl_ = nullptr;
|
a8::TcpListenerImpl* impl_ = nullptr;
|
||||||
|
|
||||||
friend class TcpSession;
|
friend class TcpSession;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user