NetCpp  v0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
dgram_local.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Evidence Srl - www.evidence.eu.com
3  *
4  * Boost Software License - Version 1.0 - August 17th, 2003
5  *
6  * Permission is hereby granted, free of charge, to any person or organization
7  * obtaining a copy of the software and accompanying documentation covered by
8  * this license (the "Software") to use, reproduce, display, distribute,
9  * execute, and transmit the Software, and to prepare derivative works of the
10  * Software, and to permit third-parties to whom the Software is furnished to
11  * do so, all subject to the following:
12  *
13  * The copyright notices in the Software and this entire statement, including
14  * the above license grant, this restriction and the following disclaimer,
15  * must be included in all copies of the Software, in whole or in part, and
16  * all derivative works of the Software, unless such copies or derivative
17  * works are solely in the form of machine-executable object code generated by
18  * a source language processor.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
23  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
24  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27  */
28 
29 #ifndef DGRAM_LOCAL_HPP_
30 #define DGRAM_LOCAL_HPP_
31 
32 #include <stdexcept>
33 
34 #include "abstract_socket.hpp"
35 #include "posix_socket.hpp"
36 #include "address.hpp"
37 #include "stream_local.hpp"
38 
39 namespace net {
40 namespace local {
41 namespace dgram {
42 
43 /// Address for local dgram communications.
45 
46 /**
47  * @brief Server for local dgram communications.
48  */
49 class server: public AbstractSocket {
50 public:
51  /**
52  * @brief Constructor
53  *
54  * This constructor allocates a concrete class
55  * derived from net::AbstractSystemSocket.
56  */
57  server():
59 
60  /**
61  * @brief Method to bind the server to an address
62  *
63  * This method invokes the platform-specific bind() operation.
64  * @param addr Address (i.e., net::local::dgram::address)
65  * which the server must be bound to
66  */
67  inline void bind (const Address& addr){
68  AbstractSocket::socket_->bind(addr);
69  }
70 
71  /**
72  * @brief Method to open the server towards a certain address
73  *
74  * This method calls net::local::dgram::server::bind(),
75  * which in turn invokes the platform-specific bind() operation.
76  * @param addr Address (i.e., net::local::dgram::address)
77  * that must be open by the server
78  */
79  inline void open (const Address& addr) {
80  bind(addr);
81  }
82 };
83 
84 
85 
86 /**
87  * @brief Client for local dgram communications.
88  */
89 class client: public AbstractSocket {
90 public:
91  /**
92  * @brief Constructor
93  *
94  * This constructor allocates a concrete class
95  * derived from net::AbstractSystemSocket.
96  */
97  client():
99 
100  /**
101  * @brief Method to connect the client to an address
102  *
103  * This method invokes the platform-specific connect() operation.
104  * @param addr Address (i.e., net::local::dgram::address)
105  * which the client must be connected to
106  */
107  inline void connect (const Address& addr){
108  AbstractSocket::socket_->connect(addr);
109  }
110 
111  /**
112  * @brief Method to open the client towards a certain address
113  *
114  * This method calls net::local::dgram::client::connect(),
115  * which in turn invokes the platform-specific bind() operation.
116  * @param addr Address (i.e., net::local::dgram::address)
117  * that must be open by the client
118  */
119  inline void open (const Address& addr) {
120  connect (addr);
121  }
122 
123 };
124 
125 
126 }}} // net::local::dgram
127 
128 #endif // DGRAM_LOCAL_HPP_