Open ddovod opened 8 years ago
Addition: Boost version also causes Undefined error: 0. iOS (device and simulator) has this error too.
Another addition: If there's nobody listening on the port I try to connect to, "Connection refused" error is returned to the async_connect callback. So "Undefined error: 0" appears only if somebody is listening port on the other side.
Up!
Up!
Up!
Up!
Up!
Up!
Up!
Update: examples works fine, sorry, my bad. Assuming there's somebody who is listening 8888 port on the localhost. The code below works bad on iOS/mac os:
std::string m_address = "127.0.0.1";
int m_port = 8888;
asio::io_service m_service;
asio::ip::tcp::socket m_socket(m_service);
asio::ip::tcp::endpoint ep(asio::ip::address::from_string(m_address), m_port);
m_socket.async_connect(ep, [] (const asio::error_code& err) {
std::cout << "onConnect -> " << err.message() << std::endl;
});
m_service.run();
Output on a Debian:
onConnect -> Success
Output on a Mac OS:
onConnect -> Undefined error: 0
I think undefined error means no error, the error object is not initialized.
I am having the same problem. Any workaround?
@germandiagogomez I came to the fact that I used asio incorrectly, just check that your code conforms to docs and restrictions
@ddovod can you post the fixed code ?
Oh, so much time has passed, I'm not sure what exactly I was doing wrong.
Looking at the code above I would say that you can try to use asio::async_connect(m_socket.lowest_layer(), ...)
instead of m_socket.async_connect(...)
.
My connection code with asio now loos like this:
auto query = std::make_shared<asio::ip::tcp::resolver::query>(m_host, m_port);
m_resolver.async_resolve(*query, [this, query](const auto& error, auto iterator) {
if (error) {
onError();
} else {
asio::async_connect(m_socket.lowest_layer(), iterator, [this](const auto& connectError, const auto&) {
if (connectError) {
onError();
} else {
onConnectionFinished();
}
});
}
});
m_socketThread = std::thread([this] { m_ioService.run(); });
Hope this helps
Hello. I have some issue with examples from src/examples/cpp11/echo/async_tcp_echo_server.cpp and blocking_tcp_echo_client.cpp (also my own code works bad).
When I try to connect/read/write (blocking and async operations), i get "Undefined error: 0" in the asio::error_code parameter. Interesting thing is that data transfers successfully. Only problem is Undefined error and infinity reads with zero bytes read.
Compiling with xCode and standalone clang with command like clang++ -std=c++11 -Ipath/to/asio/include async_tcp_echo_server.cpp -oserver
Also using ASIO_STANDALONE definition.
Could you help me please? I'll check boost version soon. Thank you a lot!