nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #713: MINIFICPP-1119 unify win/posix sockets + clean up issues
Date Mon, 03 Feb 2020 16:10:24 GMT
arpadboda commented on a change in pull request #713: MINIFICPP-1119 unify win/posix sockets
+ clean up issues
URL: https://github.com/apache/nifi-minifi-cpp/pull/713#discussion_r374183989
 
 

 ##########
 File path: libminifi/src/io/ClientSocket.cpp
 ##########
 @@ -45,56 +42,68 @@ namespace nifi {
 namespace minifi {
 namespace io {
 
-Socket::Socket(const std::shared_ptr<SocketContext> &context, const std::string
&hostname, const uint16_t port, const uint16_t listeners = -1)
-    : requested_hostname_(hostname),
+static std::string get_last_err_str() noexcept {
+#ifdef WIN32
+  const auto error_code = WSAGetLastError();
+#else
+  const auto error_code = errno;
+#endif /* WIN32 */
+  return std::system_category().message(error_code);
+}
+
+Socket::Socket(const std::shared_ptr<SocketContext>& /*context*/, std::string hostname,
const uint16_t port, const uint16_t listeners = -1)
+    : addr_info_(nullptr),
+      requested_hostname_(std::move(hostname)),
+      canonical_hostname_(""),
       port_(port),
-      addr_info_(0),
+      is_loopback_only_(false),
       socket_file_descriptor_(-1),
       socket_max_(0),
       total_written_(0),
       total_read_(0),
-      is_loopback_only_(false),
       listeners_(listeners),
-      canonical_hostname_(""),
       nonBlocking_(false),
       logger_(logging::LoggerFactory<Socket>::getLogger()) {
   FD_ZERO(&total_list_);
   FD_ZERO(&read_fds_);
   initialize_socket();
 }
 
-Socket::Socket(const std::shared_ptr<SocketContext> &context, const std::string
&hostname, const uint16_t port)
-    : Socket(context, hostname, port, 0) {
-  initialize_socket();
+Socket::Socket(const std::shared_ptr<SocketContext>& context, std::string hostname,
const uint16_t port)
+    : Socket(context, std::move(hostname), port, 0) {
 }
 
-Socket::Socket(const Socket &&other)
-    : requested_hostname_(std::move(other.requested_hostname_)),
-      port_(std::move(other.port_)),
+Socket::Socket(Socket &&other) noexcept
+    : addr_info_(other.addr_info_),
+      requested_hostname_(std::move(other.requested_hostname_)),
+      canonical_hostname_(std::move(other.canonical_hostname_)),
+      port_(other.port_),
       is_loopback_only_(false),
-      addr_info_(std::move(other.addr_info_)),
       socket_file_descriptor_(other.socket_file_descriptor_),
-      socket_max_(other.socket_max_.load()),
-      listeners_(other.listeners_),
       total_list_(other.total_list_),
       read_fds_(other.read_fds_),
-      canonical_hostname_(std::move(other.canonical_hostname_)),
+      socket_max_(other.socket_max_.load()),
+      total_written_(other.total_written_.load()),
+      total_read_(other.total_read_.load()),
+      listeners_(other.listeners_),
       nonBlocking_(false),
-      logger_(std::move(other.logger_)) {
-  total_written_ = other.total_written_.load();
-  total_read_ = other.total_read_.load();
-}
+      logger_(std::move(other.logger_))
+{ }
 
 Socket::~Socket() {
-  closeStream();
+  Socket::closeStream();
 }
 
 void Socket::closeStream() {
-  if (0 != addr_info_) {
+  if (addr_info_ != nullptr) {
     freeaddrinfo(addr_info_);
-    addr_info_ = 0;
+    addr_info_ = nullptr;
   }
-  if (socket_file_descriptor_ >= 0 && socket_file_descriptor_ != INVALID_SOCKET)
{
+  if (socket_file_descriptor_ >= 0
+#ifdef WIN32
+    && socket_file_descriptor_ != INVALID_SOCKET
 
 Review comment:
   Even if this is pretty rarely used I would prefer to have a helper function for this (to
check if socket is valid). 
   Having this ifdef in the middle of a condition is a bit confusing. In a 2 liner helper
func it's easy to understand. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message