Kea hooks in external (i.e., not C++) languages.
-Asked for customers: hooks written in python (see below), lua,
-ocaml (see below?), ...
+Asked for customers: hooks written in python (done), lua, ocaml (done), ...
Kea hook summary:
- dynamic shared objects loaded from the config on hooks-libraries
https://www.lua.org/pil/p1.html is obsolete but better)
Question: C++ shared_ptr?
-Answer: must use explicit finalization to reset shared_ptr's
+Answer: must use explicit finalization to reset shared_ptr's,
+should be encapsulated into a structure. Note the example codes make
+the strong assumption shared pointers are built by the default
+constructor as a memory block of zero (the documentation says
+only the use count and the managed pointer are initialized to 0).
+The test tool inspect.cc can be used to verify boost shared pointers
+are implemented as expected.
Question: DHCPv4 packet example?
Answer: Pkt4Ptr with addOption, getCiaddr, getHtype, getHWAddr,
Question: external language types?
Answer:
python3: int, float, str, bytes
- ocaml: int, float, string (include binary)
+ ocaml: int, float, string, bytes (same representation than string)
lua: (number) integer, (number) float, string (include binary)
+
--- /dev/null
+// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <iostream>
+#include <string>
+
+#include <boost/shared_ptr.hpp>
+
+namespace isc {
+
+typedef int* IntPtr;
+typedef int*** IntPtr3;
+
+struct Four {
+ IntPtr3 a, b, c, d;
+
+ Four() : a(0), b(0), c(0), d() { }
+};
+
+typedef Four* FourPtr;
+
+typedef boost::shared_ptr<Four> FourSharedPtr;
+
+struct Encap {
+ FourSharedPtr object;
+};
+
+} // end of namespace isc
+
+using namespace std;
+using namespace isc;
+
+int main() {
+ cout << "sizeof(IntPtr ::= int*) is " << sizeof(IntPtr) * 8 << " octets\n";
+ cout << "sizeof(IntPtr3 ::= int***) is " << sizeof(IntPtr3) * 8 << " octets\n";
+ if (sizeof(IntPtr) != sizeof(IntPtr3)) {
+ cout << "unusual size difference between IntPtr and IntPtr3?\n";
+ }
+ if (sizeof(Four) != 4 * sizeof(IntPtr3)) {
+ cout << "sizeof(Four) is " << sizeof(Four) * 8
+ << " octets and don't match expected " << sizeof(IntPtr3) * 32
+ << " octet?\n";
+ }
+ Four one;
+ Four zero;
+ memset(&zero, 0, sizeof(Four));
+ if (memcmp(&zero, &one, sizeof(Four)) != 0) {
+ cout << "Four instance is not initialized to 0 as expected?\n";
+ }
+ cout << "sizeof(FourPtr ::= Four*) is " << sizeof(FourPtr) * 8 << " octets\n";
+ cout << "sizeof(FourSharedPtr ::= shared_ptr<Four> is " << sizeof(FourSharedPtr) * 8 << " octets\n";
+ cout << "sizeof(Encap) is " << sizeof(Encap) * 8 << " octets\n";
+ if (sizeof(FourSharedPtr) != sizeof(Encap)) {
+ cout << "unusual size difference between Encap and FourSharedPtr\n";
+ }
+ size_t size = sizeof(Encap);
+ if (sizeof(Four) < sizeof(Encap)) {
+ cout << "shared pointers are very big?\n";
+ size = sizeof(Four);
+ }
+ Encap encap;
+ if (memcmp(&encap, &zero, size) != 0) {
+ cerr << "shared pointers are not initialized to 0???\n";
+ return (-1);
+ }
+ cout << "shared pointers are initialized to 0 as expected\n";
+ return (0);
+}
+