libBsdSockets
C++ Wrapper classes to the BSD Socket API
ClientSocket.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2013, Komodo Does Inc
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10 Neither the name of the Komodo Does Inc nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 
13 */
14 
15 #ifndef CLIENT_SOCKET_H
16 #define CLIENT_SOCKET_H
17 
18 #ifndef SOCKET_H
19 #include "Socket.h"
20 #endif // SOCKET_H
21 
22 namespace BsdSockets {
23 
24  /*
25  * Forward Declarations
26  */
27  class Address;
28 
29  /** \class ClientSocket
30  *
31  * \brief Client Socket providing ability to connect to and Address.
32  *
33  * This adds to Socket the ability to connetc() to an address.
34  */
35  class ClientSocket : public Socket {
36  public:
37  typedef std::shared_ptr<ClientSocket> Ptr;
38 
39  /** Closes socket. Virtual destructor to support derived classes. */
40  virtual ~ClientSocket();
41 
42  /** Create a ClientSocket to theAddress.
43  *
44  * \note The caller still needs to connect()
45  *
46  * @param theAddress to open and connect the ClientSocket to
47  *
48  * @return the ClientSocket
49  */
50  static ClientSocket::Ptr create(std::shared_ptr<Address> theAddress);
51 
52  /** Create and connect a ClientSocket to theAddress.
53  *
54  * @param theAddress to open the ClientSocket to
55  *
56  * @return the ClientSocket
57  */
58  static ClientSocket::Ptr open(std::shared_ptr<Address> theAddress);
59 
60  protected:
61  /** Create ClientSocket to support an address, saving it for connect().
62  *
63  * @param theAddress to create socket to use
64  */
65  ClientSocket(std::shared_ptr<Address> theAddress);
66 
67  private:
68  ClientSocket(const Socket& rhs) = delete;
69  ClientSocket(Socket&&) = delete;
70  ClientSocket& operator=(const Socket& rhs) = delete;
71  ClientSocket& operator=(Socket&& rhs) = delete;
72 
73  public:
74  /** Connect ClientSocket to the address. */
75  void connect() const;
76  };
77 
78 } // namespace BsdSockets
79 
80 #endif // CLIENT_SOCKET_H
Client Socket providing ability to connect to and Address.
Definition: ClientSocket.h:35
ClientSocket(std::shared_ptr< Address > theAddress)
static ClientSocket::Ptr open(std::shared_ptr< Address > theAddress)
static ClientSocket::Ptr create(std::shared_ptr< Address > theAddress)
std::shared_ptr< ClientSocket > Ptr
Definition: ClientSocket.h:37
BSD Socket base class providing the basic, common functionality between ServerSockets and ClientSocke...
Definition: Socket.h:66
Namespace of the BsdSockets library.
Definition: Address.cpp:20