First unit tests
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
Merge request reports
Activity
requested review from @benbe
assigned to @doralitze
- Resolved by Leon Dietrich
30 30 void rmrf::ev::loop() { 31 31 ::ev::default_loop defloop; 32 32 33 33 auto w = std::make_shared<stdin_waiter>(); changed this line in version 6 of the diff
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); 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).
changed this line in version 6 of the diff
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 - Resolved by Leon Dietrich
- Resolved by Leon Dietrich
- Resolved by Leon Dietrich
- Resolved by Leon Dietrich
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. 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. changed this line in version 6 of the diff
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 { changed this line in version 34 of the diff
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) { changed this line in version 6 of the diff
- Resolved by Leon Dietrich
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 changed this line in version 6 of the diff
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) { changed this line in version 34 of the diff
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 }); - Comment on lines +43 to +45
Performance note: Check if a reference or const reference to
this
suffices for this callback to avoid calling the copy ctor here.Edited by Benny Baumann changed this line in version 31 of the diff