monotone

monotone Mtn Source Tree

Root/netxx/peer.h

1/*
2 * Copyright (C) 2001-2004 Peter J Jones (pjones@pmade.org)
3 * All Rights Reserved
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 * 3. Neither the name of the Author nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
23 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33/** @file
34 * This file contains the definition of the Netxx::Peer class.
35**/
36
37#ifndef _netxx_peer_h_
38#define _netxx_peer_h_
39
40// Netxx includes
41#include <netxx/types.h>
42
43// standard includes
44#include <iosfwd>
45
46namespace Netxx {
47
48/**
49 * The Netxx::Peer class holds information about the Peer you are talking
50 * and/or connected to.
51**/
52class Peer {
53public:
54 //####################################################################
55 /**
56 * Default constructor for an invalid peer.
57 *
58 * @author Peter Jones
59 **/
60 //####################################################################
61 Peer (void);
62
63 //####################################################################
64 /**
65 * Constructor that takes the address of the peer.
66 *
67 * @param addr The string form of the peer's address
68 * @param port The peer's port.
69 * @param saddr The peer address struct.
70 * @param saddr_size The size of saddr.
71 * @author Peter Jones
72 **/
73 //####################################################################
74 Peer (const char *addr, port_type port, void *saddr, size_type saddr_size);
75
76 //####################################################################
77 /**
78 * Create a new Peer where the socket file descriptor used to
79 * communicate with the peer is given in socketfd and the sockaddr
80 * struct for the peer is given in saddr.
81 *
82 * @param socketfd The socket file descriptor for the peer.
83 * @param saddr The sockaddr struct for the peer.
84 * @param saddr_size The size of the saddr struct.
85 * @author Peter Jones
86 **/
87 //####################################################################
88 Peer (socket_type socketfd, void *saddr, size_type saddr_size);
89
90 //####################################################################
91 /**
92 * Copy constructor.
93 *
94 * @param other The other Peer class to copy from.
95 * @author Peter Jones
96 **/
97 //####################################################################
98 Peer (const Peer &other);
99
100 //####################################################################
101 /**
102 * Assignment operator.
103 *
104 * @param other The other Peer class to assign from.
105 * @author Peter Jones
106 **/
107 //####################################################################
108 Peer& operator= (const Peer &other);
109
110 //####################################################################
111 /**
112 * Swap this Peer class with another one.
113 *
114 * @param other Peer class to swap with.
115 * @author Peter Jones
116 **/
117 //####################################################################
118 void swap (Peer &other);
119
120 //####################################################################
121 /**
122 * Class destructor.
123 *
124 * @author Peter Jones
125 **/
126 //####################################################################
127 ~Peer (void);
128
129 //####################################################################
130 /**
131 * Get the string version of the address of the peer.
132 *
133 * @return The address of the peer.
134 * @author Peter Jones
135 **/
136 //####################################################################
137 const char* get_address (void) const;
138
139 //####################################################################
140 /**
141 * Get the port number for the peer.
142 *
143 * @return The port number of the peer.
144 * @author Peter Jones
145 **/
146 //####################################################################
147 port_type get_port (void) const;
148
149 //####################################################################
150 /**
151 * Get the local port number for the peer.
152 *
153 * @return The local port number of the peer.
154 * @author Alex Mitrofanov
155 **/
156 //####################################################################
157 port_type get_local_port (void) const;
158
159 //####################################################################
160 /**
161 * Get the socket file descriptor for this peer. This member function
162 * will return -1 if there is no socket file descriptor for this peer.
163 *
164 * @return The socket file descriptor or -1.
165 * @author Peter Jones
166 **/
167 //####################################################################
168 socket_type get_socketfd (void) const;
169
170 //####################################################################
171 /**
172 * Test to see if a peer is valid.
173 *
174 * @return True if the peer is valid.
175 * @return False if the peer is invalid.
176 * @author Peter Jones
177 **/
178 //####################################################################
179 operator bool (void) const;
180
181 //####################################################################
182 /**
183 * Get the sockaddr struct as a void pointer if this is a valid Peer
184 * object.
185 *
186 * @return A void pointer to the sockaddr struct.
187 * @return 0 If this Peer is invalid.
188 * @author Peter Jones
189 **/
190 //####################################################################
191 const void* get_sa (void) const;
192
193 //####################################################################
194 /**
195 * Get the size of the sockaddr struct if this is a valid Peer object.
196 *
197 * @return The size of the sockaddr struct.
198 * @return 0 If this Peer is invalid.
199 * @author Peter Jones
200 **/
201 //####################################################################
202 size_type get_sa_size (void) const;
203
204private:
205 bool okay_;
206 std::string addr_;
207 port_type port_;
208 socket_type socketfd_;
209 void *sockaddr_;
210 size_type sockaddr_size_;
211
212}; // end Netxx::Peer class
213
214//####################################################################
215/**
216 * Insert the string form of the peer into the given stream.
217 *
218 * @param stream The stream to insert the peer into.
219 * @param peer The peer to insert.
220 * @return The stream from the first param.
221 * @author Peter Jones
222**/
223//####################################################################
224std::ostream& operator<< (std::ostream &stream, const Peer &peer);
225
226} // end Netxx namespace
227#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status