libt2n-git Archives

Subject: C++ inter-process communication library branch, switch-to-epoll, updated. v0.7-11-g219c71d

From: libt2n-git@xxxxxxxxxxxxxxxxxxxxxxx
To: libt2n-git@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 9 Apr 2024 17:23:41 +0200 (CEST)
The branch, switch-to-epoll has been updated
  discards  ce9435ff3c290785e0263ae498597e2f834de8d5 (commit)
  discards  098b93440230d3533f316d73c7836be159ecd567 (commit)
  discards  e6a693de53b6cf7e384fe517458f972c65dbdb92 (commit)
       via  219c71d489d9ed1de6a5232f96f7f8a299e57d15 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (ce9435ff3c290785e0263ae498597e2f834de8d5)
            \
             N -- N -- N (219c71d489d9ed1de6a5232f96f7f8a299e57d15)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.


- Log -----------------------------------------------------------------
commit 219c71d489d9ed1de6a5232f96f7f8a299e57d15
Author: Gabriel Braga <gabriel.braga@xxxxxxxxxxxxx>
Date:   Tue Apr 9 16:48:19 2024 +0200

    Switch socket management API to epoll() (#7785)
    
    Previously all the server and client sockets were being managed by
    the select() API, which operates using a fixed amount of client
    sockets. This commit changes the code to adapt to the epoll() API.
    This commit also could have a performance improvement due to epoll's
    architecture.
    
    Note: next commits should fix:
        - The clock from sec to millisecs as the epoll_wait()
        uses millisecs.
        - Unit tests need to be changed to work properly.

-----------------------------------------------------------------------

Summary of changes:
 CMakeLists.txt          |    7 +++----
 src/command_client.cpp  |    8 ++++----
 src/monotonic_clock.cpp |   27 ++++++++++++++++++++-------
 src/monotonic_clock.hxx |    3 ++-
 src/server.cpp          |    4 ++--
 test/hello.cpp          |   12 ++++++------
 test/reentrant.cpp      |    2 +-
 test/timeout.cpp        |    4 ++--
 test/wrapper.cpp        |   14 +++++++-------
 9 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 74b3e4d..25f4754 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,9 +31,8 @@ include_directories(${XMLPP_INCLUDE_DIRS})
 link_directories(${XMLPP_LIBRARY_DIRS})
 
 # Documentation
-option(DOCUMENTATION "Generate API documentation with Doxygen" ON)
 find_package(Doxygen)
-if(DOXYGEN_FOUND AND DOCUMENTATION)
+if(DOXYGEN_FOUND)
    # Find doxy config
    message(STATUS "Doxygen found.")
    set(DOXY_DIR "${CMAKE_SOURCE_DIR}/doc")
@@ -62,9 +61,9 @@ if(DOXYGEN_FOUND AND DOCUMENTATION)
    add_custom_target(docs ALL DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html)
 
    message(STATUS "Generating API documentation with Doxygen.")
-else(DOXYGEN_FOUND AND DOCUMENTATION)
+else(DOXYGEN_FOUND)
    message(STATUS "Not generating API documentation.")
-endif(DOXYGEN_FOUND AND DOCUMENTATION)
+endif(DOXYGEN_FOUND)
 
 # Spec file
 configure_file(${CMAKE_SOURCE_DIR}/libt2n.spec.in 
${CMAKE_SOURCE_DIR}/libt2n.spec @ONLY)
diff --git a/src/command_client.cpp b/src/command_client.cpp
index ec4280f..0780f73 100644
--- a/src/command_client.cpp
+++ b/src/command_client.cpp
@@ -128,9 +128,9 @@ std::string command_client::read_packet(const int 
&millisec_timeout)
 
     while(!(got_packet=c->get_packet(resultpacket)) && my_timeout > 0  && 
!c->is_closed())
     {
-        timeout_checkpoint=monotonic_clock_gettime_msec();
+        timeout_checkpoint=monotonic_clock_gettime_sec();
         c->fill_buffer(millisec_timeout);
-        my_timeout -= abs(monotonic_clock_gettime_msec() - timeout_checkpoint);
+        my_timeout -= abs(monotonic_clock_gettime_sec() - timeout_checkpoint);
     }
 
 
@@ -151,9 +151,9 @@ void command_client::read_hello()
     int my_timeout=hello_timeout_millisec, timeout_checkpoint;
     while(!(got_packet=c->get_packet(resultpacket)) && my_timeout > 0  && 
!c->is_closed())
     {
-        timeout_checkpoint=monotonic_clock_gettime_msec();
+        timeout_checkpoint=monotonic_clock_gettime_sec();
         c->fill_buffer(my_timeout);
-        my_timeout -= abs(monotonic_clock_gettime_msec() - timeout_checkpoint);
+        my_timeout -= abs(monotonic_clock_gettime_sec() - timeout_checkpoint);
 
         c->peek_packet(resultpacket);
         check_hello(resultpacket);           // will throw before timeout if 
wrong data received
diff --git a/src/monotonic_clock.cpp b/src/monotonic_clock.cpp
index 7445f14..3b4e720 100644
--- a/src/monotonic_clock.cpp
+++ b/src/monotonic_clock.cpp
@@ -26,18 +26,31 @@ on this file might be covered by the GNU General Public 
License.
 
 /**
  * @brief fetches the value from the monotonic clock source.
- * @return the time since system start in milliseconds, -1 if read was 
unsuccessful
+ * @param[out] seconds the seconds.
+ * @param[out] nano_seconds the nano seconds.
+ * @return @a true if the clock was successfully read.
  */
-int monotonic_clock_gettime_msec()
+bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds)
 {
     struct timespec tp[1];
-    int millisec, nano_seconds;
     int res= clock_gettime (CLOCK_MONOTONIC, tp);
     if (0 == res)
     {
+        seconds= tp->tv_sec;
         nano_seconds= tp->tv_nsec;
-        millisec = nano_seconds/1000000;
-        return millisec;
     }
-    return -1;
-}
\ No newline at end of file
+    return (res==0);
+}
+
+/**
+ * @brief fetches the value from the monotonic clock source.
+ * @return the time since system start in seconds, 0 if read was unsuccessful
+ */
+int monotonic_clock_gettime_sec()
+{
+    long int seconds=0;
+    long int nano_seconds;
+
+    monotonic_clock_gettime(seconds,nano_seconds);
+    return seconds;
+}
diff --git a/src/monotonic_clock.hxx b/src/monotonic_clock.hxx
index f5c4830..98a9583 100644
--- a/src/monotonic_clock.hxx
+++ b/src/monotonic_clock.hxx
@@ -22,6 +22,7 @@ on this file might be covered by the GNU General Public 
License.
 #ifndef __LIBT2N_MONOTONIC_CLOCK
 #define __LIBT2N_MONOTONIC_CLOCK
 
-int monotonic_clock_gettime_msec();
+bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds);
+int monotonic_clock_gettime_sec();
 
 #endif
\ No newline at end of file
diff --git a/src/server.cpp b/src/server.cpp
index 45f8672..c61dbf4 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -66,7 +66,7 @@ std::ostream* 
server_connection::get_logstream(log_level_values level)
 /// check if timeout is expired, close connection if so
 void server_connection::check_timeout()
 {
-    if (timeout != -1 && last_action_time+timeout < 
monotonic_clock_gettime_msec())
+    if (timeout != -1 && last_action_time+timeout < 
monotonic_clock_gettime_sec())
     {
         LOGSTREAM(debug,"timeout on connection " << connection_id << ", 
closing");
         this->close();
@@ -76,7 +76,7 @@ void server_connection::check_timeout()
 /// reset the timeout, e.g. if something is received
 void server_connection::reset_timeout()
 {
-    last_action_time=monotonic_clock_gettime_msec();
+    last_action_time=monotonic_clock_gettime_sec();
 }
 
 /** @brief add a callback to one connection
diff --git a/test/hello.cpp b/test/hello.cpp
index a7a885d..48ccf5c 100644
--- a/test/hello.cpp
+++ b/test/hello.cpp
@@ -146,7 +146,7 @@ BOOST_AUTO_TEST_CASE(BadTag)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constuctor_exception();
+            t2n_exception* ep=cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(BadVersion)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constuctor_exception();
+            t2n_exception* ep=cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -263,7 +263,7 @@ BOOST_AUTO_TEST_CASE(SeparatorMissing)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constuctor_exception();
+            t2n_exception* ep=cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -330,7 +330,7 @@ BOOST_AUTO_TEST_CASE(WrongByteOrder)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constuctor_exception();
+            t2n_exception* ep=cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -386,7 +386,7 @@ BOOST_AUTO_TEST_CASE(OtherServerBig)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constuctor_exception();
+            t2n_exception* ep=cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -442,7 +442,7 @@ BOOST_AUTO_TEST_CASE(OtherServerSmall)
 
             command_client cc(&sc);
 
-            t2n_exception* ep=cc.get_constuctor_exception();
+            t2n_exception* ep=cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
diff --git a/test/reentrant.cpp b/test/reentrant.cpp
index 204e741..c03e330 100644
--- a/test/reentrant.cpp
+++ b/test/reentrant.cpp
@@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(ReentrantServer)
 
                 long long maxtime=1000000;
                 while(maxtime > 0)
-                    cs.handle(maxtime,&maxtime);
+                    cs.handle(maxtime);
             }
 
             global_server = NULL;
diff --git a/test/timeout.cpp b/test/timeout.cpp
index 936cc6a..1eb9e5b 100644
--- a/test/timeout.cpp
+++ b/test/timeout.cpp
@@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(HelloTimeoutNothing)
             socket_client_connection sc("./socket");
             command_client cc(&sc,1000000,1000000);
 
-            t2n_exception* ep=cc.get_constuctor_exception();
+            t2n_exception* ep=cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
@@ -301,7 +301,7 @@ BOOST_AUTO_TEST_CASE(HelloTimeoutSlowData)
             socket_client_connection sc("./socket");
             command_client cc(&sc,1000000,1000000);
 
-            t2n_exception* ep=cc.get_constuctor_exception();
+            t2n_exception* ep=cc.get_constructor_exception();
 
             string errormsg;
             if (ep)
diff --git a/test/wrapper.cpp b/test/wrapper.cpp
index 5fedaf5..f7dcb88 100644
--- a/test/wrapper.cpp
+++ b/test/wrapper.cpp
@@ -202,8 +202,8 @@ class cmd_group_x_client : public command_client
 {
     public:
         cmd_group_x_client(libt2n::client_connection *_c,
-         long long _command_timeout_usec=command_timeout_usec_default,
-         long long _hello_timeout_usec=hello_timeout_usec_default)
+         long long _command_timeout_usec=command_timeout_millisec_default,
+         long long _hello_timeout_usec=hello_timeout_millisec_default)
          : libt2n::command_client(_c,_command_timeout_usec,_hello_timeout_usec)
         {}
 
@@ -358,8 +358,8 @@ BOOST_AUTO_TEST_CASE(reconnect_after_close)
     wraptype::set_connection(auto_ptr<ConnectionWrapper>
         (new ReconnectSocketWrapper("./socket")));
 
-    wraptype::get_connection_wrapper()->set_command_timeout_usec(3000000);
-    wraptype::get_connection_wrapper()->set_hello_timeout_usec(3000000);
+    wraptype::get_connection_wrapper()->set_command_timeout_millisec(3000000);
+    wraptype::get_connection_wrapper()->set_hello_timeout_millisec(3000000);
 
     // 42 closes connection on the server side
     t2n_exec(&cmd_group_x_client::serverfunc)(42);
@@ -406,8 +406,8 @@ BOOST_AUTO_TEST_CASE(ignore_handler_reconnects)
     wraptype::set_connection(auto_ptr<ConnectionWrapper>
         (new ReconnectIgnoreFailureSocketWrapper("./socket")));
 
-    wraptype::get_connection_wrapper()->set_command_timeout_usec(3000000);
-    wraptype::get_connection_wrapper()->set_hello_timeout_usec(3000000);
+    wraptype::get_connection_wrapper()->set_command_timeout_millisec(3000000);
+    wraptype::get_connection_wrapper()->set_hello_timeout_millisec(3000000);
 
     // 42 closes connection on the server side
     t2n_exec(&cmd_group_x_client::serverfunc)(42);
@@ -493,7 +493,7 @@ BOOST_AUTO_TEST_CASE(ignore_finds_lateserver)
         // parent
         {
             // wait till server is up
-            sleep(1);
+            sleep(2);
         }
     }
 


hooks/post-receive
-- 
C++ inter-process communication library

--
libt2n-git - see http://www.intra2net.com/en/developer/libt2n for details.
To unsubscribe send a mail to libt2n-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • C++ inter-process communication library branch, switch-to-epoll, updated. v0.7-11-g219c71d, libt2n-git <=