Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
connector.h
Go to the documentation of this file.
1
13// --------------------------------------------------------------------------
14// This file is part of the "sockpp" C++ socket library.
15//
16// Copyright (c) 2014-2019 Frank Pagliughi
17// All rights reserved.
18//
19// Redistribution and use in source and binary forms, with or without
20// modification, are permitted provided that the following conditions are
21// met:
22//
23// 1. Redistributions of source code must retain the above copyright notice,
24// this list of conditions and the following disclaimer.
25//
26// 2. Redistributions in binary form must reproduce the above copyright
27// notice, this list of conditions and the following disclaimer in the
28// documentation and/or other materials provided with the distribution.
29//
30// 3. Neither the name of the copyright holder nor the names of its
31// contributors may be used to endorse or promote products derived from this
32// software without specific prior written permission.
33//
34// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
35// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
36// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
38// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45// --------------------------------------------------------------------------
46
47#ifndef __sockpp_connector_h
48#define __sockpp_connector_h
49
51#include "sockpp/sock_address.h"
52
53namespace sockpp {
54
56
64{
66 using base = stream_socket;
67
68 // Non-copyable
69 connector(const connector&) =delete;
70 connector& operator=(const connector&) =delete;
71
72public:
82 connector(const sock_address& addr) { connect(addr); }
88 connector(connector&& conn) : base(std::move(conn)) {}
95 base::operator=(std::move(rhs));
96 return *this;
97 }
106 bool is_connected() const { return is_open(); }
114 bool connect(const sock_address& addr);
115};
116
118
122template <typename STREAM_SOCK, typename ADDR=typename STREAM_SOCK::addr_t>
124{
126 using base = connector;
127
128 // Non-copyable
129 connector_tmpl(const connector_tmpl&) =delete;
130 connector_tmpl& operator=(const connector_tmpl&) =delete;
131
132public:
134 using stream_sock_t = STREAM_SOCK;
136 using addr_t = ADDR;
137
147 connector_tmpl(const addr_t& addr) : base(addr) {}
154 base::operator=(std::move(rhs));
155 return *this;
156 }
162 addr_t address() const { return addr_t(base::address()); }
176 bool bind(const addr_t& addr) { return base::bind(addr); }
184 bool connect(const addr_t& addr) { return base::connect(addr); }
185};
186
188// end namespace sockpp
189}
190
191#endif // __sockpp_connector_h
192
Definition connector.h:124
ADDR addr_t
Definition connector.h:136
connector_tmpl()
Definition connector.h:141
addr_t peer_address() const
Definition connector.h:168
connector_tmpl & operator=(connector_tmpl &&rhs)
Definition connector.h:153
STREAM_SOCK stream_sock_t
Definition connector.h:134
bool connect(const addr_t &addr)
Definition connector.h:184
bool bind(const addr_t &addr)
Definition connector.h:176
connector_tmpl(const addr_t &addr)
Definition connector.h:147
addr_t address() const
Definition connector.h:162
Definition connector.h:64
connector(const sock_address &addr)
Definition connector.h:82
connector(connector &&conn)
Definition connector.h:88
bool connect(const sock_address &addr)
Definition connector.cpp:43
connector & operator=(connector &&rhs)
Definition connector.h:94
bool is_connected() const
Definition connector.h:106
connector()
Definition connector.h:76
Definition sock_address.h:65
bool is_open() const
Definition socket.h:238
bool bind(const sock_address &addr)
Definition socket.cpp:187
sock_address_any address() const
Definition socket.cpp:195
sock_address_any peer_address() const
Definition socket.cpp:210
Definition stream_socket.h:63
stream_socket & operator=(stream_socket &&rhs)
Definition stream_socket.h:122
stream_socket()
Definition stream_socket.h:85