diff --git a/qse/include/qse/si/TcpServer.hpp b/qse/include/qse/si/TcpServer.hpp index 2ab48572..e98a70a7 100644 --- a/qse/include/qse/si/TcpServer.hpp +++ b/qse/include/qse/si/TcpServer.hpp @@ -45,15 +45,6 @@ public: TcpServer () QSE_CPP_NOEXCEPT; virtual ~TcpServer () QSE_CPP_NOEXCEPT; - enum - { - ERR_NONE = 0, - ERR_OPEN = 1, - ERR_BIND = 2, - ERR_LISTEN = 3, - ERR_EXCEPTION = 4 - }; - virtual int start (const qse_char_t* addrs) QSE_CPP_NOEXCEPT; virtual int stop () QSE_CPP_NOEXCEPT; diff --git a/qse/lib/si/TcpServer.cpp b/qse/lib/si/TcpServer.cpp index 4e496a77..4200adce 100644 --- a/qse/lib/si/TcpServer.cpp +++ b/qse/lib/si/TcpServer.cpp @@ -106,8 +106,6 @@ void TcpServer::free_all_listeners () QSE_CPP_NOEXCEPT Listener* lp; struct epoll_event dummy_ev; - ::epoll_ctl (this->listener.ep_fd, EPOLL_CTL_DEL, this->listener.mux_pipe[0], &dummy_ev); - while (this->listener.head) { lp = this->listener.head; @@ -119,7 +117,19 @@ void TcpServer::free_all_listeners () QSE_CPP_NOEXCEPT delete lp; } + if (this->listener.mux_pipe[0] >= 0) + { + ::epoll_ctl (this->listener.ep_fd, EPOLL_CTL_DEL, this->listener.mux_pipe[0], &dummy_ev); + close (this->listener.mux_pipe[0]); + this->listener.mux_pipe[0] = -1; + } + if (this->listener.mux_pipe[1] >= 0) + { + close (this->listener.mux_pipe[1]); + this->listener.mux_pipe[1] = -1; + } QSE_ASSERT (this->listener.ep_fd >= 0); + ::close (this->listener.ep_fd); this->listener.ep_fd = -1; } diff --git a/qse/samples/si/tcpsvr01.cpp b/qse/samples/si/tcpsvr01.cpp index 65f572d5..f2626032 100644 --- a/qse/samples/si/tcpsvr01.cpp +++ b/qse/samples/si/tcpsvr01.cpp @@ -12,7 +12,7 @@ #include #include -static int g_stopreq = 0; + class ClientHandler @@ -20,16 +20,20 @@ class ClientHandler public: int operator() (QSE::Socket* sck, QSE::SocketAddress* addr) { -qse_printf (QSE_T("XXXXXXXXXXXXXXXXXXXXXXXXXX\n"));p +qse_printf (QSE_T("XXXXXXXXXXXXXXXXXXXXXXXXXX\n")); return 0; } }; +static QSE::TcpServerF* g_server; + static int test1 (void) { QSE::TcpServerF server; server.setThreadStackSize (256000); + g_server = &server; server.start (QSE_T("0.0.0.0:9998")); + g_server = QSE_NULL; return 0; } @@ -56,7 +60,7 @@ static int test2 (void) static void handle_sigint (int sig, siginfo_t* siginfo, void* ctx) { - g_stopreq = 1; + if (g_server) g_server->stop (); } static void set_signal (int sig, void(*handler)(int, siginfo_t*, void*))