From 954d271d509356ab8042976b9add577150254b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 6 Oct 2016 23:54:39 +0200 Subject: Fix the argument of strerror after bind() fix coverity CID 134470 --- louloulibs/network/tcp_socket_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'louloulibs/network/tcp_socket_handler.cpp') diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp index 5420b1c..967fefe 100644 --- a/louloulibs/network/tcp_socket_handler.cpp +++ b/louloulibs/network/tcp_socket_handler.cpp @@ -80,7 +80,7 @@ void TCPSocketHandler::init_socket(const struct addrinfo* rp) } if (!rp) log_error("Failed to bind socket to ", this->bind_addr, ": ", - strerror(bind_error)); + strerror(errno)); else log_info("Socket successfully bound to ", this->bind_addr); } -- cgit v1.2.3 From ce06c25e93183282be42ab79bfed2ab7c02791ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 20 Oct 2016 19:32:20 +0200 Subject: Very little optimization by using a simpler scope_guard when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The version with the vector, that can be disabled etc, is “very” slow, so we use unique_ptr when we don’t need to disable it, and when it only contains one function --- louloulibs/network/tcp_socket_handler.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'louloulibs/network/tcp_socket_handler.cpp') diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp index 967fefe..ca267cd 100644 --- a/louloulibs/network/tcp_socket_handler.cpp +++ b/louloulibs/network/tcp_socket_handler.cpp @@ -103,8 +103,6 @@ void TCPSocketHandler::connect(const std::string& address, const std::string& po this->port = port; this->use_tls = tls; - utils::ScopeGuard sg; - struct addrinfo* addr_res; if (!this->connecting) -- cgit v1.2.3 From aa4255224eb19ca55a963574fb527e1f07ff9cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 20 Oct 2016 20:08:29 +0200 Subject: Optimize tcp_socket::on_send by using vector::erase() only once per call --- louloulibs/network/tcp_socket_handler.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'louloulibs/network/tcp_socket_handler.cpp') diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp index ca267cd..9d8cfea 100644 --- a/louloulibs/network/tcp_socket_handler.cpp +++ b/louloulibs/network/tcp_socket_handler.cpp @@ -305,23 +305,24 @@ void TCPSocketHandler::on_send() else { // remove all the strings that were successfully sent. - for (auto it = this->out_buf.begin(); - it != this->out_buf.end();) + auto it = this->out_buf.begin(); + while (it != this->out_buf.end()) { - if (static_cast(res) >= (*it).size()) + if (static_cast(res) >= it->size()) { - res -= (*it).size(); - it = this->out_buf.erase(it); + res -= it->size(); + ++it; } else { // If one string has partially been sent, we use substr to // crop it if (res > 0) - (*it) = (*it).substr(res, std::string::npos); + *it = it->substr(res, std::string::npos); break; } } + this->out_buf.erase(this->out_buf.begin(), it); if (this->out_buf.empty()) this->poller->stop_watching_send_events(this); } -- cgit v1.2.3 From 6d5d7eff6835ff0dbeca8d84bfadee127918c3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Thu, 27 Oct 2016 01:15:26 +0200 Subject: Directly use Botan::byte instead of char, to avoid an unnecessary cast --- louloulibs/network/tcp_socket_handler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'louloulibs/network/tcp_socket_handler.cpp') diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp index 9d8cfea..1adbaac 100644 --- a/louloulibs/network/tcp_socket_handler.cpp +++ b/louloulibs/network/tcp_socket_handler.cpp @@ -417,15 +417,14 @@ void TCPSocketHandler::start_tls() void TCPSocketHandler::tls_recv() { static constexpr size_t buf_size = 4096; - char recv_buf[buf_size]; + Botan::byte recv_buf[buf_size]; const ssize_t size = this->do_recv(recv_buf, buf_size); if (size > 0) { const bool was_active = this->tls->is_active(); try { - this->tls->received_data(reinterpret_cast(recv_buf), - static_cast(size)); + this->tls->received_data(recv_buf, static_cast(size)); } catch (const Botan::TLS::TLS_Exception& e) { // May happen if the server sends malformed TLS data (buggy server, // or more probably we are just connected to a server that sends @@ -448,9 +447,8 @@ void TCPSocketHandler::tls_send(std::string&& data) const bool was_active = this->tls->is_active(); if (!this->pre_buf.empty()) { - this->tls->send(reinterpret_cast(this->pre_buf.data()), - this->pre_buf.size()); - this->pre_buf = ""; + this->tls->send(this->pre_buf.data(), this->pre_buf.size()); + this->pre_buf.clear(); } if (!data.empty()) this->tls->send(reinterpret_cast(data.data()), @@ -459,7 +457,9 @@ void TCPSocketHandler::tls_send(std::string&& data) this->on_tls_activated(); } else - this->pre_buf += data; + this->pre_buf.insert(this->pre_buf.end(), + std::make_move_iterator(data.begin()), + std::make_move_iterator(data.end())); } void TCPSocketHandler::tls_data_cb(const Botan::byte* data, size_t size) -- cgit v1.2.3 From 3e7c8ab4bc1ea15f02dbeee51ca8894bdd70eeab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 28 Oct 2016 00:22:20 +0200 Subject: Trivial cleanup --- louloulibs/network/tcp_socket_handler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'louloulibs/network/tcp_socket_handler.cpp') diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp index 1adbaac..9decee1 100644 --- a/louloulibs/network/tcp_socket_handler.cpp +++ b/louloulibs/network/tcp_socket_handler.cpp @@ -292,7 +292,8 @@ void TCPSocketHandler::on_send() // unconsting the content of s is ok, sendmsg will never modify it msg_iov[msg.msg_iovlen].iov_base = const_cast(s.data()); msg_iov[msg.msg_iovlen].iov_len = s.size(); - if (++msg.msg_iovlen == UIO_FASTIOV) + msg.msg_iovlen++; + if (msg.msg_iovlen == UIO_FASTIOV) break; } ssize_t res = ::sendmsg(this->socket, &msg, MSG_NOSIGNAL); -- cgit v1.2.3 From 7376831bc8f6dbec8eaf4f4c0a6bba819a0a1e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Mon, 7 Nov 2016 14:43:07 +0100 Subject: Add get-irc-connection-info adhoc command fix #3171 --- louloulibs/network/tcp_socket_handler.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'louloulibs/network/tcp_socket_handler.cpp') diff --git a/louloulibs/network/tcp_socket_handler.cpp b/louloulibs/network/tcp_socket_handler.cpp index 9decee1..1dddde5 100644 --- a/louloulibs/network/tcp_socket_handler.cpp +++ b/louloulibs/network/tcp_socket_handler.cpp @@ -179,6 +179,8 @@ void TCPSocketHandler::connect(const std::string& address, const std::string& po if (this->use_tls) this->start_tls(); #endif + this->connection_date = std::chrono::system_clock::now(); + this->on_connected(); return ; } @@ -397,6 +399,16 @@ bool TCPSocketHandler::is_connecting() const return this->connecting || this->resolver.is_resolving(); } +bool TCPSocketHandler::is_using_tls() const +{ + return this->use_tls; +} + +std::string TCPSocketHandler::get_port() const +{ + return this->port; +} + void* TCPSocketHandler::get_receive_buffer(const size_t) const { return nullptr; -- cgit v1.2.3