From: Max M. <ma...@kt...> - 2011-01-17 16:11:43
|
Hey everybody. I have a problem using the asynchronous server version of the cpp-netlib. As soon as I make a request a bad_cast exception is cast on the thread that ran .run(). I am making a request to "http://localhost:11200/proxy/?url=http://www.google.se", but all other requests seem to fail aswell. This is working fine for the synchronous version of the server. I am making this request from firefox. Also, I am using v0.8 of the library. Any ideas? Checking the documentation for using the async-server, it seems to be pretty identical to what I am doing. //asyncproxy.cpp #include <string> #include "asyncproxy.h" namespace proxy { void ASyncProxy::startProxy(std::string url, std::string port) { boost::network::utils::thread_pool thread_pool(2); http_server server(url, port, *this, thread_pool); server.run(); } ASyncProxy::ASyncProxy(void (*callback)(std::string)) { this->callback = callback; } void ASyncProxy::operator()(http_server::request const & req, http_server::connection_ptr connection) { connection->set_status(http_server::connection::ok); } } int main() { proxy::ASyncProxy prox(&writeQueue); prox.startProxy("localhost", 11200); } //asyncproxy.h #include <boost\network\protocol\http\server.hpp> #include <boost\network\utils\thread_pool.hpp> namespace proxy { struct ASyncProxy { typedef boost::network::http::async_server<ASyncProxy> http_server; public: void startProxy(std::string url, std::string port); ASyncProxy(void (*callback)(std::string)); void operator()(http_server::request const & req, http_server::connection_ptr connection); private: void (*callback)(std::string); }; } #endif |
From: Dean M. B. <mik...@gm...> - 2011-01-18 05:07:42
|
Hi Max, Sorry for the late response this time, I've been asleep for a bit and taking a break earlier today. Please see thoughts below. On Tue, Jan 18, 2011 at 12:11 AM, Max Malmgren <ma...@kt...> wrote: > Hey everybody. > > I have a problem using the asynchronous server version of the cpp-netlib. As > soon as I make a request a bad_cast exception is cast on the thread that ran > .run(). > > I am making a request to > "http://localhost:11200/proxy/?url=http://www.google.se", but all other > requests seem to fail aswell. > > This is working fine for the synchronous version of the server. I am making > this request from firefox. Also, I am using v0.8 of the library. > Can you please send the exact request that the browser sends over the line? Can you please use something like FireBug to catch the raw request (with method, headers, and body) that it sends to the server? > Any ideas? Checking the documentation for using the async-server, it seems > to be pretty identical to what I am doing. > > //asyncproxy.cpp > #include <string> > #include "asyncproxy.h" > > namespace proxy { > void ASyncProxy::startProxy(std::string url, std::string port) > { > boost::network::utils::thread_pool thread_pool(2); > http_server server(url, port, *this, thread_pool); > server.run(); > } > ASyncProxy::ASyncProxy(void (*callback)(std::string)) > { > this->callback = callback; > } > void ASyncProxy::operator()(http_server::request const & req, > http_server::connection_ptr connection) > { > connection->set_status(http_server::connection::ok); This is it? Unfortunately you'd need to write out headers and data to the connection too for anything to actually be sent through the connection. Please check the test in libs/network/test/http_async_server.cpp to see what an asynchronous handler should look like. HTH -- Dean Michael Berris about.me/deanberris |
From: Oleg M. <ole...@gm...> - 2011-01-19 03:15:53
Attachments:
signature.asc
|
Hello Max, On 18.01.2011 02:11, Max Malmgren wrote: > I have a problem using the asynchronous server version of the > cpp-netlib. As soon as I make a request a bad_cast exception is cast on > the thread that ran .run(). Dean has already spotted the problem in ASyncProxy::operator(). Apart of that please consider using master or 0.8-devel branch of git://github.com/mikhailberis/cpp-netlib.git until 0.8.1 is released: there are important fixes to async_connection. -- Best regards, Oleg Malashenko. |
From: Max M. <ma...@kt...> - 2011-01-20 14:41:24
|
Hi! I have now done a few tests regarding the ASyncProxy class I mailed about. The original problem arised when compiling with MSVS 2010, using boost 1.44 installed with the boost pro installer package. This yielded a bad_cast exception thrown whenever a request was made. Then I decided to test it on my Ubuntu machine. I installed boost 1.45 using bjam. Everything worked fine. I got no exception and the connection.write("hello") indeed sent that very response to my browser. I concluded that I should probably build boost 1.45 on my windows machine, which is what I did today. Following your advice I also checked out cpp-netlib from the master branch of the git repository, and used that instead of the download. Originally I got a compile error, but once I included boost/or.hpp in the boost/network/version.hpp file it compiled. However, it still does not work on my windows distribution, while it does on my ubuntu distribution. I still get a bad_cast exception thrown. Do you have any idea what might be the problem? Any known compiler weirdness regarding MSVC 2010 vs g++? I am using firefox both on windows and on my ubuntu machine, they both issued GET requests, difference was the user-agent header. Thanks for any and all replies. Best regards, Max Malmgren ________________________________________ From: Oleg Malashenko [ole...@gm...] Sent: Wednesday, January 19, 2011 4:15 AM To: C++ Networking Library Developers Mailing List Subject: Re: [cpp-netlib-devel] cpp-netlib async server request - bad cast exception thrown Hello Max, On 18.01.2011 02:11, Max Malmgren wrote: > I have a problem using the asynchronous server version of the > cpp-netlib. As soon as I make a request a bad_cast exception is cast on > the thread that ran .run(). Dean has already spotted the problem in ASyncProxy::operator(). Apart of that please consider using master or 0.8-devel branch of git://github.com/mikhailberis/cpp-netlib.git until 0.8.1 is released: there are important fixes to async_connection. -- Best regards, Oleg Malashenko. |
From: Oleg M. <ole...@gm...> - 2011-01-21 01:40:16
Attachments:
signature.asc
|
Hello, Max, On 21.01.2011 00:41, Max Malmgren wrote: > Originally I got a compile error, but once I included boost/or.hpp in > the boost/network/version.hpp file it compiled. However, it still > does not work on my windows distribution, while it does on my ubuntu > distribution. I still get a bad_cast exception thrown. Can you please run it under MSVS debugger and post a backtrace from the point where exception is thrown? It shouldn't be a problem. -- Best regards, Oleg Malashenko. |
From: Max M. <ma...@kt...> - 2011-01-21 08:08:53
|
Hi! See below for my call stack information at the moment of error. I will try to investigate a little on my own, even though I am not very experienced at c++ or boost. For convieniency, here is the method that seems to fail: boost::asio::ip::address_v4 address::to_v4() const { if (type_ != ipv4) { std::bad_cast ex; boost::throw_exception(ex); } return ipv4_address_; } Seems that type_ != ipv4, though I have no idea why. It seems to be some win-specific implementation above in the stack-trace, which would explain why it works on Ubuntu. Sorry if I am wasting your time! Best regards, Max Malmgren KernelBase.dll!76bcb727() [Frames below may be incorrect and/or missing, no symbols loaded for KernelBase.dll] KernelBase.dll!76bcb727() msvcr100.dll!std::bad_cast::bad_cast(const std::bad_cast & that) Line 75 + 0x10 bytes C++ 81fd17b7() msvcr100.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 157 C++ NativeCodeTest.exe!boost::throw_exception<std::bad_cast>(const std::bad_cast & e) Line 61 + 0x2e bytes C++ > NativeCodeTest.exe!boost::asio::ip::address::to_v4() Line 91 C++ NativeCodeTest.exe!boost::network::http::async_connection<boost::network::http::tags::http_async_server,proxy::ASyncProxy>::start() Line 313 + 0x5a bytes C++ NativeCodeTest.exe!boost::network::http::async_server_base<boost::network::http::tags::http_async_server,proxy::ASyncProxy>::handle_accept(const boost::system::error_code & ec) Line 71 C++ NativeCodeTest.exe!boost::asio::asio_handler_invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,boost::network::http::sync_server_base<boost::network::http::tags::http_server,proxy::SyncProxy>,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<boost::network::http::sync_server_base<boost::network::http::tags::http_server,proxy::SyncProxy> *>,boost::arg<1> > >,boost::system::error_code> >(boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,boost::network::http::sync_server_base<boost::network::http::tags::http_server,proxy::SyncProxy>,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<boost::network::http::sync_server_base<boost::network::http::tags::http_server,proxy::SyncProxy> *>,boost::arg<1> > >,boost::system::error_code> function, ...) Line 65 C++ NativeCodeTest.exe!boost::asio::detail::win_iocp_socket_accept_op<boost::asio::basic_socket<boost::asio::ip::tcp,boost::asio::stream_socket_service<boost::asio::ip::tcp> >,boost::asio::ip::tcp,boost::_bi::bind_t<void,boost::_mfi::mf1<void,boost::network::http::async_server_base<boost::network::http::tags::http_async_server,proxy::ASyncProxy>,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<boost::network::http::async_server_base<boost::network::http::tags::http_async_server,proxy::ASyncProxy> *>,boost::arg<1> > > >::do_complete(boost::asio::detail::win_iocp_io_service * owner, boost::asio::detail::win_iocp_operation * base, boost::system::error_code ec, unsigned int __formal) Line 136 + 0x2a bytes C++ NativeCodeTest.exe!boost::asio::detail::win_iocp_io_service::do_one(bool block, boost::system::error_code & ec) Line 386 + 0x10 bytes C++ NativeCodeTest.exe!boost::asio::detail::win_iocp_io_service::run(boost::system::error_code & ec) Line 160 + 0xb bytes C++ NativeCodeTest.exe!boost::asio::io_service::run() Line 58 C++ NativeCodeTest.exe!proxy::ASyncProxy::startProxy(std::basic_string<char,std::char_traits<char>,std::allocator<char> > url, std::basic_string<char,std::char_traits<char>,std::allocator<char> > port) Line 14 C++ NativeCodeTest.exe!StartASyncProxy(char * port, char * url) Line 64 C++ NativeCodeTest.exe!main() Line 76 + 0xf bytes C++ NativeCodeTest.exe!__tmainCRTStartup() Line 555 + 0x17 bytes C kernel32.dll!76363677() ntdll.dll!776b9d42() ntdll.dll!776b9d15() ________________________________________ From: Oleg Malashenko [ole...@gm...] Sent: Friday, January 21, 2011 2:39 AM To: C++ Networking Library Developers Mailing List Subject: Re: [cpp-netlib-devel] cpp-netlib async server request - bad cast exception thrown Hello, Max, On 21.01.2011 00:41, Max Malmgren wrote: > Originally I got a compile error, but once I included boost/or.hpp in > the boost/network/version.hpp file it compiled. However, it still > does not work on my windows distribution, while it does on my ubuntu > distribution. I still get a bad_cast exception thrown. Can you please run it under MSVS debugger and post a backtrace from the point where exception is thrown? It shouldn't be a problem. -- Best regards, Oleg Malashenko. |
From: Dean M. B. <mik...@gm...> - 2011-01-21 08:17:31
|
On Fri, Jan 21, 2011 at 4:08 PM, Max Malmgren <ma...@kt...> wrote: > Hi! See below for my call stack information at the moment of error. I will try to investigate a little on my own, even though I am not very experienced at c++ or boost. > For convieniency, here is the method that seems to fail: > > boost::asio::ip::address_v4 address::to_v4() const > { > if (type_ != ipv4) > { > std::bad_cast ex; > boost::throw_exception(ex); > } > return ipv4_address_; > } > > Seems that type_ != ipv4, though I have no idea why. It seems to be some win-specific implementation above in the stack-trace, which would explain why it works on Ubuntu. > Sorry if I am wasting your time! > It looks like you're using IPv6 -- which IMO is a good thing, but not so good for cpp-netlib. :D This is a bug because I assumed that all servers will be using ipv4 addresses. Please file that as an issue in the issue tracker at http://github.com/cpp-netlib/cpp-netlib/issues -- have a good one and thanks for reporting the issue. :) (Also, next time, please don't top-post. :) ) -- Dean Michael Berris about.me/deanberris |
From: Oleg M. <ole...@gm...> - 2011-01-21 08:42:29
Attachments:
signature.asc
|
On 21.01.2011 18:17, Dean Michael Berris wrote: >> Seems that type_ != ipv4, though I have no idea why. It seems to be >> some win-specific implementation above in the stack-trace, which >> would explain why it works on Ubuntu. > > It looks like you're using IPv6 -- which IMO is a good thing, but > not so good for cpp-netlib. :D As a workaround try "0.0.0.0" or "127.0.0.1" instead of "localhost" in prox.startProxy(): it should force resolver to use ipv4 endpoints. -- Best regards, Oleg Malashenko. |