quickstep-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jianq...@apache.org
Subject incubator-quickstep git commit: Update ntohll/htonll for protability
Date Wed, 05 Dec 2018 23:29:21 GMT
Repository: incubator-quickstep
Updated Branches:
  refs/heads/trace-dev 29024a3e9 -> 9005d9935


Update ntohll/htonll for protability


Project: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/commit/9005d993
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/tree/9005d993
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quickstep/diff/9005d993

Branch: refs/heads/trace-dev
Commit: 9005d99359b8d7cae8fc2c31539e70bd5e45761f
Parents: 29024a3
Author: Jianqiao Zhu <jianqiao@cs.wisc.edu>
Authored: Fri Nov 9 22:23:04 2018 -0600
Committer: Jianqiao Zhu <jianqiao@cs.wisc.edu>
Committed: Fri Nov 9 22:30:39 2018 -0600

----------------------------------------------------------------------
 cli/simple_socket/SimpleSocketConnection.hpp | 25 ++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quickstep/blob/9005d993/cli/simple_socket/SimpleSocketConnection.hpp
----------------------------------------------------------------------
diff --git a/cli/simple_socket/SimpleSocketConnection.hpp b/cli/simple_socket/SimpleSocketConnection.hpp
index 111db6a..0bd7774 100644
--- a/cli/simple_socket/SimpleSocketConnection.hpp
+++ b/cli/simple_socket/SimpleSocketConnection.hpp
@@ -20,6 +20,7 @@
 #ifndef QUICKSTEP_CLI_SIMPLE_SOCKET_SIMPLE_SOCKET_CONNECTION_HPP_
 #define QUICKSTEP_CLI_SIMPLE_SOCKET_SIMPLE_SOCKET_CONNECTION_HPP_
 
+#include <arpa/inet.h>
 #include <sys/socket.h>
 
 #include <cstdint>
@@ -72,12 +73,12 @@ class SimpleSocketConnection {
     // Decode request data.
     const std::uint64_t *size_ptr =
         static_cast<const std::uint64_t*>(request_data_);
-    const std::uint64_t num_fields = ntohll(*size_ptr++);
+    const std::uint64_t num_fields = Ntohll(*size_ptr++);
 
     std::vector<std::pair<std::uint64_t, std::uint64_t>> field_sizes;
     for (std::size_t i = 0; i < num_fields; ++i) {
-      const std::uint64_t key_size = ntohll(*size_ptr++);
-      const std::uint64_t value_size = ntohll(*size_ptr++);
+      const std::uint64_t key_size = Ntohll(*size_ptr++);
+      const std::uint64_t value_size = Ntohll(*size_ptr++);
       field_sizes.emplace_back(key_size, value_size);
     }
 
@@ -108,11 +109,11 @@ class SimpleSocketConnection {
   inline std::uint64_t receiveUInt64() const {
     std::uint64_t code;
     receiveData(&code, sizeof(std::uint64_t));
-    return ntohll(code);
+    return Ntohll(code);
   }
 
   inline void writeUInt64(const std::uint64_t value) const {
-    const uint64_t code = htonll(value);
+    const uint64_t code = Htonll(value);
     write(socket_fd_, &code, sizeof(std::uint64_t));
   }
 
@@ -146,6 +147,20 @@ class SimpleSocketConnection {
     }
   }
 
+  inline static std::uint64_t Ntohll(const std::uint64_t code) {
+    const std::uint32_t lo32 = static_cast<std::uint32_t>(code);
+    const std::uint32_t hi32 = static_cast<std::uint32_t>(code >> 32);
+    return (static_cast<std::uint64_t>(ntohl(lo32)) << 32)
+               | static_cast<std::uint64_t>(ntohl(hi32));
+  }
+
+  inline static std::uint64_t Htonll(const std::uint64_t code) {
+    const std::uint32_t lo32 = static_cast<std::uint32_t>(code);
+    const std::uint32_t hi32 = static_cast<std::uint32_t>(code >> 32);
+    return (static_cast<std::uint64_t>(htonl(lo32)) << 32)
+               | static_cast<std::uint64_t>(htonl(hi32));
+  }
+
   const int socket_fd_;
   std::uint64_t request_data_length_;
   void *request_data_;


Mime
View raw message