summaryrefslogtreecommitdiff
path: root/src/network/socket_handler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/socket_handler.cpp')
-rw-r--r--src/network/socket_handler.cpp12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/network/socket_handler.cpp b/src/network/socket_handler.cpp
index 2348faa..a9e0c5e 100644
--- a/src/network/socket_handler.cpp
+++ b/src/network/socket_handler.cpp
@@ -23,8 +23,8 @@ using namespace std::string_literals;
# define UIO_FASTIOV 8
#endif
-SocketHandler::SocketHandler():
- poller(nullptr),
+SocketHandler::SocketHandler(std::shared_ptr<Poller> poller):
+ poller(poller),
connected(false),
connecting(false)
{
@@ -107,6 +107,7 @@ void SocketHandler::connect(const std::string& address, const std::string& port)
|| errno == EISCONN)
{
log_info("Connection success.");
+ this->poller->add_socket_handler(this);
this->connected = true;
this->connecting = false;
this->on_connected();
@@ -134,11 +135,6 @@ void SocketHandler::connect()
this->connect(this->address, this->port);
}
-void SocketHandler::set_poller(Poller* poller)
-{
- this->poller = poller;
-}
-
void SocketHandler::on_recv()
{
static constexpr size_t buf_size = 4096;
@@ -231,8 +227,6 @@ void SocketHandler::close()
this->port.clear();
this->poller->remove_socket_handler(this->get_socket());
::close(this->socket);
- // recreate the socket for a potential future usage
- this->init_socket();
}
socket_t SocketHandler::get_socket() const