nidas  v1.2-1520
UnixSocketAddress.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2006, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef NIDAS_UTIL_UNIXSOCKETADDRESS
28 #define NIDAS_UTIL_UNIXSOCKETADDRESS
29 
30 #include "SocketAddress.h"
31 #include <sys/un.h>
32 
33 namespace nidas { namespace util {
34 
40 public:
41 
45  // UnixSocketAddress();
46 
50  UnixSocketAddress(const std::string& path);
51 
55  UnixSocketAddress(const struct sockaddr_un* sockaddr);
56 
61 
66 
70  UnixSocketAddress* clone() const;
71 
75  int getFamily() const { return AF_UNIX; }
76 
80  int getPort() const { return -1; }
81 
88  struct sockaddr* getSockAddrPtr() { return (struct sockaddr*) &_sockaddr; }
89 
93  const struct sockaddr* getConstSockAddrPtr() const
94  {
95  return (const struct sockaddr*) &_sockaddr;
96  }
97 
98  socklen_t getSockAddrLen() const { return sizeof(_sockaddr); }
99 
103  std::string toString() const;
104 
108  std::string toAddressString() const;
109 
114  bool operator < (const SocketAddress& x) const;
115 
119  bool operator == (const SocketAddress& x) const;
120 
121 protected:
122  std::string _path;
123 
124  struct sockaddr_un _sockaddr;
125 };
126 
127 }} // namespace nidas namespace util
128 
129 #endif
int getPort() const
AF_UNIX addresses don&#39;t have ports, return -1.
Definition: UnixSocketAddress.h:80
std::string toAddressString() const
Java style toString: also returns &quot;unix:path&quot;.
Definition: UnixSocketAddress.cc:139
An interface for a socket address.
Definition: SocketAddress.h:36
bool operator<(const SocketAddress &x) const
Comparator operator for addresses.
Definition: UnixSocketAddress.cc:148
struct sockaddr * getConstSockAddrPtr() const
Provide const pointer to struct sockaddr_un.
Definition: UnixSocketAddress.h:93
struct sockaddr * getSockAddrPtr()
Provide non-const pointer to struct sockaddr_un.
Definition: UnixSocketAddress.h:88
socklen_t getSockAddrLen() const
Return the length of the struct sockaddr_XX for this address family.
Definition: UnixSocketAddress.h:98
bool operator==(const SocketAddress &x) const
Equality operator for addresses.
Definition: UnixSocketAddress.cc:158
UnixSocketAddress(const std::string &path)
Default constructor, path of &quot;&quot;, empty string.
Definition: UnixSocketAddress.cc:37
int getFamily() const
Return the address family, AF_UNIX.
Definition: UnixSocketAddress.h:75
UnixSocketAddress * clone() const
Virtual constructor.
Definition: UnixSocketAddress.cc:116
An AF_UNIX socket address.
Definition: UnixSocketAddress.h:39
struct sockaddr_un _sockaddr
Definition: UnixSocketAddress.h:124
std::string toString() const
Java style toString: returns &quot;unix:path&quot;.
Definition: UnixSocketAddress.cc:132
UnixSocketAddress & operator=(const UnixSocketAddress &x)
Assignment operator.
Definition: UnixSocketAddress.cc:122
std::string _path
Definition: UnixSocketAddress.h:122