Форум программистов, компьютерный форум, киберфорум
Boost C++
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 4.84/56: Рейтинг темы: голосов - 56, средняя оценка - 4.84
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
1

boost::asio::ip::tcp::resolver::close() - проблемы

11.11.2011, 16:50. Показов 10289. Ответов 13
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Есть код клиента. Выложу только значащие моменты.

Проблема заключается в следующем - при асинхронном резолве, если интернет выключен и как ip используется имя сайта (пример внизу) - действие таймера заканчивается и переходим в обработчик события таймера. При вызове resolver_.cancel() вызывается on_resolve, но вызывается не с той ошибкой, которая должна бы быть.

The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.
А с :
Код
20111111T164915 tests[6306]       network.cpp:  80  On resolve: 2:asio.netdb - Host not found (non-authoritative), try again later
При просмотре кода в asio пришли к выводу, что при cancel поток не завершается.

Как быть? Кто-то сталкивался с таким?

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class client_peer
{
  public:
    typedef client_peer this_type;
    client_peer(const std::string& ip, int port, bool use_ssl = false) : ip_(ip), port_(port), 
    use_ssl_(use_ssl ? use_ssl : port == 443),/*timeout_(180),*/ wait_timer_(io_service_), resolver_(io_service_)
    {
    }
    void set_content_type(const std::string&);
    void set_credentials(const std::string&);
    void set_timeout(int);
    std::string send_and_receive(const std::string&, const std::string&, const std::string&, const std::string&);
    std::string send_and_receive(const std::string&, const std::string&, const std::string&, const std::string&, const std::string&);
    void connect(unsigned int timeout = 5);
    void run();
    void set_certificate(const std::string& key, const std::string& ca);
  private:
    void on_finish_read(pion::net::HTTPResponsePtr&, pion::net::TCPConnectionPtr&);
    void on_finish_write();
    void on_timeout(const net::error_code&);
    void on_connect(const net::error_code&);
    void on_handshake(const net::error_code&);
    void on_resolve(const net::error_code&, net::ip::tcp::resolver::iterator);
    void do_reconnect();
    void do_timeout();
    void do_resolve();
  private:
    std::string ip_;
    int port_;
    bool use_ssl_;
    //int timeout_;
    std::string credentials_;
    std::string content_type_;
    net::io_service io_service_;
    net::deadline_timer wait_timer_;
    pion::net::TCPConnectionPtr tcp_conn_;
    pion::net::HTTPResponsePtr http_response_;
    net::ip::tcp::resolver resolver_;
    net::ip::tcp::resolver::iterator endpoint_iter_;
    boost::shared_ptr<net::ssl::context> ssl_context_;
};
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
void client_peer::connect(unsigned int timeout)
{
    LDEBUG << "Is ssl? " << std::boolalpha << use_ssl_;
    wait_timer_.expires_from_now(dt::seconds(timeout));
    do_resolve();
    run();
    wait_timer_.expires_at(dt::ptime());
}
 
void client_peer::do_reconnect()
{
    LDEBUG << "Try to reconnect with: " << ip_ << ":" << port_;
    if (!tcp_conn_)
    {
       if (!ssl_context_)
       {
          tcp_conn_ = pion::net::TCPConnectionPtr(new pion::net::TCPConnection(io_service_, use_ssl_));
       }
       else
       {
          tcp_conn_ = pion::net::TCPConnectionPtr(new pion::net::TCPConnection(io_service_, *ssl_context_));
       }
    }
    net::ip::tcp::endpoint cur_endpoint = *endpoint_iter_;
    tcp_conn_->async_connect(cur_endpoint, 
                             boost::bind(&this_type::on_connect, this, net::placeholders::error));
}
 
void client_peer::do_resolve()
{
   LDEBUG << "Try resolve: " << ip_ << ":" << port_;
   net::ip::tcp::resolver::query query(ip_, int_to_string(port_));
   resolver_.async_resolve(query, boost::bind(&this_type::on_resolve, this, net::placeholders::error, net::placeholders::iterator));
}
 
void client_peer::do_timeout()
{
    LDEBUG << "do set timeout";
    if (wait_timer_.expires_at().is_not_a_date_time())
    {
        wait_timer_.expires_from_now(dt::seconds(5));
        LINFO << "NOW: " << boost::posix_time::second_clock::universal_time() << " Timer: " << wait_timer_.expires_at();
        wait_timer_.async_wait(boost::bind(&this_type::on_timeout, this, net::placeholders::error));
    }
}
 
void client_peer::on_resolve(const net::error_code& error, net::ip::tcp::resolver::iterator endpoint_iterator)
{
   LDEBUG << "On resolve: " << error;
   if (error)
   {
      if (error != net::error::operation_aborted)
      {
         LERR << "Cannot resolve address: " << ip_ << ":" << port_;
         throw network_error("Resolve error");
      }
   }
   else
   {
      if (endpoint_iterator == net::ip::tcp::resolver::iterator())
      {
         LERR << "No resolve address: " << ip_ << ":" << port_;
         throw network_error("Resolve error");
      }
      else
      {
         endpoint_iter_ = endpoint_iterator;
         do_reconnect();
      }
   }
}
 
void client_peer::on_timeout(const net::error_code& error)
{
    LDEBUG << "On timeout: " << error;
    if (error != net::error::operation_aborted)
    {
       LDEBUG << "Timeout with: " << ip_ << ":" << port_ << ", do close socket";
       if (tcp_conn_ && tcp_conn_->is_open())
       {
          tcp_conn_->close();
       }
       resolver_.cancel();
       //io_service_.stop();
    }
}
 
void client_peer::on_handshake(const net::error_code& error)
{
    LDEBUG << "On handshake: " << error << " do cancel timer";
    wait_timer_.cancel();
    if (error)
    {
       LWARN << "Cannot handshake with: " << ip_ << ":" << port_;
       throw network_error("Handshake error");
    }
}
 
void client_peer::on_connect(const net::error_code& error)
{
    LDEBUG << "On connect: " << error << " is_open: " << tcp_conn_->is_open();
    if (error)
    {
       if (tcp_conn_->is_open())
       {
          ++endpoint_iter_;
          if (endpoint_iter_ != net::ip::tcp::resolver::iterator())
          {
             do_reconnect();
          }
       }
    }
    else
    {
       tcp_conn_->setLifecycle(pion::net::TCPConnection::LIFECYCLE_KEEPALIVE);
       if (tcp_conn_->getSSLFlag())
       {
          LDEBUG << "do handshake";
          tcp_conn_->async_handshake_client(boost::bind(&this_type::on_handshake, this, net::placeholders::error));
       }
       else
       {
          LDEBUG << "do cancel timer";
          wait_timer_.cancel();
       }
    }
}
 
void client_peer::run()
{
    if (!wait_timer_.expires_at().is_special())
    {
        dt::ptime now = dt::microsec_clock::universal_time();
        if (wait_timer_.expires_at() - dt::microseconds(1) > now)
        {
            LDEBUG << "do set timer to: " << wait_timer_.expires_at();
            wait_timer_.async_wait(boost::bind(&this_type::on_timeout, this, net::placeholders::error));
        }
        else
        {
            LDEBUG << "Timeout before run: " << now;
            throw timeout_error();
        }
    }
    else
    {
        LDEBUG << "do infinite wait";
    }
    try
    {
        io_service_.run();
    }
    catch (const std::exception& e)
    {
        LINFO << "Exception from run: " << e.what();
        io_service_.reset();
        throw;
    }
    io_service_.reset();
    if (tcp_conn_ && !tcp_conn_->is_open())
    {
       throw timeout_error();
    }
}
Пример работы.
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
BOOST_AUTO_TEST_CASE(test_async_resolve)
{
   LINFO << "Test async resolve";
   bool exc = false;
   try
   {
      http::client_peer client_con("oldi.ru", 443);
      client_con.connect(1);
   }
   catch (const std::exception& e)
   {
      LERR << e.what();
      exc = true;
   }
   BOOST_CHECK(exc);
}
1
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
11.11.2011, 16:50
Ответы с готовыми решениями:

boost::asio::ip::tcp::socket::async_connect не вызывает handler
Пытаюсь подключиться к серверу: void CTcpClient::Connect( const std::string &amp; IpAddress_, int...

Ошибка в boost::asio::ip::tcp::iostream stream (&request);
Только приступаю к изучению boost::asio, не судите строго. Программа вычитывает картинку и...

Asio deadline_timer и tcp::socket отослать асинхоронно по tcp по таймеру
Здравствуйте. Цель по tcp соединению отсылать через равные промежутки времени сообщение одно и...

Boost Asio C++
Добрый день. Юзаю этот ( http://www.boost.org/ ) проект. Нужна помощь с документаций...

13
Эксперт С++
3211 / 1459 / 74
Регистрация: 09.08.2009
Сообщений: 3,441
Записей в блоге: 2
14.11.2011, 13:18 2
ForEveR, приложи минимальный код воспроизводящий ошибку. компилябельный, желательно.


Добавлено через 1 минуту
Цитата Сообщение от ForEveR Посмотреть сообщение
и как ip используется имя сайта
а если таки вписать IP ?




зы
только что тему увидел оО
0
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
14.11.2011, 20:28  [ТС] 3
niXman, Если вписать IP то все ок. Тогда ведь resolve не нужен.

C++
1
2
 client_peer client_con("oldi.ru", 443);
client_con.connect(1);
Собственно вот минимальный код. Клиент порезанный под то чтобы работать будет выглядеть так.

Код
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
namespace boost
{
 
namespace system
{
std::ostream& operator << (std::ostream&, const error_code&);
}
 
namespace asio
{
typedef boost::system::error_code error_code;
typedef boost::system::system_error system_error;
}
 
}
 
namespace net = boost::asio;
 
 
class network_error : public std::logic_error
{
   public:
       network_error(const std::string& message) : std::logic_error(message) {}
};
 
class timeout_error : public network_error
{
   public:
       timeout_error() : network_error("network_timeout") {}
};
class client_peer
{
  public:
    typedef client_peer this_type;
    client_peer(const std::string& ip, int port, bool use_ssl = false) : ip_(ip), port_(port), 
    use_ssl_(use_ssl ? use_ssl : port == 443),/*timeout_(180),*/ wait_timer_(io_service_), resolver_(io_service_)
    {
    }
    void connect(unsigned int timeout = 5);
    void run();
  private:
    void on_timeout(const net::error_code&);
    void on_resolve(const net::error_code&, net::ip::tcp::resolver::iterator);
    void do_timeout();
    void do_resolve();
  private:
    std::string ip_;
    int port_;
    bool use_ssl_;
    net::io_service io_service_;
    net::deadline_timer wait_timer_;
    net::ip::tcp::resolver resolver_;
    net::ip::tcp::resolver::iterator endpoint_iter_;
};
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
namespace boost { namespace system {
 
std::ostream& operator << (std::ostream& o, const error_code& e)
{
   o << e.value() << ":" << e.category().name() << " - " << e.message();
   return o;
}
 
}
}
 
void client_peer::connect(unsigned int timeout)
{
    wait_timer_.expires_from_now(dt::seconds(timeout));
    do_resolve();
    run();
    wait_timer_.expires_at(dt::ptime());
}
 
void client_peer::do_resolve()
{
   net::ip::tcp::resolver::query query(ip_, int_to_string(port_));
   resolver_.async_resolve(query, boost::bind(&this_type::on_resolve, this, net::placeholders::error, net::placeholders::iterator));
}
 
void client_peer::do_timeout()
{
    if (wait_timer_.expires_at().is_not_a_date_time())
    {
        wait_timer_.expires_from_now(dt::seconds(5));
        wait_timer_.async_wait(boost::bind(&this_type::on_timeout, this, net::placeholders::error));
    }
}
 
void client_peer::on_resolve(const net::error_code& error, net::ip::tcp::resolver::iterator endpoint_iterator)
{
   if (error)
   {
      if (error != net::error::operation_aborted)
      {
         throw network_error("Resolve error");
      }
   }
   else
   {
      if (endpoint_iterator == net::ip::tcp::resolver::iterator())
      {
         throw network_error("Resolve error");
      }
      else
      {
         endpoint_iter_ = endpoint_iterator;
      }
   }
}
 
void client_peer::on_timeout(const net::error_code& error)
{
    if (error != net::error::operation_aborted)
    {
       if (tcp_conn_ && tcp_conn_->is_open())
       {
          tcp_conn_->close();
       }
       resolver_.cancel();
    }
}
 
void client_peer::run()
{
    if (!wait_timer_.expires_at().is_special())
    {
        dt::ptime now = dt::microsec_clock::universal_time();
        if (wait_timer_.expires_at() - dt::microseconds(1) > now)
        {
            wait_timer_.async_wait(boost::bind(&this_type::on_timeout, this, net::placeholders::error));
        }
        else
        {
            throw timeout_error();
        }
    }
    else
    {
    }
    try
    {
        io_service_.run();
    }
    catch (const std::exception& e)
    {
        io_service_.reset();
        throw;
    }
    io_service_.reset();
    if (tcp_conn_ && !tcp_conn_->is_open())
    {
       throw timeout_error();
    }
}


Добавлено через 4 часа 24 минуты
Хм. Протупил. Вот фулл компилябельный код.
Код
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <string>
#include <stdexcept>
 
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
 
namespace boost
{
 
namespace system
{
std::ostream& operator << (std::ostream&, const error_code&);
}
 
namespace asio
{
typedef boost::system::error_code error_code;
typedef boost::system::system_error system_error;
}
 
}
 
namespace dt
{
using namespace boost::gregorian;
using namespace boost::posix_time;
}
 
namespace net = boost::asio;
 
 
class network_error : public std::logic_error
{
   public:
       network_error(const std::string& message) : std::logic_error(message) {}
};
 
class timeout_error : public network_error
{
   public:
       timeout_error() : network_error("network_timeout") {}
};
class client_peer
{
  public:
    typedef client_peer this_type;
    client_peer(const std::string& ip, int port, bool use_ssl = false) : ip_(ip), port_(port), 
    use_ssl_(use_ssl ? use_ssl : port == 443),/*timeout_(180),*/ wait_timer_(io_service_), resolver_(io_service_)
    {
    }
    void connect(unsigned int timeout = 5);
    void run();
  private:
    void on_timeout(const net::error_code&);
    void on_resolve(const net::error_code&, net::ip::tcp::resolver::iterator);
    void do_timeout();
    void do_resolve();
  private:
    std::string ip_;
    int port_;
    bool use_ssl_;
    net::io_service io_service_;
    net::deadline_timer wait_timer_;
    net::ip::tcp::resolver resolver_;
    net::ip::tcp::resolver::iterator endpoint_iter_;
};
 
namespace boost { namespace system {
 
std::ostream& operator << (std::ostream& o, const error_code& e)
{
   o << e.value() << ":" << e.category().name() << " - " << e.message();
   return o;
}
 
}
}
 
void client_peer::connect(unsigned int timeout)
{
    wait_timer_.expires_from_now(dt::seconds(timeout));
    do_resolve();
    run();
    wait_timer_.expires_at(dt::ptime());
}
 
void client_peer::do_resolve()
{
   net::ip::tcp::resolver::query query(ip_, boost::lexical_cast<std::string>(port_));
   resolver_.async_resolve(query, boost::bind(&this_type::on_resolve, this, net::placeholders::error, net::placeholders::iterator));
}
 
void client_peer::do_timeout()
{
    if (wait_timer_.expires_at().is_not_a_date_time())
    {
        wait_timer_.expires_from_now(dt::seconds(5));
        wait_timer_.async_wait(boost::bind(&this_type::on_timeout, this, net::placeholders::error));
    }
}
 
void client_peer::on_resolve(const net::error_code& error, net::ip::tcp::resolver::iterator endpoint_iterator)
{
   std::cerr << "On resolve with: " << error << std::endl;
   if (error)
   {
      if (error != net::error::operation_aborted)
      {
         throw network_error("Resolve error");
      }
   }
   else
   {
      if (endpoint_iterator == net::ip::tcp::resolver::iterator())
      {
         throw network_error("Resolve error");
      }
      else
      {
         endpoint_iter_ = endpoint_iterator;
      }
   }
}
 
void client_peer::on_timeout(const net::error_code& error)
{
    if (error != net::error::operation_aborted)
    {
       resolver_.cancel();
    }
}
 
void client_peer::run()
{
    if (!wait_timer_.expires_at().is_special())
    {
        dt::ptime now = dt::microsec_clock::universal_time();
        if (wait_timer_.expires_at() - dt::microseconds(1) > now)
        {
            wait_timer_.async_wait(boost::bind(&this_type::on_timeout, this, net::placeholders::error));
        }
        else
        {
            throw timeout_error();
        }
    }
    else
    {
    }
    try
    {
        io_service_.run();
    }
    catch (const std::exception& e)
    {
        io_service_.reset();
        throw;
    }
    io_service_.reset();
}
 
int main()
{
   client_peer client("oldi.ru", 80);
   client.connect(1);
}
0
Эксперт С++
3211 / 1459 / 74
Регистрация: 09.08.2009
Сообщений: 3,441
Записей в блоге: 2
17.11.2011, 15:27 4
ОС какая?

Добавлено через 3 минуты
под минимальным кодом я подразумевал что-то вроде этого:
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <boost/asio.hpp>
 
int main() {
   boost::asio::io_service ios;
   boost::asio::deadline_timer timer(ios);
   boost::asio::ip::tcp::resolver resolver(ios);
   boost::asio::ip::tcp::resolver::query query("google.ru", "http");
 
   auto func = [&](const boost::system::error_code& e, boost::asio::ip::tcp::resolver::iterator it) {
      if ( e ) { std::cout << "e: " << e.message() << std::endl; }
      if ( it == boost::asio::ip::tcp::resolver::iterator() ) { std::cout << "null iterator" << std::endl; }
      if ( e || it == boost::asio::ip::tcp::resolver::iterator() ) { return; }
 
      for ( ; it != boost::asio::ip::tcp::resolver::iterator(); ++it) {
         std::cout << "it: " << it->endpoint() << std::endl;
      }
   };
 
   resolver.async_resolve(
      query,
      func
   );
 
   timer.expires_from_now(boost::posix_time::milliseconds(1000));
   timer.async_wait(
      [&](const boost::system::error_code& error){
         std::cout << "timer expired" << std::endl;
         resolver.cancel();
      }
   );
 
   ios.run();
}
выполни его на своей архитектуре, и покажи вывод.
1
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
17.11.2011, 16:02  [ТС] 5
Bash
1
2
3
4
5
root@pterois:/home/forever/My_pro1/cpp_pro# iptables -I INPUT -j DROP
forever@pterois:~/My_pro1/cpp_pro$ ./file 
timer expired
e: Host not found (non-authoritative), try again later
null iterator
Ось : Ubuntu 11.10
0
Эксперт С++
3211 / 1459 / 74
Регистрация: 09.08.2009
Сообщений: 3,441
Записей в блоге: 2
17.11.2011, 17:08 6
у меня почти такой же результат. я даже пробовал установить таймаут в 1мкс.
похоже что баг.

сам напишешь баг-репорт?

Добавлено через 7 минут
еще вопрос.
после того как выводится "timer expired", сколько времени проходит до того как выведутся остальные строки?

Добавлено через 1 минуту
Цитата Сообщение от ForEveR Посмотреть сообщение
но вызывается не с той ошибкой, которая должна бы быть.
по всей видимости это и есть ответ
1
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
17.11.2011, 18:38  [ТС] 7
Долго.

Bash
1
2
3
4
5
6
7
8
forever@pterois:~/My_pro1/cpp_pro$ time ./file 
timer expired
e: Host not found (non-authoritative), try again later
null iterator
 
real    0m40.049s
user    0m0.004s
sys 0m0.004s
Спасибо. Значит будем танцевать с бубном.
0
Эксперт С++
3211 / 1459 / 74
Регистрация: 09.08.2009
Сообщений: 3,441
Записей в блоге: 2
17.11.2011, 19:02 8
Цитата Сообщение от ForEveR Посмотреть сообщение
Долго.
хм.. у меня тут же отваливается.

по поводу баг-репорта что?
1
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
17.11.2011, 20:29  [ТС] 9
niXman, Я сомневаюсь, что смогу по английски верно сформулировать проблему. На чтение тех документации знаний хватает, на составление сообщений вряд ли.
0
Эксперт С++
5043 / 2622 / 241
Регистрация: 07.10.2009
Сообщений: 4,310
Записей в блоге: 1
18.11.2011, 10:49 10
ForEveR, опиши грамотно на русском, а мы дружно подсобим
0
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
18.11.2011, 11:27  [ТС] 11
fasked, По сути как-то так...

При попытке выполнить резолв хоста с выключенным интернетом при использовании boost::asio::ip::tcp::resolver::async_resolve, неверно работает boost::asio::ip::tcp::resolver::cancel.
Не выполняется условие : This function forces the completion of any pending asynchronous operations on the host resolver. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code. Хандлер вызывается не с ошибкой с кодом boost::asio::error::operation_aborted, а с кодом boost::asio::error::host_not_found_try_again.
1
Эксперт С++
5043 / 2622 / 241
Регистрация: 07.10.2009
Сообщений: 4,310
Записей в блоге: 1
18.11.2011, 12:07 12
Лучший ответ Сообщение было отмечено как решение

Решение

Ну вот я бы, пожалуй, как-то так написал.
If connection is down, `boost::asio::ip::tcp::resolver::cancel' doesn't work properly by attemting to resolve a host using `boost::asio::ip::tcp::resolver::async_resolve'.

Handler has invoked with the code `host_not_found_try_again' and not `operation_aborted'.

Though it's documented that function forces the completion of any pending asynchronous operations on the host resolver, the handler for each cancelled operation will be invoked with the `boost::asio::error::operation_aborted' error code.
Сюда еще добавить код, воспроизводящий ошибку, и ссылку на описание в документации желательно.
4
В астрале
Эксперт С++
8049 / 4806 / 655
Регистрация: 24.06.2010
Сообщений: 10,562
18.11.2011, 13:30  [ТС] 13
Лучший ответ Сообщение было отмечено как решение

Решение

https://svn.boost.org/trac/boost/ticket/6138
3
Эксперт С++
3211 / 1459 / 74
Регистрация: 09.08.2009
Сообщений: 3,441
Записей в блоге: 2
18.11.2011, 15:41 14
Лучший ответ Сообщение было отмечено как решение

Решение

не успел... ну и маладца!


ForEveR, мои пять копеек на будущее. как правило, перед тем как постить в баг-реппорт, сначала пишут в asio-users@lists.sourceforge.net и уже после, когда мнение нескольких участников сходится в том что это баг, пишут баг-реппорт.

к тому же, в привычке писать в список рассылки есть один плюс - это как форум. плюс - там тебе ответят не кодеры широкого профиля, а именно те кто интересуется этой библиотекой. IgorR, к примеру. асс реальный. сам автор очень редко отвечает в списке рассылки. чего там удивляться, в его блоге последняя запись апреля 2010
4
18.11.2011, 15:41
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
18.11.2011, 15:41
Помогаю со студенческими работами здесь

Boost.asio
Добрый день. Я только начал знакомство с boost.asio и при использовании примеров с офф.сайта...

boost/asio
Кто тестил asio в Вuilder-е? Код использовал отсюда...

boost::asio
начал ковырять буст. Возник вопрос с созданием клинт-серверного приложения. Для ознакомления хочу...

C++ | boost::asio + ssl?
Доброго времени суток! Хотелось бы узнать как подключаться по SSL? int main() { ...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
14
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru