ARC SDK
HostnameResolver.h
1 #ifndef __ARC_HOSTNAMERESOLVER_H__
2 #define __ARC_HOSTNAMERESOLVER_H__
3 
4 #include <string>
5 #include <list>
6 
7 #include <unistd.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 
12 #include <glibmm.h>
13 
14 namespace Arc {
15 
16  class Run;
17 
19 
24  public:
25 
26 
27  class SockAddr {
28  friend class HostnameResolver;
29  public:
30  SockAddr();
31  SockAddr(SockAddr const& other);
32  SockAddr& operator=(SockAddr const& other);
33  ~SockAddr();
34  int Family() const { return family; }
35  sockaddr const* Addr() const { return addr; }
36  socklen_t Length() const { return length; }
37  private:
38  int family;
39  socklen_t length;
40  sockaddr *addr;
41  };
42 
44  HostnameResolver(void);
46  ~HostnameResolver(void);
48  static HostnameResolver* Acquire(void);
50  static void Release(HostnameResolver* fa);
52  bool ping(void);
54  int hr_resolve(std::string const& node, std::string const& service, bool local, std::list<SockAddr>& addrs);
56  int geterrno() { return errno_; };
58  operator bool(void) { return (hostname_resolver_ != NULL); };
60  bool operator!(void) { return (hostname_resolver_ == NULL); };
62  static void testtune(void);
63  private:
64  Glib::Mutex lock_;
65  Run* hostname_resolver_;
66  int errno_;
67  public:
69  typedef struct {
70  unsigned int size;
71  unsigned int cmd;
72  } header_t;
73  };
74 
76 
82  public:
84  HostnameResolverContainer(unsigned int minval, unsigned int maxval);
90 
95 
97  void Release(HostnameResolver* hr);
99  void SetMin(unsigned int val);
101  void SetMax(unsigned int val);
102  private:
103  Glib::Mutex lock_;
104  unsigned int min_;
105  unsigned int max_;
106  std::list<HostnameResolver*> hrs_;
107  void KeepRange(void);
108  };
109 
110 } // namespace Arc
111 
112 #endif // __ARC_HOSTNAMERESOLVER_H__
113 
Arc namespace contains all core ARC classes.
Definition: ArcConfig.h:11
bool operator!(void)
Returns true if this instance is not in useful condition.
Definition: HostnameResolver.h:60
HostnameResolverContainer(void)
Creates container with number of stored objects between 1 and 10.
void Release(HostnameResolver *hr)
Returns object into container.
Definition: HostnameResolver.h:27
Container for shared HostnameResolver objects.
Definition: HostnameResolver.h:81
HostnameResolver(void)
New HostnameResolver object.
Internal struct used for communication between processes.
Definition: HostnameResolver.h:69
static void Release(HostnameResolver *fa)
Destructor which returns object into global cache.
~HostnameResolverContainer(void)
Destroys container and all stored objects.
HostnameResolver * Acquire(void)
Get object from container.
static HostnameResolver * Acquire(void)
Constructor which takes already existing object from global cache.
int geterrno()
Get errno of last operation. Every operation resets errno.
Definition: HostnameResolver.h:56
Defines interface for accessing filesystems.
Definition: HostnameResolver.h:23
void SetMin(unsigned int val)
Adjust minimal number of stored objects.
void SetMax(unsigned int val)
Adjust maximal number of stored objects.
bool ping(void)
Check if communication with proxy works.
static void testtune(void)
Special method for using in unit tests.
int hr_resolve(std::string const &node, std::string const &service, bool local, std::list< SockAddr > &addrs)
Performs resolution of provided host name.
~HostnameResolver(void)
Shuts down any spawned executable.
This class runs an external executable.
Definition: Run.h:19