bmahler commented on code in PR #501:
URL: https://github.com/apache/mesos/pull/501#discussion_r1518226542


##########
src/linux/ebpf.cpp:
##########
@@ -14,4 +14,90 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "linux/ebpf.hpp"
\ No newline at end of file
+#include "linux/ebpf.hpp"
+
+#include <linux/bpf.h>
+#include <sys/syscall.h>
+
+#include <string>
+#include <vector>
+
+#include "stout/check.hpp"
+#include "stout/error.hpp"
+#include "stout/try.hpp"
+
+using std::string;
+using std::vector;
+
+namespace ebpf {
+
+Try<int, ErrnoError> bpf(int cmd, bpf_attr* attr, size_t size)
+{
+  // We retry the system call `attempts` times. The default is 5, as per
+  // what's done by libbpf:
+  // https://github.com/libbpf/libbpf/blob/master/src/bpf.h#L71-L75
+  int result, attempts = 5;
+  do {
+    result = (int)syscall(__NR_bpf, cmd, attr, size);
+  } while (errno == EAGAIN && --attempts > 0);
+
+  if (result == -1) {
+    return ErrnoError();
+  }
+  return result == -1;

Review Comment:
   return result;



##########
src/linux/ebpf.cpp:
##########
@@ -14,4 +14,90 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "linux/ebpf.hpp"
\ No newline at end of file
+#include "linux/ebpf.hpp"
+
+#include <linux/bpf.h>
+#include <sys/syscall.h>
+
+#include <string>
+#include <vector>
+
+#include "stout/check.hpp"
+#include "stout/error.hpp"
+#include "stout/try.hpp"
+
+using std::string;
+using std::vector;
+
+namespace ebpf {
+
+Try<int, ErrnoError> bpf(int cmd, bpf_attr* attr, size_t size)
+{
+  // We retry the system call `attempts` times. The default is 5, as per
+  // what's done by libbpf:
+  // https://github.com/libbpf/libbpf/blob/master/src/bpf.h#L71-L75
+  int result, attempts = 5;
+  do {
+    result = (int)syscall(__NR_bpf, cmd, attr, size);
+  } while (errno == EAGAIN && --attempts > 0);

Review Comment:
   ```
     do {
       result = (int)syscall(__NR_bpf, cmd, attr, size);
     } while (result == -1 && errno == EAGAIN && --attempts > 0);
   ```



##########
src/linux/ebpf.cpp:
##########
@@ -14,4 +14,90 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#include "linux/ebpf.hpp"
\ No newline at end of file
+#include "linux/ebpf.hpp"
+
+#include <linux/bpf.h>
+#include <sys/syscall.h>
+
+#include <string>
+#include <vector>
+
+#include "stout/check.hpp"
+#include "stout/error.hpp"
+#include "stout/try.hpp"
+
+using std::string;
+using std::vector;
+
+namespace ebpf {
+
+Try<int, ErrnoError> bpf(int cmd, bpf_attr* attr, size_t size)
+{
+  // We retry the system call `attempts` times. The default is 5, as per
+  // what's done by libbpf:
+  // https://github.com/libbpf/libbpf/blob/master/src/bpf.h#L71-L75
+  int result, attempts = 5;
+  do {
+    result = (int)syscall(__NR_bpf, cmd, attr, size);
+  } while (errno == EAGAIN && --attempts > 0);
+
+  if (result == -1) {
+    return ErrnoError();
+  }
+  return result == -1;
+}
+
+
+Program::Program(bpf_prog_type _type) : type(_type) {}
+
+
+void Program::append(vector<bpf_insn>&& instructions)
+{
+  program.insert(
+    program.end(),
+    std::make_move_iterator(instructions.begin()),
+    std::make_move_iterator(instructions.end()));
+}
+
+
+Try<int> load(Program& program)

Review Comment:
   const& here



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to