Skip to content
Snippets Groups Projects
Commit 87d33bd1 authored by Benny Baumann's avatar Benny Baumann
Browse files

add: Allow specifying target with socketaddress instance

parent 970283c7
No related branches found
No related tags found
1 merge request!1First unit tests
...@@ -38,6 +38,24 @@ tcp_client::tcp_client( ...@@ -38,6 +38,24 @@ tcp_client::tcp_client(
// TODO log created client // TODO log created client
} }
tcp_client::tcp_client(
const destructor_cb_type destructor_cb_,
auto_fd &&socket_fd,
const socketaddr &peer_address_
) :
connection_client{},
destructor_cb(destructor_cb_),
peer_address{peer_address_.str()},
port{},
net_socket(std::forward<auto_fd>(socket_fd)),
io{},
write_queue{}
{
io.set<tcp_client, &tcp_client::cb_ev>(this);
io.start(this->net_socket.get(), ::ev::READ);
// TODO log created client
}
tcp_client::tcp_client( tcp_client::tcp_client(
const std::string &peer_address_, const std::string &peer_address_,
const std::string &service_or_port, const std::string &service_or_port,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "net/async_fd.hpp" #include "net/async_fd.hpp"
#include "net/connection_client.hpp" #include "net/connection_client.hpp"
#include "net/ioqueue.hpp" #include "net/ioqueue.hpp"
#include "net/socketaddress.hpp"
namespace rmrf::net { namespace rmrf::net {
...@@ -41,7 +42,7 @@ public: ...@@ -41,7 +42,7 @@ public:
private: private:
const destructor_cb_type destructor_cb; const destructor_cb_type destructor_cb;
const std::string peer_address; std::string peer_address;
uint16_t port; uint16_t port;
auto_fd net_socket; auto_fd net_socket;
...@@ -62,6 +63,18 @@ public: ...@@ -62,6 +63,18 @@ public:
*/ */
tcp_client(const destructor_cb_type destructor_cb_, auto_fd&& socket_fd, std::string peer_address_, uint16_t port_); tcp_client(const destructor_cb_type destructor_cb_, auto_fd&& socket_fd, std::string peer_address_, uint16_t port_);
/**
* Construct a new TCP client using an already existing socket. This might be particulary useful if you've
* got a server and accept incoming connections.
*
* @brief Connect to a TCP server
* @param destructor_cb_ The callback that should be issued when the client closes or looses it's connection
* @param socket_fd A file descriptor for an already open socket to be wrapped by this client
* @param peer_address_ The address the socket is bound to on the other end of the connection
* @param port_ The bound port
*/
tcp_client(const destructor_cb_type destructor_cb_, auto_fd&& socket_fd, const socketaddr& peer_address_);
/** /**
* Construct a new TCP client using an address and port pair. * Construct a new TCP client using an address and port pair.
* @brief Connect to a TCP server * @brief Connect to a TCP server
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment