]> git.tdb.fi Git - libs/net.git/blob - source/sockaddr.h
Don't close socket on Communicator error
[libs/net.git] / source / sockaddr.h
1 #ifndef MSP_NET_SOCKADDR_H_
2 #define MSP_NET_SOCKADDR_H_
3
4 #include <string>
5 #ifndef WIN32
6 #include <sys/socket.h>
7 #endif
8 #include "constants.h"
9
10 namespace Msp {
11 namespace Net {
12
13 class SockAddr
14 {
15 protected:
16         SockAddr() { }
17 public:
18         virtual ~SockAddr() { }
19
20         static SockAddr *create(const sockaddr &sa) { return create(reinterpret_cast<const sockaddr_storage &>(sa)); }
21         static SockAddr *create(const sockaddr_storage &);
22
23         virtual SockAddr *copy() const = 0;
24
25         virtual Family get_family() const = 0;
26         virtual std::string str() const = 0;
27
28         /** Fills a struct sockaddr with information from this SockAddr.  Returns
29         the number of bytes used. */
30         virtual unsigned fill_sockaddr(sockaddr &) const = 0;
31         virtual unsigned fill_sockaddr(sockaddr_storage &) const;
32 };
33
34 } // namespace Net
35 } // namespace Msp
36
37 #endif