Skip to content

Commit

Permalink
Fix: define CLTCPServer as uncopyable
Browse files Browse the repository at this point in the history
  • Loading branch information
MakingL committed Jan 9, 2020
1 parent 2d17bfe commit 6ac34f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

static std::string g_local_ip;

CLTCPServer::CLTCPServer(const char *host, unsigned int port) : m_port(port), m_host(host) {
CLTCPServer::CLTCPServer(const char *host, unsigned int port) : m_port(port),
m_host(host),
m_listen_fd(0) {
if ((m_listen_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
utility::unix_error("Cannot create socket");
}
Expand Down
10 changes: 10 additions & 0 deletions src/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class CLTCPServer {

}

~CLTCPServer() {
if (m_listen_fd) {
close(m_listen_fd);
}
}

int start_listen();

Expand All @@ -27,6 +32,11 @@ class CLTCPServer {
bool limit_client_crowding(int connect_fd, unsigned int client_ip); /* 限流*/
void on_a_client_exit(unsigned int client_ip);

private:
/* 禁止复制 CLTCPServer 对象。只声明 copying 函数,不定义 */
CLTCPServer(const CLTCPServer&);
CLTCPServer &operator=(const CLTCPServer &);

private:
unsigned int m_port;
std::string m_host;
Expand Down

0 comments on commit 6ac34f7

Please sign in to comment.