~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to iocore/dns/SRV.h

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-05-09 01:00:04 UTC
  • mto: (1.1.11) (5.3.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: package-import@ubuntu.com-20130509010004-9fqq9n0adseg3f8w
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
struct HostDBInfo;
31
31
 
 
32
#define HOST_DB_MAX_ROUND_ROBIN_INFO  16
32
33
#define RAND_INV_RANGE(r) ((int) ((RAND_MAX + 1) / (r)))
33
34
 
34
 
class SRV
 
35
struct SRV
35
36
{
36
 
private:
37
37
  unsigned int weight;
38
38
  unsigned int port;
39
39
  unsigned int priority;
40
40
  unsigned int ttl;
 
41
  unsigned int host_len;
 
42
  unsigned int key;
41
43
  char host[MAXDNAME];
42
44
 
43
 
public:
44
 
  LINK(SRV, link);
45
 
  SRV():weight(0), port(0), priority(0), ttl(0)
46
 
  {
47
 
    memset(host, 0, MAXDNAME);
48
 
  }
49
 
 
50
 
  unsigned int getWeight()
51
 
  {
52
 
    return weight;
53
 
  }
54
 
  unsigned int getPriority() const
55
 
  {
56
 
    return priority;
57
 
  }
58
 
  unsigned int getPort()
59
 
  {
60
 
    return port;
61
 
  }
62
 
  unsigned int getTTL()
63
 
  {
64
 
    return ttl;
65
 
  }
66
 
  char *getHost()
67
 
  {
68
 
    return &host[0];
69
 
  }
70
 
 
71
 
  void setWeight(int w)
72
 
  {
73
 
    weight = w;
74
 
  }
75
 
  void setTTL(int t)
76
 
  {
77
 
    ttl = t;
78
 
  }
79
 
  void setPort(int p)
80
 
  {
81
 
    port = p;
82
 
  }
83
 
  void setPriority(int p)
84
 
  {
85
 
    priority = p;
86
 
  }
87
 
  void setHost(const char *h)
88
 
  {
89
 
    if (!h) {
90
 
      Debug("dns_srv", "SRV::setHost() was passed a NULL host -- better check your code)");
91
 
      host[0] = '\0';
92
 
      return;
93
 
    }
94
 
    if (*h == '\0') {
95
 
      Debug("dns_srv", "SRV::setHost() was passed a blank host -- better check what might have happened.");
96
 
      host[0] = '\0';
97
 
      return;
98
 
    }
99
 
    ink_strlcpy(host, h, sizeof(host));
100
 
  }
101
 
 
 
45
  SRV():weight(0), port(0), priority(0), ttl(0), host_len(0), key(0)
 
46
  {
 
47
    host[0] = '\0';
 
48
  }
102
49
};
103
50
 
104
 
TS_INLINE bool
105
 
operator<(const SRV & left, const SRV & right)
 
51
inline bool
 
52
operator<(const SRV &left, const SRV &right)
106
53
{
107
 
  return (left.getPriority() < right.getPriority());    /* lower priorities first :) */
 
54
  // lower priorities first, then the key
 
55
  return (left.priority == right.priority) ? (left.key < right.key) : (left.priority < right.priority);
108
56
}
109
57
 
110
 
extern ClassAllocator<SRV> SRVAllocator;
111
58
 
112
 
class SRVHosts
 
59
struct SRVHosts
113
60
{
114
 
private:
115
 
  SortableQueue<SRV> hosts;
116
61
  int srv_host_count;
 
62
  int srv_hosts_length;
 
63
  SRV hosts[HOST_DB_MAX_ROUND_ROBIN_INFO];
117
64
 
118
 
public:
119
65
   ~SRVHosts()
120
66
  {
121
 
    SRV *i;
122
 
    while ((i = hosts.dequeue())) {
123
 
      Debug("dns_srv", "freeing srv entry inside SRVHosts::~SRVHosts");
124
 
      SRVAllocator.free(i);
125
 
    }
126
 
  }
127
 
 
128
 
  SRVHosts():srv_host_count(0)
129
 
  {
130
 
    hosts.clear();
131
 
  }
132
 
 
133
 
  SortableQueue<SRV> *getHosts() {
134
 
    return &hosts;
135
 
  }
136
 
 
137
 
  void getWeightedHost(char *);
138
 
 
139
 
  bool insert(SRV * rec)
140
 
  {
141
 
    hosts.enqueue(rec);
142
 
    srv_host_count++;
143
 
    return true;
144
 
  }
145
 
 
146
 
  int getCount()
147
 
  {
148
 
    return srv_host_count;
149
 
  }
150
 
 
151
 
  /* convert this HostDBInfo to an SRVHosts */
152
 
  SRVHosts(HostDBInfo * info);
153
 
 
 
67
  }
 
68
 
 
69
  SRVHosts():srv_host_count(0), srv_hosts_length(0)
 
70
  {
 
71
  }
154
72
};
155
73
 
156
74
#endif