~percona-dev/percona-server/release-5.5.11-20.2-fix-bug-764138

« back to all changes in this revision

Viewing changes to HandlerSocket-Plugin-for-MySQL/libhsclient/auto_addrinfo.hpp

  • Committer: Ignacio Nin
  • Date: 2011-03-13 17:18:23 UTC
  • mfrom: (33.3.17 release-5.5.8-20)
  • Revision ID: ignacio.nin@percona.com-20110313171823-m06xs104nekulywb
Merge changes from release-5.5.8-20 to 5.5.9

Merge changes from the release branch of 5.5.8 to 5.5.9. These include
the HandlerSocket and UDF directories and the building scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// vim:sw=2:ai
 
3
 
 
4
/*
 
5
 * Copyright (C) 2010 DeNA Co.,Ltd.. All rights reserved.
 
6
 * See COPYRIGHT.txt for details.
 
7
 */
 
8
 
 
9
#ifndef DENA_AUTO_ADDRINFO_HPP
 
10
#define DENA_AUTO_ADDRINFO_HPP
 
11
 
 
12
#include <sys/types.h>
 
13
#include <sys/socket.h>
 
14
#include <netdb.h>
 
15
 
 
16
#include "util.hpp"
 
17
 
 
18
namespace dena {
 
19
 
 
20
struct auto_addrinfo : private noncopyable {
 
21
  auto_addrinfo() : addr(0) { }
 
22
  ~auto_addrinfo() {
 
23
    reset();
 
24
  }
 
25
  void reset(addrinfo *a = 0) {
 
26
    if (addr != 0) {
 
27
      freeaddrinfo(addr);
 
28
    }
 
29
    addr = a;
 
30
  }
 
31
  const addrinfo *get() const { return addr; }
 
32
  int resolve(const char *node, const char *service, int flags = 0,
 
33
    int family = AF_UNSPEC, int socktype = SOCK_STREAM, int protocol = 0) {
 
34
    reset();
 
35
    addrinfo hints = { };
 
36
    hints.ai_flags = flags;
 
37
    hints.ai_family = family;
 
38
    hints.ai_socktype = socktype;
 
39
    hints.ai_protocol = protocol;
 
40
    return getaddrinfo(node, service, &hints, &addr);
 
41
  }
 
42
 private:
 
43
  addrinfo *addr;
 
44
};
 
45
 
 
46
};
 
47
 
 
48
#endif
 
49