Skip to content
Snippets Groups Projects

First unit tests

Merged Leon Dietrich requested to merge first_unit_tests into master

Bugs that still remain:

  • The socketaddr factory (DNS lookup) does not yet seam to be fully functional.
  • UDP socket test needs to pass
  • TCP socket test needs to pass
  • Unit Test for socketaddr Factory lookups
  • Segfault at test shutdown needs to be fixed.
  • fcntl needs to be checked for correct flag retuns
Edited by Leon Dietrich

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 30 30 void rmrf::ev::loop() {
    31 31 ::ev::default_loop defloop;
    32 32
    33 33 auto w = std::make_shared<stdin_waiter>();
  • 34 34
    35 35 defloop.run(0);
    36 36 }
    37
    38 void stop_default_loop_cb(EV_P_ ev_async*, int) {
    39 ::ev::loop_ref defloop = ::ev::get_default_loop();
    40 defloop.break_loop();
    41 }
    42
    43 void rmrf::ev::stop() {
    44 ::ev::loop_ref defloop = ::ev::get_default_loop();
    45 // We need to use the C API directly as ev++ does not yet support asynchrounous events
    46 ev_async stop_event;
    47 ev_async_init(&stop_event, stop_default_loop_cb);
    48 ev_async_start(defloop, &stop_event);
    49 ev_async_send(defloop, &stop_event);
    • Comment on lines +45 to +49

      Any chance of creating our own OOP wrapper classes for this as shims we can replace with the real API once it becomes available?

    • Do you mean our own C++ wrapper for libev? I don't think that would be necessary as they're other competing wrappers around and one might be better.

    • Not a full wrapper, but a minor supplement providing the missing stuff.

      If you know/find another one that is more complete AND packaged on Debian/Ubuntu/available on (most) *BSD go ahead.

      Point here is mostly about avoiding to mix API between a lib and its wrapper as this is prone to cause issues down the line. The supplement approach at least allows to keep essential changes in a central place if implementation needs to change and allows to drop things once the upstream library provides the missing interfaces (with minimal code changes).

    • Benny Baumann changed this line in version 6 of the diff

      changed this line in version 6 of the diff

    • Please register or sign in to reply
  • 4 4
    5 5 namespace rmrf::net {
    6 6
    7 /**
    8 * @class null_fd
    9 * @author leondietrich
    10 * @date 07/08/21
  • 12 19 constexpr operator int() const { return -1; }
    13 20 };
    14 21
    22 /**
    23 * Instantiate a null FD.
    24 */
    15 25 constexpr null_fd nullfd{};
    16 26
    27 /**
    28 * Automatic file descriptor. This class wraps raw file descriptors and handles their
    29 * life time.
    30 * @class auto_fd
    31 * @author leondietrich
    32 * @date 07/08/21
  • Benny Baumann
  • Benny Baumann
  • Benny Baumann
  • Benny Baumann
  • 46 85 return r;
    47 86 }
    48 87
    49 // Close an open file descriptor. Reset the descriptor to -1.
    88 /**
    89 * Use this method in order to manually close the resource associated with this file descriptor.
    90 * After this method was executed this file descriptor is invalid. Further calls to this method
    91 * won't do anything.
    • Suggested change
      90 * won't do anything.
      90 * will do anything.
    • Don't we check our self whether or not the fd is valid?

    • Yes. That's what that internal if is about. The change in wording avoids negation of the statement, which could be confusing to read. Unfortunately I mixed up things. Probably now without the possibility to mis-read this:

      Suggested change
      90 * won't do anything.
      90 * will do nothing.
    • Please register or sign in to reply
  • 9 9
    10 10 namespace rmrf::net {
    11 11
    12 /**
    13 * This class handles raw server sockets and wrapps them with automatic
    14 * resource management functions. This class is an internal helper class
    15 * utilized by classes like the TCP Server and thus shouldn't be used directly.
    16 * @class async_server_socket
    17 * @author leondietrich
    18 * @date 14/07/21
    19 * @file async_server.hpp
    20 * @brief An asynchronous server socket handler.
    21 * @see rmrf::net::tcp_server_socket
    22 */
    12 23 class async_server_socket : public std::enable_shared_from_this<async_server_socket> {
  • 25 36 ::ev::io io;
    26 37
    27 38 public:
    39
    40 /**
    41 * This constructor accepts your given file descriptor to the operating systems socket.
    42 * @param fd A handle to the socket in form of an auto_fd
    43 */
    28 44 async_server_socket(auto_fd &&fd);
    45
    46 /**
    47 * This deconstructor automatically unregisteres the socket from libev which in turn automatically removes it from
    48 * the watch list of active sockets. However this does not close the socket in the kernels perspective so you must
    49 * use always auto_fd.
  • 48 * the watch list of active sockets. However this does not close the socket in the kernels perspective so you must
    49 * use always auto_fd.
    50 * @brief Automatically unregister the socket from libev
    51 */
    29 52 ~async_server_socket();
    30 53
    31 accept_handler_type get_accept_handler() const;
    32 void set_accept_handler(const accept_handler_type &value);
    54 /**
    55 * This method will return the currently used connection acceptance handler.
    56 * Be aware that it will return an invalid state unless you used set_accept_handler
    57 * prior to calling this method.
    58 * @brief get the current registered accept handler
    59 * @return The current accept handler
    60 */
    61 inline accept_handler_type get_accept_handler() const {
  • 57 * prior to calling this method.
    58 * @brief get the current registered accept handler
    59 * @return The current accept handler
    60 */
    61 inline accept_handler_type get_accept_handler() const {
    62 return on_accept;
    63 }
    64
    65 /**
    66 * Use this method in order to set a new incomming socket acceptance handler.
    67 * It's best to call this method right after the constructor call of this class.
    68 * @brief Set a new acceptance handler
    69 * @param value The new handler to set
    70 */
    71 inline void set_accept_handler(
    72 const accept_handler_type& value) {
  • Benny Baumann
  • 17 23 public:
    24
    25 /**
    26 * This function type accepts a reference to the incomming data string which it may not alter
    27 * and may not return any data.
    28 */
    18 29 typedef std::function<void(const std::string&)> incomming_data_cb;
    19 30 protected:
    20 31 incomming_data_cb in_data_cb;
    21 32 public:
    22 connection_client();
    33 connection_client() : in_data_cb{} {};
    23 34
    24 35 /**
    25 36 * Use this method to send data to the other endpoint.
    37 * @param data The data to send
  • 4 4 * Created on: 05.01.2021
    5 5 * Author: doralitze
    6 6 */
    7
    7
    8 8 #include "net/connection_line_buffer.hpp"
    9 9
    10 10 namespace rmrf::net {
    11 11
    12 static std::string::size_type default_eol_search(const std::string& data, std::string::size_type start_position) {
    12 std::string::size_type default_eol_search(const std::string& data, std::string::size_type start_position) {
  • 36 37 client(c),
    37 38 found_next_line_cb(found_next_line_cb_),
    38 39 max(max_line_size),
    39 data("") {
    40 this->client->set_incomming_data_callback(std::bind(&connection_line_buffer::conn_data_in_cb, this, std::placeholders::_1));
    40 data_buffer(std::ostringstream::ate),
    41 buffer_length{0} {
    42 this->client->set_incomming_data_callback(
    43 [this](const std::string& data_in) {
    44 conn_data_in_cb(data_in);
    45 });
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading