~ubuntu-branches/ubuntu/saucy/curl/saucy-201307251546

« back to all changes in this revision

Viewing changes to lib/hostasyn.c

  • Committer: Bazaar Package Importer
  • Author(s): Ramakrishnan Muthukrishnan
  • Date: 2011-02-28 19:35:36 UTC
  • mto: (3.6.1 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20110228193536-p3a9jawxxofcsz7o
Tags: upstream-7.21.4
ImportĀ upstreamĀ versionĀ 7.21.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
73
73
#ifdef CURLRES_ASYNCH
74
74
 
75
75
/*
 
76
 * Cancel all possibly still on-going resolves for this connection.
 
77
 */
 
78
void Curl_async_cancel(struct connectdata *conn)
 
79
{
 
80
  /* If we have a "half" response already received, we first clear that off
 
81
     so that nothing is tempted to use it */
 
82
  if(conn->async.temp_ai) {
 
83
    Curl_freeaddrinfo(conn->async.temp_ai);
 
84
    conn->async.temp_ai = NULL;
 
85
  }
 
86
}
 
87
 
 
88
 
 
89
/*
76
90
 * Curl_addrinfo_callback() gets called by ares, gethostbyname_thread()
77
91
 * or getaddrinfo_thread() when we got the name resolved (or not!).
78
92
 *
82
96
 *
83
97
 * The storage operation locks and unlocks the DNS cache.
84
98
 */
85
 
CURLcode Curl_addrinfo_callback(struct connectdata * conn,
 
99
CURLcode Curl_addrinfo_callback(struct connectdata *conn,
86
100
                                int status,
87
101
                                struct Curl_addrinfo *ai)
88
102
{
95
109
    if(ai) {
96
110
      struct SessionHandle *data = conn->data;
97
111
 
 
112
#if defined(ENABLE_IPV6) && defined(CURLRES_ARES) /* CURLRES_IPV6 */
 
113
      Curl_addrinfo *ai_tail = ai;
 
114
 
 
115
      while (ai_tail->ai_next)
 
116
        ai_tail = ai_tail->ai_next;
 
117
 
 
118
      /* Add the new results to the list of old results. */
 
119
      ai_tail->ai_next = conn->async.temp_ai;
 
120
      conn->async.temp_ai = ai;
 
121
 
 
122
      if(--conn->async.num_pending > 0)
 
123
        /* We are not done yet. Just return. */
 
124
        return CURLE_OK;
 
125
 
 
126
      /* make sure the temp pointer is cleared and isn't pointing to something
 
127
         we take care of below */
 
128
      conn->async.temp_ai = NULL;
 
129
#endif
98
130
      if(data->share)
99
131
        Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
100
132
 
110
142
      if(data->share)
111
143
        Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
112
144
    }
113
 
    else
 
145
    else {
 
146
#if defined(ENABLE_IPV6) && defined(CURLRES_ARES) /* CURLRES_IPV6 */
 
147
      if(--conn->async.num_pending > 0) {
 
148
        /* We are not done yet. Clean up and return.
 
149
           This function will be called again. */
 
150
        if(conn->async.temp_ai) {
 
151
          Curl_freeaddrinfo(conn->async.temp_ai);
 
152
          conn->async.temp_ai = NULL;
 
153
        }
 
154
        return CURLE_OUT_OF_MEMORY;
 
155
      }
 
156
#endif
114
157
      rc = CURLE_OUT_OF_MEMORY;
115
 
  }
 
158
    }
 
159
  }
 
160
#if defined(ENABLE_IPV6) && defined(CURLRES_ARES) /* CURLRES_IPV6 */
 
161
  else
 
162
  {
 
163
      if(--conn->async.num_pending > 0)
 
164
        /* We are not done yet. Just return. */
 
165
        return CURLE_OK;
 
166
 
 
167
      if(conn->async.temp_ai) {
 
168
        /* We are done, and while this latest request
 
169
           failed, some previous results exist. */
 
170
        struct SessionHandle *data = conn->data;
 
171
 
 
172
        if(data->share)
 
173
          Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
 
174
 
 
175
        dns = Curl_cache_addr(data, conn->async.temp_ai,
 
176
                              conn->async.hostname,
 
177
                              conn->async.port);
 
178
        if(!dns) {
 
179
          /* failed to store, cleanup and return error */
 
180
          Curl_freeaddrinfo(conn->async.temp_ai);
 
181
          rc = CURLE_OUT_OF_MEMORY;
 
182
        }
 
183
        if(data->share)
 
184
          Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
 
185
 
 
186
        /* make sure the temp pointer is cleared and isn't pointing to
 
187
           something we've taken care of already */
 
188
        conn->async.temp_ai = NULL;
 
189
      }
 
190
  }
 
191
#endif
116
192
 
117
193
  conn->async.dns = dns;
118
194