From ec1fc048a75ee1be7f80b8c4800d7aae74474bc3 Mon Sep 17 00:00:00 2001
From: Florian Fischer <florian.fl.fischer@fau.de>
Date: Mon, 14 Sep 2020 13:12:07 +0200
Subject: [PATCH] wrap emper io functions in new io namespace

---
 emper/AsyncLibrary.cpp             | 14 +++++++-------
 emper/AsyncLibrary.hpp             |  3 +++
 emper/Runtime.cpp                  |  2 +-
 tests/SimpleDiskAndNetworkTest.cpp |  2 ++
 tests/SimpleNetworkTest.cpp        |  1 +
 5 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/emper/AsyncLibrary.cpp b/emper/AsyncLibrary.cpp
index c4c1b6b8..8ca9027d 100644
--- a/emper/AsyncLibrary.cpp
+++ b/emper/AsyncLibrary.cpp
@@ -209,7 +209,7 @@ static bool do_async_send(int fd, unsigned char* buff, int buff_len, int* return
 	return false;
 }
 
-int async_connect(int fd, sockaddr* sockaddress, socklen_t len, bool fd_serialized)
+int io::async_connect(int fd, sockaddr* sockaddress, socklen_t len, bool fd_serialized)
 {
 
     int flags = fcntl(fd, F_GETFL, 0);
@@ -266,7 +266,7 @@ int async_connect(int fd, sockaddr* sockaddress, socklen_t len, bool fd_serializ
     return 0;
 }
 
-int async_accept(int fd, sockaddr* sockaddress, socklen_t len, bool fd_serialized)
+int io::async_accept(int fd, sockaddr* sockaddress, socklen_t len, bool fd_serialized)
 {
 
 	int flags = fcntl(fd, F_GETFL, 0);
@@ -318,7 +318,7 @@ int async_accept(int fd, sockaddr* sockaddress, socklen_t len, bool fd_serialize
     return notify.return_value;
 }
 
-int async_recv(int fd, unsigned char* buff, int buff_len, bool read_once, bool fd_serialized)
+int io::async_recv(int fd, unsigned char* buff, int buff_len, bool read_once, bool fd_serialized)
 {
 
 	size_t offset = 0;
@@ -388,7 +388,7 @@ int async_recv(int fd, unsigned char* buff, int buff_len, bool read_once, bool f
     return notify.curr_offset;
 }
 
-int async_send(int fd, unsigned char* buff, int buff_len, bool fd_serialized)
+int io::async_send(int fd, unsigned char* buff, int buff_len, bool fd_serialized)
 {
 
 	size_t offset = 0;
@@ -463,7 +463,7 @@ static std::mutex io_uring_mutex;
 static std::vector<aio_handle*> overflow_queue;
 static std::mutex overflow_queue_mutex;
 
-int async_read_file(int fd, unsigned char* buff, size_t count, off_t offset) {
+int io::async_read_file(int fd, unsigned char* buff, size_t count, off_t offset) {
 
     aio_handle notify;
     notify.op = aio_op::uring_read;
@@ -504,7 +504,7 @@ int async_read_file(int fd, unsigned char* buff, size_t count, off_t offset) {
     return notify.return_value;
 }
 
-int async_write_file(int fd, const unsigned char* buff, size_t count, off_t offset) {
+int io::async_write_file(int fd, const unsigned char* buff, size_t count, off_t offset) {
 
     aio_handle notify;
     notify.op = aio_op::uring_write;
@@ -667,7 +667,7 @@ void handle_aio_event(aio_handle *notify, int result = -1) {
     }
 }
 
-void run_epoll_thread()
+void io::run_epoll_thread()
 {
     setup_epoll();
     setup_io_uring();
diff --git a/emper/AsyncLibrary.hpp b/emper/AsyncLibrary.hpp
index 65152f10..fded71d5 100644
--- a/emper/AsyncLibrary.hpp
+++ b/emper/AsyncLibrary.hpp
@@ -3,6 +3,7 @@
 #include "emper-config.h"
 
 #include <sys/socket.h>
+namespace io {
 /**
  * @param fd filedescriptor for this operation
  * @param buff destination buffer
@@ -48,3 +49,5 @@ int async_write_file(int fd, const unsigned char* buff, size_t count, off_t offs
 // Internal, move to somewhere else
 void run_epoll_thread();
 #endif
+
+}
diff --git a/emper/Runtime.cpp b/emper/Runtime.cpp
index b6aab435..f861dc26 100644
--- a/emper/Runtime.cpp
+++ b/emper/Runtime.cpp
@@ -122,7 +122,7 @@ Fiber* Runtime::nextFiber() {
 
 void Runtime::waitUntilFinished() {
 #ifdef EMPER_ASYNC_LIB
-	run_epoll_thread();
+	io::run_epoll_thread();
 #endif
 	for (workerid_t i = 0; i < workerCount; ++i) {
 		pthread_join(threads[i], nullptr);
diff --git a/tests/SimpleDiskAndNetworkTest.cpp b/tests/SimpleDiskAndNetworkTest.cpp
index eff621b5..e8d4566d 100644
--- a/tests/SimpleDiskAndNetworkTest.cpp
+++ b/tests/SimpleDiskAndNetworkTest.cpp
@@ -29,6 +29,8 @@
 #include "emper.hpp"
 #include "AsyncLibrary.hpp"
 
+using namespace io;
+
 
 #define MAX 1024
 void func()
diff --git a/tests/SimpleNetworkTest.cpp b/tests/SimpleNetworkTest.cpp
index b746c4b7..343ce9cc 100644
--- a/tests/SimpleNetworkTest.cpp
+++ b/tests/SimpleNetworkTest.cpp
@@ -27,6 +27,7 @@
 #include "emper.hpp"
 #include "AsyncLibrary.hpp"
 
+using namespace io;
 
 #define MAX 1024
 void func()
-- 
GitLab