From 4b69a820ed6c622f0c085d8335ba9294a493437a Mon Sep 17 00:00:00 2001
From: Marek Vavrusa <marek.vavrusa@nic.cz>
Date: Wed, 14 Sep 2011 13:05:14 +0200
Subject: [PATCH] Finished polling API refactorization.

Commit refs #983.
---
 Knot.files                                    | 12 +++---
 src/Makefile.am                               |  8 ++--
 src/common/{os_fdset.c => fdset.c}            | 16 +++----
 src/common/{os_fdset.h => fdset.h}            |  8 ++--
 .../{os_fdset_epoll.c => fdset_epoll.c}       |  2 +-
 src/common/{os_fdset_poll.c => fdset_poll.c}  |  2 +-
 .../{os_fdset_tests.c => fdset_tests.c}       | 42 +++++++++----------
 src/tests/common/fdset_tests.h                |  9 ++++
 src/tests/common/os_fdset_tests.h             |  9 ----
 src/tests/unittests_main.c                    |  4 +-
 10 files changed, 56 insertions(+), 56 deletions(-)
 rename src/common/{os_fdset.c => fdset.c} (69%)
 rename src/common/{os_fdset.h => fdset.h} (96%)
 rename src/common/{os_fdset_epoll.c => fdset_epoll.c} (99%)
 rename src/common/{os_fdset_poll.c => fdset_poll.c} (99%)
 rename src/tests/common/{os_fdset_tests.c => fdset_tests.c} (73%)
 create mode 100644 src/tests/common/fdset_tests.h
 delete mode 100644 src/tests/common/os_fdset_tests.h

diff --git a/Knot.files b/Knot.files
index ef2d19e6c4..e21fa6cd3f 100644
--- a/Knot.files
+++ b/Knot.files
@@ -107,10 +107,10 @@ src/common/general-tree.h
 src/common/general-tree.c
 src/common/WELL1024a.c
 src/common/WELL1024a.h
-src/common/os_fdset.h
-src/common/os_fdset.c
-src/common/os_fdset_poll.c
-src/common/os_fdset_epoll.c
+src/common/fdset.h
+src/common/fdset.c
+src/common/fdset_poll.c
+src/common/fdset_epoll.c
 src/zcompile/parser-descriptor.h
 src/zcompile/parser-descriptor.c
 src/zcompile/parser-util.h
@@ -182,8 +182,8 @@ src/tests/common/skiplist_tests.c
 src/tests/common/skiplist_tests.h
 src/tests/common/slab_tests.c
 src/tests/common/slab_tests.h
-src/tests/common/os_fdset_tests.c
-src/tests/common/os_fdset_tests.h
+src/tests/common/fdset_tests.c
+src/tests/common/fdset_tests.h
 src/tests/knot/dthreads_tests.c
 src/tests/knot/dthreads_tests.h
 src/tests/knot/conf_tests.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 4a1a754e1c..2f651c1e42 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,8 +58,8 @@ unittests_SOURCES =				\
 	tests/common/skiplist_tests.h		\
 	tests/common/slab_tests.c		\
 	tests/common/slab_tests.h		\
-        tests/common/os_fdset_tests.c		\
-        tests/common/os_fdset_tests.h		\
+        tests/common/fdset_tests.c		\
+        tests/common/fdset_tests.h		\
 	tests/knot/conf_tests.c			\
 	tests/knot/conf_tests.h			\
 	tests/knot/dthreads_tests.c		\
@@ -179,8 +179,8 @@ libknots_la_SOURCES =				\
 	common/errors.c				\
         common/WELL1024a.h			\
         common/WELL1024a.c			\
-        common/os_fdset.h			\
-        common/os_fdset.c
+        common/fdset.h			\
+        common/fdset.c
 
 libknotd_la_SOURCES =				\
 	knot/stat/gatherer.c				\
diff --git a/src/common/os_fdset.c b/src/common/fdset.c
similarity index 69%
rename from src/common/os_fdset.c
rename to src/common/fdset.c
index 8a779cb8e0..fd875745bf 100644
--- a/src/common/os_fdset.c
+++ b/src/common/fdset.c
@@ -1,20 +1,20 @@
-#include "os_fdset.h"
+#include "fdset.h"
 #include "config.h"
 
 /* Attempt to use epoll_wait(). */
 #ifdef HAVE_EPOLL_WAIT
-  #include "os_fdset_epoll.c"
+  #include "fdset_epoll.c"
 #else
   /* Attempt to use kqueue(). */
   #ifdef HAVE_KQUEUE
-    #warning "os_fdset: kqueue backend N/A, fallback to poll()"
-    #include "os_fdset_poll.c"
+    #warning "fdset: kqueue backend N/A, fallback to poll()"
+    #include "fdset_poll.c"
   #else
     /* poll() API */
     #ifdef HAVE_POLL
-      #include "os_fdset_poll.c"
+      #include "fdset_poll.c"
     #else
-      #error "os_fdset: no socket polling API found"
+      #error "fdset: no socket polling API found"
     #endif /* HAVE_POLL */
   #endif /* HAVE_KQUEUE */
 #endif /* HAVE_EPOLL_WAIT */
@@ -24,12 +24,12 @@
 //#include <stdio.h>
 //#define _GNU_SOURCE /* Required for RTLD_DEFAULT. */
 //#include <dlfcn.h>
-//void __attribute__ ((constructor)) os_fdset_init()
+//void __attribute__ ((constructor)) fdset_init()
 //{
 //	int poll_ok = dlsym(RTLD_DEFAULT, "poll") != 0;
 //	int epoll_ok = dlsym(RTLD_DEFAULT, "epoll_wait") != 0;
 //	int kqueue_ok = dlsym(RTLD_DEFAULT, "kqueue") != 0;
 
 //	fprintf(stderr, "using polling subsystem %s (poll %d epoll %d kqueue %d)\n",
-//		os_fdset_method(), poll_ok, epoll_ok, kqueue_ok);
+//		fdset_method(), poll_ok, epoll_ok, kqueue_ok);
 //}
diff --git a/src/common/os_fdset.h b/src/common/fdset.h
similarity index 96%
rename from src/common/os_fdset.h
rename to src/common/fdset.h
index 53fb9d06c5..500f5d6018 100644
--- a/src/common/os_fdset.h
+++ b/src/common/fdset.h
@@ -1,5 +1,5 @@
 /*!
- * \file os_fdset.h
+ * \file fdset.h
  *
  * \author Marek Vavrusa <marek.vavrusa@nic.cz>
  *
@@ -15,8 +15,8 @@
  * @{
  */
 
-#ifndef _KNOTD_OS_FDSET_H_
-#define _KNOTD_OS_FDSET_H_
+#ifndef _KNOTD_FDSET_H_
+#define _KNOTD_FDSET_H_
 
 #include <stddef.h>
 
@@ -133,6 +133,6 @@ int fdset_next(fdset_t *fdset, fdset_it_t *it);
  */
 const char* fdset_method();
 
-#endif /* _KNOTD_OS_FDSET_H_ */
+#endif /* _KNOTD_FDSET_H_ */
 
 /*! @} */
diff --git a/src/common/os_fdset_epoll.c b/src/common/fdset_epoll.c
similarity index 99%
rename from src/common/os_fdset_epoll.c
rename to src/common/fdset_epoll.c
index 90977934bd..6067770bcd 100644
--- a/src/common/os_fdset_epoll.c
+++ b/src/common/fdset_epoll.c
@@ -3,7 +3,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#include "os_fdset.h"
+#include "fdset.h"
 
 #define OS_FDS_CHUNKSIZE 8   /*!< Number of pollfd structs in a chunk. */
 #define OS_FDS_KEEPCHUNKS 32 /*!< Will attempt to free memory when reached. */
diff --git a/src/common/os_fdset_poll.c b/src/common/fdset_poll.c
similarity index 99%
rename from src/common/os_fdset_poll.c
rename to src/common/fdset_poll.c
index 29365b2f94..d7f2035c9b 100644
--- a/src/common/os_fdset_poll.c
+++ b/src/common/fdset_poll.c
@@ -3,7 +3,7 @@
 #include <sys/poll.h>
 #include <stddef.h>
 
-#include "os_fdset.h"
+#include "fdset.h"
 
 #define OS_FDS_CHUNKSIZE 8   /*!< Number of pollfd structs in a chunk. */
 #define OS_FDS_KEEPCHUNKS 32 /*!< Will attempt to free memory when reached. */
diff --git a/src/tests/common/os_fdset_tests.c b/src/tests/common/fdset_tests.c
similarity index 73%
rename from src/tests/common/os_fdset_tests.c
rename to src/tests/common/fdset_tests.c
index 9b2f7e1f44..10f940f5fa 100644
--- a/src/tests/common/os_fdset_tests.c
+++ b/src/tests/common/fdset_tests.c
@@ -3,8 +3,8 @@
 #include <sys/time.h>
 #include <pthread.h>
 
-#include "tests/common/os_fdset_tests.h"
-#include "common/os_fdset.h"
+#include "tests/common/fdset_tests.h"
+#include "common/fdset.h"
 
 #define WRITE_PATTERN ((char) 0xde)
 #define WRITE_PATTERN_LEN sizeof(char)
@@ -44,15 +44,15 @@ static size_t timeval_diff(struct timeval *from, struct timeval *to) {
 	return res.tv_sec*1000 + res.tv_usec/1000;
 }
 
-static int os_fdset_tests_count(int argc, char *argv[]);
-static int os_fdset_tests_run(int argc, char *argv[]);
+static int fdset_tests_count(int argc, char *argv[]);
+static int fdset_tests_run(int argc, char *argv[]);
 
 /*! Exported unit API.
  */
-unit_api os_fdset_tests_api = {
+unit_api fdset_tests_api = {
 	"Native fdset poll wrapper",   //! Unit name
-	&os_fdset_tests_count,  //! Count scheduled tests
-	&os_fdset_tests_run     //! Run scheduled tests
+	&fdset_tests_count,  //! Count scheduled tests
+	&fdset_tests_run     //! Run scheduled tests
 };
 
 void* thr_action(void *arg)
@@ -73,28 +73,28 @@ void* thr_action(void *arg)
 	return 0;
 }
 
-static int os_fdset_tests_count(int argc, char *argv[])
+static int fdset_tests_count(int argc, char *argv[])
 {
 	return 11;
 }
 
-static int os_fdset_tests_run(int argc, char *argv[])
+static int fdset_tests_run(int argc, char *argv[])
 {
-	diag("os_fdset: implements '%s'", fdset_method());
+	diag("fdset: implements '%s'", fdset_method());
 
 	/* 1. Create fdset. */
 	fdset_t *set = fdset_new();
-	ok(set != 0, "os_fdset: new");
+	ok(set != 0, "fdset: new");
 
 	/* 2. Create pipe. */
 	int fds[2], tmpfds[2];
 	int ret = pipe(fds);
-	ok(ret >= 0, "os_fdset: pipe() works");
+	ok(ret >= 0, "fdset: pipe() works");
 	ret = pipe(tmpfds);
 
 	/* 3. Add fd to set. */
 	ret = fdset_add(set, fds[0], OS_EV_READ);
-	ok(ret == 0, "os_fdset: add to set works");
+	ok(ret == 0, "fdset: add to set works");
 	fdset_add(set, tmpfds[0], OS_EV_READ);
 
 	/* Schedule write. */
@@ -109,25 +109,25 @@ static int os_fdset_tests_run(int argc, char *argv[])
 	size_t diff = timeval_diff(&ts, &te);
 
 	ok(ret > 0 && diff > 99 && diff < 10000,
-	   "os_fdset: poll returned events in %zu ms", diff);
+	   "fdset: poll returned events in %zu ms", diff);
 
 	/* 5. Prepare event set. */
 	fdset_it_t it;
 	ret = fdset_begin(set, &it);
-	ok(ret == 0 && it.fd == fds[0], "os_fdset: begin is valid, ret=%d", ret);
+	ok(ret == 0 && it.fd == fds[0], "fdset: begin is valid, ret=%d", ret);
 
 	/* 6. Receive data. */
 	char buf = 0x00;
 	ret = read(it.fd, &buf, WRITE_PATTERN_LEN);
-	ok(ret >= 0 && buf == WRITE_PATTERN, "os_fdset: contains valid data, fd=%d", it.fd);
+	ok(ret >= 0 && buf == WRITE_PATTERN, "fdset: contains valid data, fd=%d", it.fd);
 
 	/* 7. Iterate event set. */
 	ret = fdset_next(set, &it);
-	ok(ret < 0, "os_fdset: boundary check works");
+	ok(ret < 0, "fdset: boundary check works");
 
 	/* 8. Remove from event set. */
 	ret = fdset_remove(set, fds[0]);
-	ok(ret == 0, "os_fdset: remove from fdset works");
+	ok(ret == 0, "fdset: remove from fdset works");
 	close(fds[0]);
 	close(fds[1]);
 	ret = fdset_remove(set, tmpfds[0]);
@@ -136,7 +136,7 @@ static int os_fdset_tests_run(int argc, char *argv[])
 
 	/* 9. Poll empty fdset. */
 	ret = fdset_wait(set);
-	ok(ret <= 0, "os_fdset: polling empty fdset returns -1 (ret=%d)", ret);
+	ok(ret <= 0, "fdset: polling empty fdset returns -1 (ret=%d)", ret);
 
 	/* 10. Crash test. */
 	lives_ok({
@@ -148,11 +148,11 @@ static int os_fdset_tests_run(int argc, char *argv[])
 		 fdset_end(0, 0);
 		 fdset_next(0, 0);
 		 fdset_method();
-	}, "os_fdset: crash test successful");
+	}, "fdset: crash test successful");
 
 	/* 11. Destroy fdset. */
 	ret = fdset_destroy(set);
-	ok(ret == 0, "os_fdset: destroyed");
+	ok(ret == 0, "fdset: destroyed");
 
 	/* Cleanup. */
 	pthread_join(t, 0);
diff --git a/src/tests/common/fdset_tests.h b/src/tests/common/fdset_tests.h
new file mode 100644
index 0000000000..5c8db291ac
--- /dev/null
+++ b/src/tests/common/fdset_tests.h
@@ -0,0 +1,9 @@
+#ifndef _KNOTD_FDSET_TESTS_H_
+#define _KNOTD_FDSET_TESTS_H_
+
+#include "common/libtap/tap_unit.h"
+
+/* Unit API. */
+unit_api fdset_tests_api;
+
+#endif /* _KNOTD_FDSET_TESTS_H_ */
diff --git a/src/tests/common/os_fdset_tests.h b/src/tests/common/os_fdset_tests.h
deleted file mode 100644
index 087fc9278c..0000000000
--- a/src/tests/common/os_fdset_tests.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef _KNOTD_OS_FDSET_TESTS_H_
-#define _KNOTD_OS_FDSET_TESTS_H_
-
-#include "common/libtap/tap_unit.h"
-
-/* Unit API. */
-unit_api os_fdset_tests_api;
-
-#endif /* _KNOTD_OS_FDSET_TESTS_H_ */
diff --git a/src/tests/unittests_main.c b/src/tests/unittests_main.c
index 7d023977c7..4deee8b4ad 100644
--- a/src/tests/unittests_main.c
+++ b/src/tests/unittests_main.c
@@ -8,7 +8,7 @@
 #include "tests/common/events_tests.h"
 #include "tests/common/da_tests.h"
 #include "tests/common/acl_tests.h"
-#include "tests/common/os_fdset_tests.h"
+#include "tests/common/fdset_tests.h"
 #include "tests/knot/dthreads_tests.h"
 #include "tests/knot/journal_tests.h"
 #include "tests/knot/server_tests.h"
@@ -31,7 +31,7 @@ int main(int argc, char *argv[])
 		&events_tests_api,   //! Events testing unit
 		&da_tests_api,       //! Dynamic array unit
 		&acl_tests_api,      //! ACLs
-		&os_fdset_tests_api, //! FDSET polling wrapper
+		&fdset_tests_api, //! FDSET polling wrapper
 
 		/* Server parts. */
 		&conf_tests_api,     //! Configuration parser tests
-- 
GitLab