[asio] An error occured in asio::win_mutex.hpp
Hi ALL, I have encountered this error, and would like to program a win32 FTP client with asio lib. In asio examples I reffenrenced at the 'Services(logger program)'. Could you help me ? I appriciate any suggestion. Thank all, Yasuhiko Yoshimura (Japan) An accsess violence occured at the below ===>> point. win_mutex.hpp:line 125: ------------------------------------------------------------------------ Then variable values are: &crit_section_ 0xcdcdcdcd this 0xcdcdcdcd (boost::noncopyable_::noncopyable) // Locking must be performed in a separate function to lock() since the // compiler does not support the use of structured exceptions and C++ // exceptions in the same function. int do_lock() { __try { ===>> ::EnterCriticalSection(&crit_section_); } __except(GetExceptionCode() == STATUS_INVALID_HANDLE || GetExceptionCode() == STATUS_NO_MEMORY ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH) { if (GetExceptionCode() == STATUS_NO_MEMORY) return ERROR_OUTOFMEMORY; return ERROR_INVALID_HANDLE; } return 0; } ------------------------------------------------------------------------ Here are my codes below. And error point was ===>> ------------------------------------------------------------------------ using boost::asio::ip::tcp; class ftp_client_dtp : public boost::enable_shared_from_this<ftp_client_dtp> { public: typedef boost::shared_ptr<ftp_client_dtp> pointer; static pointer create(boost::asio::io_service& io_service) { return pointer(new ftp_client_dtp(io_service)); } tcp::socket& socket() { return *work_socket_; } ... void start() { work_thread_.reset(new boost::thread( boost::bind(&boost::asio::io_service::run, &work_io_service_))); // Start an asynchronous resolve to translate the server and service names // into a list of endpoints. tcp::resolver::query query(sip_, sport_); work_resolver_->async_resolve(query, boost::bind(&ftp_client_dtp::handle_resolve, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::iterator)); } void close() { work_io_service_.post(boost::bind(&ftp_client_dtp::do_close, shared_from_this())); } ftp_client_dtp(boost::asio::io_service& io_service) : work_io_service_(), work_resolver_(new boost::asio::ip::tcp::resolver(work_io_service_)), work_socket_(new boost::asio::ip::tcp::socket(work_io_service_)) ===>> { } ~ftp_client_dtp() { work_.reset(); if (work_thread_) work_thread_->join(); } private: std::ofstream f; void handle_resolve(const boost::system::error_code& err, tcp::resolver::iterator endpoint_iterator) { ... } void handle_connect(const boost::system::error_code& err, tcp::resolver::iterator endpoint_iterator) { ... } void handle_read_content(const boost::system::error_code& err) { ... } void do_close() { work_socket_->close(); } std::string sip_, sport_, scurrentpath_, sfilename_; boost::asio::streambuf request_; boost::asio::streambuf response_; boost::scoped_ptr<boost::asio::ip::tcp::resolver> work_resolver_; boost::scoped_ptr<boost::asio::ip::tcp::socket> work_socket_; boost::asio::io_service work_io_service_; boost::scoped_ptr<boost::asio::io_service::work> work_; boost::scoped_ptr<boost::thread> work_thread_; }; ftp_client_dtp::pointer new_connection_; new_connection_ = ftp_client_dtp::create(io_service_); new_connection_->start(); ------------------------------------------------------------------------ Thank all, Yasuhiko Yoshimura (Japan)
<...>
ftp_client_dtp(boost::asio::io_service& io_service) : work_io_service_(), work_resolver_(new boost::asio::ip::tcp::resolver(work_io_service_)), work_socket_(new boost::asio::ip::tcp::socket(work_io_service_)) ===>> { } <...> boost::scoped_ptr<boost::asio::ip::tcp::resolver> work_resolver_; boost::scoped_ptr<boost::asio::ip::tcp::socket> work_socket_;
boost::asio::io_service work_io_service_; <...>
Please, pay attention that member objects are initialized in the order of their definition. I.e., when you initialize work_resolver_ and work_socket_ you pass them uninitialized work_io_service_ as a parameter.
Hi Igor R, Thank you very much for your reply. Now I have got a resolution that moving the initialization of 2 variable objects (work_resolver_ , work_socket_) that you mentioned into start() function from the constructor. Thank you, Yasuhiko Yoshimura -------------------------------------------------- From: "Igor R" <boost.lists@gmail.com> Sent: Wednesday, September 15, 2010 8:26 PM To: <boost-users@lists.boost.org> Subject: Re: [Boost-users] [asio] An error occured in asio::win_mutex.hpp
<...>
ftp_client_dtp(boost::asio::io_service& io_service) : work_io_service_(), work_resolver_(new boost::asio::ip::tcp::resolver(work_io_service_)), work_socket_(new boost::asio::ip::tcp::socket(work_io_service_)) ===>> { } <...> boost::scoped_ptr<boost::asio::ip::tcp::resolver> work_resolver_; boost::scoped_ptr<boost::asio::ip::tcp::socket> work_socket_;
boost::asio::io_service work_io_service_; <...>
Please, pay attention that member objects are initialized in the order of their definition. I.e., when you initialize work_resolver_ and work_socket_ you pass them uninitialized work_io_service_ as a parameter. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Now I have got a resolution that moving the initialization of 2 variable objects (work_resolver_ , work_socket_) that you mentioned into start() function from the constructor.
Well, you could just change the order of their definition, so that io_service is always defined *first*..
participants (2)
-
Igor R
-
Yasuhiko Yoshimura (informax.co.jp)