| 224 | } |
| 225 | |
| 226 | void container::impl::reconnect(pn_connection_t* pnc) { |
| 227 | --reconnecting_; |
| 228 | |
| 229 | if (stopping_ && reconnecting_==0) { |
| 230 | pn_connection_free(pnc); |
| 231 | //TODO: We've lost the error - we should really propagate it here |
| 232 | pn_proactor_disconnect(proactor_, NULL); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | connection_context& cc = connection_context::get(pnc); |
| 237 | reconnect_context& rc = *cc.reconnect_context_.get(); |
| 238 | |
| 239 | connection_options& co = *cc.connection_options_; |
| 240 | co.apply_reconnect_urls(pnc); |
| 241 | |
| 242 | // Figure out next connection url to try |
| 243 | // rc.current_url_ == -1 means try the url specified in connect, not a failover url |
| 244 | const proton::url url(rc.current_url_==-1 ? cc.reconnect_url_ : cc.failover_urls_[rc.current_url_]); |
| 245 | |
| 246 | // XXXX Debug: |
| 247 | //std::cout << "Retries: " << rc.retries_ << " Delay: " << rc.delay_ << " Trying: " << url << "@" << rc.current_url_ << std::endl; |
| 248 | |
| 249 | ++rc.current_url_; |
| 250 | // Did we go through all the urls? |
| 251 | if (rc.current_url_==int(cc.failover_urls_.size())) { |
| 252 | rc.current_url_ = -1; |
| 253 | ++rc.retries_; |
| 254 | } |
| 255 | |
| 256 | connection_options opts; |
| 257 | opts.container_id(id_); |
| 258 | default_url_options(opts, url); |
| 259 | opts.update(co); |
| 260 | messaging_handler* mh = opts.handler(); |
| 261 | cc.handler = mh; |
| 262 | cc.active_url_ = url; |
| 263 | |
| 264 | make_wrapper(pnc).open(co); |
| 265 | start_connection(url, pnc); |
| 266 | } |
| 267 | |
| 268 | namespace { |
| 269 | duration random_between(duration min, duration max) |