From: Braden M. <br...@us...> - 2007-04-22 09:09:35
|
Update of /cvsroot/openvrml/openvrml/src/openvrml-xembed In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20594/src/openvrml-xembed Modified Files: gtkvrmlbrowser.cpp Log Message: Ensure that only one thread at a time writes a request to the request channel. Index: gtkvrmlbrowser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/openvrml-xembed/gtkvrmlbrowser.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** gtkvrmlbrowser.cpp 22 Apr 2007 09:04:37 -0000 1.6 --- gtkvrmlbrowser.cpp 22 Apr 2007 09:09:33 -0000 1.7 *************** *** 1,3 **** ! // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*- // // OpenVRML Mozilla plug-in --- 1,3 ---- ! // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 78 -*- // // OpenVRML Mozilla plug-in *************** *** 102,105 **** --- 102,106 ---- class G_GNUC_INTERNAL resource_fetcher : public openvrml::resource_fetcher { GIOChannel * request_channel_; + boost::mutex request_channel_mutex_; public: *************** *** 110,113 **** --- 111,117 ---- virtual std::auto_ptr<openvrml::resource_istream> do_get_resource(const std::string & uri); + + bool write_request_chars(const gchar * buf, gssize count, + gsize * bytes_written); }; *************** *** 540,551 **** class plugin_resource_istream : public openvrml::resource_istream { const boost::shared_ptr<plugin_streambuf> streambuf_; ! GIOChannel * const request_channel_; public: plugin_resource_istream(const std::string & uri, ! GIOChannel * const request_channel): openvrml::resource_istream(0), streambuf_(new plugin_streambuf(uri)), ! request_channel_(request_channel) { using std::ostringstream; --- 544,555 ---- class plugin_resource_istream : public openvrml::resource_istream { const boost::shared_ptr<plugin_streambuf> streambuf_; ! resource_fetcher & resource_fetcher_; public: plugin_resource_istream(const std::string & uri, ! resource_fetcher & fetcher): openvrml::resource_istream(0), streambuf_(new plugin_streambuf(uri)), ! resource_fetcher_(fetcher) { using std::ostringstream; *************** *** 560,581 **** request << "get-url " << uri << '\n'; gsize bytes_written; ! GError * error = 0; ! scope_guard error_guard = make_guard(g_error_free, ref(error)); ! boost::ignore_unused_variable_warning(error_guard); ! GIOStatus io_status = ! g_io_channel_write_chars(this->request_channel_, ! request.str().data(), ! request.str().length(), ! &bytes_written, ! &error); ! if (io_status != G_IO_STATUS_NORMAL) { ! g_warning(error->message); ! this->setstate(ios_base::badbit); ! return; ! } ! ! io_status = g_io_channel_flush(this->request_channel_, &error); ! if (io_status != G_IO_STATUS_NORMAL) { ! g_warning(error->message); this->setstate(ios_base::badbit); return; --- 564,573 ---- request << "get-url " << uri << '\n'; gsize bytes_written; ! const bool write_succeeded = ! this->resource_fetcher_ ! .write_request_chars(request.str().data(), ! request.str().length(), ! &bytes_written); ! if (!write_succeeded) { this->setstate(ios_base::badbit); return; *************** *** 589,594 **** this->setstate(ios_base::badbit); } - - error_guard.dismiss(); } --- 581,584 ---- *************** *** 610,614 **** }; return std::auto_ptr<openvrml::resource_istream>( ! new plugin_resource_istream(uri, this->request_channel_)); } --- 600,634 ---- }; return std::auto_ptr<openvrml::resource_istream>( ! new plugin_resource_istream(uri, *this)); ! } ! ! bool resource_fetcher::write_request_chars(const gchar * const buf, ! const gssize count, ! gsize * const bytes_written) ! { ! boost::mutex::scoped_lock lock(this->request_channel_mutex_); ! ! using boost::ref; ! ! GError * error = 0; ! scope_guard error_guard = make_guard(g_error_free, ref(error)); ! boost::ignore_unused_variable_warning(error_guard); ! ! GIOStatus status = ! g_io_channel_write_chars(this->request_channel_, buf, count, ! bytes_written, &error); ! if (status != G_IO_STATUS_NORMAL) { ! g_warning(error->message); ! return false; ! } ! ! status = g_io_channel_flush(this->request_channel_, &error); ! if (status != G_IO_STATUS_NORMAL) { ! g_warning(error->message); ! return false; ! } ! ! error_guard.dismiss(); ! return true; } |