Blob Blame History Raw
From 71f5498b023bf93fc3aa78fbe926abbfd12419e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
Date: Tue, 18 Jan 2022 23:55:19 +0100
Subject: [PATCH] Keep old uvw version but support recent type

TcpHandle were renamed to TCPHandle in uvw 2.3.5. Use new name, but keep
old uvw not updated. More recent uvw would require more recent libuv
library, which might not always be available. Should compile both on
recent uvw library and original bundled code.

Change also HTTPS code.
---
 3rd/uvw/uvw/tcp.hpp     |  1 +
 flame/httpssession.cpp  |  2 +-
 flame/httpssession.h    |  4 ++--
 flame/tcpsession.cpp    |  2 +-
 flame/tcpsession.h      |  4 ++--
 flame/tcptlssession.cpp |  2 +-
 flame/tcptlssession.h   |  2 +-
 flame/tokenbucket.h     |  2 +-
 flame/trafgen.cpp       | 18 +++++++++---------
 flame/trafgen.h         |  2 +-
 10 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/3rd/uvw/uvw/tcp.hpp b/3rd/uvw/uvw/tcp.hpp
index 49cdc75..bf60c4c 100644
--- a/3rd/uvw/uvw/tcp.hpp
+++ b/3rd/uvw/uvw/tcp.hpp
@@ -256,5 +256,6 @@ private:
     unsigned int flags;
 };
 
+typedef TcpHandle TCPHandle;
 
 }
diff --git a/flame/httpssession.cpp b/flame/httpssession.cpp
index 1a9b98a..f2a616e 100644
--- a/flame/httpssession.cpp
+++ b/flame/httpssession.cpp
@@ -16,7 +16,7 @@ static ssize_t gnutls_push_trampoline(gnutls_transport_ptr_t h, const void *buf,
     return session->gnutls_push(buf, len);
 }
 
-HTTPSSession::HTTPSSession(std::shared_ptr<uvw::TcpHandle> handle,
+HTTPSSession::HTTPSSession(std::shared_ptr<uvw::TCPHandle> handle,
     TCPSession::malformed_data_cb malformed_data_handler,
     TCPSession::got_dns_msg_cb got_dns_msg_handler,
     TCPSession::connection_ready_cb connection_ready_handler,
diff --git a/flame/httpssession.h b/flame/httpssession.h
index 0f96ed2..c414d5c 100644
--- a/flame/httpssession.h
+++ b/flame/httpssession.h
@@ -44,7 +44,7 @@ public:
     using log_send_cb = std::function<void(int32_t id)>;
     using handshake_error_cb = std::function<void()>;
 
-    HTTPSSession(std::shared_ptr<uvw::TcpHandle> handle,
+    HTTPSSession(std::shared_ptr<uvw::TCPHandle> handle,
         TCPSession::malformed_data_cb malformed_data_handler,
         TCPSession::got_dns_msg_cb got_dns_msg_handler,
         TCPSession::connection_ready_cb connection_ready_handler,
@@ -87,7 +87,7 @@ private:
     STATE_HTTP2 http2_state;
     malformed_data_cb _malformed_data;
     got_dns_msg_cb _got_dns_msg;
-    std::shared_ptr<uvw::TcpHandle> _handle;
+    std::shared_ptr<uvw::TCPHandle> _handle;
     enum class LinkState { HANDSHAKE,
         DATA,
         CLOSE } _tls_state;
diff --git a/flame/tcpsession.cpp b/flame/tcpsession.cpp
index 2ec8c30..d0b6c5b 100644
--- a/flame/tcpsession.cpp
+++ b/flame/tcpsession.cpp
@@ -4,7 +4,7 @@
 
 #include "tcpsession.h"
 
-TCPSession::TCPSession(std::shared_ptr<uvw::TcpHandle> handle,
+TCPSession::TCPSession(std::shared_ptr<uvw::TCPHandle> handle,
                        malformed_data_cb malformed_data_handler,
                        got_dns_msg_cb got_dns_msg_handler,
                        connection_ready_cb connection_ready_handler)
diff --git a/flame/tcpsession.h b/flame/tcpsession.h
index f56018d..6478ae4 100644
--- a/flame/tcpsession.h
+++ b/flame/tcpsession.h
@@ -11,7 +11,7 @@ public:
     using got_dns_msg_cb = std::function<void(std::unique_ptr<char[]> data, size_t size)>;
     using connection_ready_cb = std::function<void()>;
 
-    TCPSession(std::shared_ptr<uvw::TcpHandle> handle,
+    TCPSession(std::shared_ptr<uvw::TCPHandle> handle,
                malformed_data_cb malformed_data_handler,
                got_dns_msg_cb got_dns_msg_handler,
                connection_ready_cb connection_ready_handler);
@@ -29,7 +29,7 @@ public:
 
 private:
     std::string _buffer;
-    std::shared_ptr<uvw::TcpHandle> _handle;
+    std::shared_ptr<uvw::TCPHandle> _handle;
     malformed_data_cb _malformed_data;
     got_dns_msg_cb _got_dns_msg;
     connection_ready_cb _connection_ready;
diff --git a/flame/tcptlssession.cpp b/flame/tcptlssession.cpp
index 080b112..917a18c 100644
--- a/flame/tcptlssession.cpp
+++ b/flame/tcptlssession.cpp
@@ -16,7 +16,7 @@ static ssize_t gnutls_push_trampoline(gnutls_transport_ptr_t h, const void *buf,
     return session->gnutls_push(buf, len);
 }
 
-TCPTLSSession::TCPTLSSession(std::shared_ptr<uvw::TcpHandle> handle,
+TCPTLSSession::TCPTLSSession(std::shared_ptr<uvw::TCPHandle> handle,
                              TCPSession::malformed_data_cb malformed_data_handler,
                              TCPSession::got_dns_msg_cb got_dns_msg_handler,
                              TCPSession::connection_ready_cb connection_ready_handler,
diff --git a/flame/tcptlssession.h b/flame/tcptlssession.h
index ec9ff6e..b905cec 100644
--- a/flame/tcptlssession.h
+++ b/flame/tcptlssession.h
@@ -9,7 +9,7 @@ class TCPTLSSession : public TCPSession
 public:
     using handshake_error_cb =  std::function<void()>;
 
-    TCPTLSSession(std::shared_ptr<uvw::TcpHandle> handle,
+    TCPTLSSession(std::shared_ptr<uvw::TCPHandle> handle,
                   TCPSession::malformed_data_cb malformed_data_handler,
                   TCPSession::got_dns_msg_cb got_dns_msg_handler,
                   TCPSession::connection_ready_cb connection_ready_handler,
diff --git a/flame/tokenbucket.h b/flame/tokenbucket.h
index a851e31..2ea3588 100644
--- a/flame/tokenbucket.h
+++ b/flame/tokenbucket.h
@@ -2,7 +2,7 @@
 #pragma once
 
 #include <chrono>
-#include <uvw/loop.hpp>
+#include <uvw.hpp>
 
 class TokenBucket
 {
diff --git a/flame/trafgen.cpp b/flame/trafgen.cpp
index 8aeda32..b88943d 100644
--- a/flame/trafgen.cpp
+++ b/flame/trafgen.cpp
@@ -94,12 +94,12 @@ void TrafGen::start_tcp_session()
     assert(_tcp_session.get() == 0);
     assert(_finish_session_timer.get() == 0);
     Target current_target = _traf_config->next_target();
-    _tcp_handle = _loop->resource<uvw::TcpHandle>(_traf_config->family);
+    _tcp_handle = _loop->resource<uvw::TCPHandle>(_traf_config->family);
 
     if (_traf_config->family == AF_INET) {
         _tcp_handle->bind<uvw::IPv4>(_traf_config->bind_ip, 0);
     } else {
-        _tcp_handle->bind<uvw::IPv6>(_traf_config->bind_ip, 0, uvw::TcpHandle::Bind::IPV6ONLY);
+        _tcp_handle->bind<uvw::IPv6>(_traf_config->bind_ip, 0, uvw::TCPHandle::Bind::IPV6ONLY);
     }
 
     _metrics->trafgen_id(_tcp_handle->sock().port);
@@ -182,7 +182,7 @@ void TrafGen::start_tcp_session()
     /** SOCKET CALLBACKS **/
 
     // SOCKET: local socket was closed, cleanup resources and possibly restart another connection
-    _tcp_handle->on<uvw::CloseEvent>([this](uvw::CloseEvent &event, uvw::TcpHandle &h) {
+    _tcp_handle->on<uvw::CloseEvent>([this](uvw::CloseEvent &event, uvw::TCPHandle &h) {
         // if timer is still going (e.g. we got here through EndEvent), cancel it
         if (_finish_session_timer.get()) {
             _finish_session_timer->stop();
@@ -201,34 +201,34 @@ void TrafGen::start_tcp_session()
     });
 
     // SOCKET: socket error
-    _tcp_handle->on<uvw::ErrorEvent>([this](uvw::ErrorEvent &event, uvw::TcpHandle &h) {
+    _tcp_handle->on<uvw::ErrorEvent>([this](uvw::ErrorEvent &event, uvw::TCPHandle &h) {
         _metrics->net_error();
         // XXX need to close?
     });
 
     // INCOMING: remote peer closed connection, EOF
-    _tcp_handle->on<uvw::EndEvent>([this](uvw::EndEvent &event, uvw::TcpHandle &h) {
+    _tcp_handle->on<uvw::EndEvent>([this](uvw::EndEvent &event, uvw::TCPHandle &h) {
         _tcp_session->on_end_event();
     });
 
     // OUTGOING: we've finished writing all our data and are shutting down
-    _tcp_handle->on<uvw::ShutdownEvent>([this](uvw::ShutdownEvent &event, uvw::TcpHandle &h) {
+    _tcp_handle->on<uvw::ShutdownEvent>([this](uvw::ShutdownEvent &event, uvw::TCPHandle &h) {
         _tcp_session->on_shutdown_event();
     });
 
     // INCOMING: remote peer sends data, pass to session
-    _tcp_handle->on<uvw::DataEvent>([this](uvw::DataEvent &event, uvw::TcpHandle &h) {
+    _tcp_handle->on<uvw::DataEvent>([this](uvw::DataEvent &event, uvw::TCPHandle &h) {
         _tcp_session->receive_data(event.data.get(), event.length);
     });
 
     // OUTGOING: write operation has finished
-    _tcp_handle->on<uvw::WriteEvent>([this](uvw::WriteEvent &event, uvw::TcpHandle &h) {
+    _tcp_handle->on<uvw::WriteEvent>([this](uvw::WriteEvent &event, uvw::TCPHandle &h) {
         if (!_finish_session_timer)
             start_wait_timer_for_tcp_finish();
     });
 
     // SOCKET: on connect
-    _tcp_handle->on<uvw::ConnectEvent>([this](uvw::ConnectEvent &event, uvw::TcpHandle &h) {
+    _tcp_handle->on<uvw::ConnectEvent>([this](uvw::ConnectEvent &event, uvw::TCPHandle &h) {
         _tcp_session->on_connect_event();
         _metrics->tcp_connection();
 
diff --git a/flame/trafgen.h b/flame/trafgen.h
index 9907757..37901bd 100644
--- a/flame/trafgen.h
+++ b/flame/trafgen.h
@@ -64,7 +64,7 @@ class TrafGen
     std::shared_ptr<TokenBucket> _rate_limit;
 
     std::shared_ptr<uvw::UDPHandle> _udp_handle;
-    std::shared_ptr<uvw::TcpHandle> _tcp_handle;
+    std::shared_ptr<uvw::TCPHandle> _tcp_handle;
     std::shared_ptr<TCPSession> _tcp_session;
 
     std::shared_ptr<uvw::TimerHandle> _sender_timer;
-- 
2.31.1