Make sure WFServer's new_connection() returns a WFConnection, and protect CommConnection.

This commit is contained in:
XieHan
2021-05-22 18:48:56 +08:00
parent 233e2ed843
commit c4a4b3b857
6 changed files with 15 additions and 8 deletions

View File

@@ -31,8 +31,9 @@
class CommConnection
{
public:
protected:
virtual ~CommConnection() { }
friend class Communicator;
};
class CommTarget

View File

@@ -49,7 +49,7 @@ public:
int state;
private:
virtual CommConnection *new_connection(int)
virtual WFConnection *new_connection(int connect_fd)
{
return new WFConnection;
}

View File

@@ -18,9 +18,9 @@
#include "WFMySQLServer.h"
CommConnection *WFMySQLServer::new_connection(int accept_fd)
WFConnection *WFMySQLServer::new_connection(int accept_fd)
{
CommConnection *conn = this->WFServer::new_connection(accept_fd);
WFConnection *conn = this->WFServer::new_connection(accept_fd);
if (conn)
{
@@ -37,7 +37,7 @@ CommConnection *WFMySQLServer::new_connection(int accept_fd)
return conn;
}
delete conn;
this->delete_connection(conn);
}
return NULL;

View File

@@ -48,7 +48,7 @@ public:
}
protected:
virtual CommConnection *new_connection(int accept_fd);
virtual WFConnection *new_connection(int accept_fd);
virtual CommSession *new_session(long long seq, CommConnection *conn);
};

View File

@@ -134,7 +134,7 @@ int WFServerBase::create_listen_fd()
return listen_fd;
}
CommConnection *WFServerBase::new_connection(int accept_fd)
WFConnection *WFServerBase::new_connection(int accept_fd)
{
if (++this->conn_count <= this->params.max_connections ||
this->drain(1) == 1)
@@ -150,6 +150,11 @@ CommConnection *WFServerBase::new_connection(int accept_fd)
return NULL;
}
void WFServerBase::delete_connection(WFConnection *conn)
{
delete (WFServerConnection *)conn;
}
void WFServerBase::handle_unbound()
{
this->mutex.lock();

View File

@@ -158,7 +158,8 @@ protected:
WFServerParams params;
protected:
virtual CommConnection *new_connection(int accept_fd);
virtual WFConnection *new_connection(int accept_fd);
void delete_connection(WFConnection *conn);
private:
int init(const struct sockaddr *bind_addr, socklen_t addrlen,