diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-08-10 16:38:33 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-08-12 09:13:51 +0100 |
| commit | b1dc9c3a2f7e55c9afc5bf2d5b465371b048e14f (patch) | |
| tree | 9968238c6c0511f044e6fcdb4abcc08b5eb28f27 /src/lib/json_server.cc | |
| parent | 4a0ae92e28d7d1f0dd648d1b620efc324fdef161 (diff) | |
Remove all use of stringstream in an attempt to fix
the suspected thread-unsafe crash bugs on OS X.
Diffstat (limited to 'src/lib/json_server.cc')
| -rw-r--r-- | src/lib/json_server.cc | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/lib/json_server.cc b/src/lib/json_server.cc index 4af133875..490f9fc5f 100644 --- a/src/lib/json_server.cc +++ b/src/lib/json_server.cc @@ -18,15 +18,16 @@ */ -#include <boost/asio.hpp> -#include <boost/bind.hpp> -#include <boost/thread.hpp> #include "json_server.h" #include "job_manager.h" #include "job.h" #include "util.h" #include "film.h" #include "transcode_job.h" +#include "raw_convert.h" +#include <boost/asio.hpp> +#include <boost/bind.hpp> +#include <boost/thread.hpp> #include <iostream> using std::string; @@ -151,48 +152,43 @@ JSONServer::request (string url, shared_ptr<tcp::socket> socket) action = r["action"]; } - locked_stringstream json; + string json; if (action == "status") { list<shared_ptr<Job> > jobs = JobManager::instance()->get (); - json << "{ \"jobs\": ["; + json += "{ \"jobs\": ["; for (list<shared_ptr<Job> >::iterator i = jobs.begin(); i != jobs.end(); ++i) { - json << "{ "; + json += "{ "; if ((*i)->film()) { - json << "\"dcp\": \"" << (*i)->film()->dcp_name() << "\", "; + json += "\"dcp\": \"" + (*i)->film()->dcp_name() + "\", "; } - json << "\"name\": \"" << (*i)->json_name() << "\", "; + json += "\"name\": \"" + (*i)->json_name() + "\", "; if ((*i)->progress ()) { - json << "\"progress\": " << (*i)->progress().get() << ", "; + json += "\"progress\": " + raw_convert<string>((*i)->progress().get()) + ", "; } else { - json << "\"progress\": unknown, "; + json += "\"progress\": unknown, "; } - json << "\"status\": \"" << (*i)->json_status() << "\""; - json << " }"; + json += "\"status\": \"" + (*i)->json_status() + "\""; + json += " }"; list<shared_ptr<Job> >::iterator j = i; ++j; if (j != jobs.end ()) { - json << ", "; + json += ", "; } } - json << "] }"; - - if (json.str().empty ()) { - json << "{ }"; - } + json += "] }"; } - locked_stringstream reply; - reply << "HTTP/1.1 200 OK\r\n" - << "Content-Length: " << json.str().length() << "\r\n" - << "Content-Type: application/json\r\n" - << "\r\n" - << json.str () << "\r\n"; - cout << "reply: " << json.str() << "\n"; - boost::asio::write (*socket, boost::asio::buffer (reply.str().c_str(), reply.str().length())); + string reply = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + raw_convert<string>(json.length()) + "\r\n" + "Content-Type: application/json\r\n" + "\r\n" + + json + "\r\n"; + cout << "reply: " << json << "\n"; + boost::asio::write (*socket, boost::asio::buffer (reply.c_str(), reply.length())); } |
