Date: Wednesday, January 18, 2006 @ 14:50:27
  Author: zsolt
    Path: /cvsroot/carob/carob

Modified: include/JavaSocket.hpp (1.20 -> 1.21) src/JavaSocket.cpp (1.33
          -> 1.34)

Implemented: htonll() and ntohll() function which converts from and to network 
byte order to host byte order a 64bit integer.
Corrected writeJavaLong() and readJavaLong() to use this functions.


------------------------+
 include/JavaSocket.hpp |   16 +++++++++++++++-
 src/JavaSocket.cpp     |   24 +++++++++++++++++++++---
 2 files changed, 36 insertions(+), 4 deletions(-)


Index: carob/include/JavaSocket.hpp
diff -u carob/include/JavaSocket.hpp:1.20 carob/include/JavaSocket.hpp:1.21
--- carob/include/JavaSocket.hpp:1.20   Thu Jan 12 18:05:05 2006
+++ carob/include/JavaSocket.hpp        Wed Jan 18 14:50:27 2006
@@ -16,7 +16,7 @@
  * limitations under the License.
  *
  * Initial developer(s): Gilles Rayrat
- * Contributor(s): 
+ * Contributor(s): Zsolt Simon
  */
 
 #ifndef SOCKET_H_
@@ -189,6 +189,20 @@
   int           socketFd;
   /** true if the socket is connected to a host */
   bool          connected;
+
+  /**
+   * Function converts the unsigned 64bit integer from network byte order to 
host byte order.
+   * @param n number to be converted
+   * @return the converted number
+   */
+  const uint64_t ntohll(const uint64_t &n) const;
+
+  /**
+   * Function converts the unsigned 64bit integer from host byte order to 
network byte order.
+   * @param n number to be converted
+   * @return the converted number
+   */
+  const uint64_t htonll(const uint64_t &n) const;
 };
 
 } //namespace CarobNS
Index: carob/src/JavaSocket.cpp
diff -u carob/src/JavaSocket.cpp:1.33 carob/src/JavaSocket.cpp:1.34
--- carob/src/JavaSocket.cpp:1.33       Mon Jan 16 17:24:29 2006
+++ carob/src/JavaSocket.cpp    Wed Jan 18 14:50:27 2006
@@ -16,7 +16,7 @@
  * limitations under the License.
  *
  * Initial developer(s): Gilles Rayrat
- * Contributor(s): 
+ * Contributor(s): Zsolt Simon
  */
 
 #include <errno.h>
@@ -267,7 +267,7 @@
 {
   wstring fctName(L"JavaSocket::writeJavaLong");
   // we have to convert the byte order
-  int64_t conv = htonl(i);
+  int64_t conv = htonll(i);
   sendToSocket(fctName, L"Int64", &conv, sizeof(conv), SOCKET_SEND_FLAGS);
 }
 
@@ -281,7 +281,7 @@
   
   if (receiveFromSocket(fctName, L"Int64", &rec, sizeof(rec), 0))
   {
-    i = ntohl(rec);
+    i = ntohll(rec);
   }
 }
 
@@ -362,6 +362,24 @@
   }
 }
 
+const uint64_t JavaSocket::ntohll(const uint64_t &n) const
+{
+#if __BYTE_ORDER == __BIG_ENDIAN
+  return n;
+#else
+  return (((uint64_t)ntohl(n)) << 32) + ntohl(n >> 32);
+#endif
+}
+
+const uint64_t JavaSocket::htonll(const uint64_t &n) const
+{
+#if __BYTE_ORDER == __BIG_ENDIAN
+  return n;
+#else
+  return (((uint64_t)htonl(n)) << 32) + htonl(n >> 32);
+#endif
+}
+
 /*
  * Local Variables:
  * c-file-style: "bsd"

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to