remove my own slurp(), because it is in the Lib now. Adopt API change from time_t to unsigned.

JSON-107-01
Roker 4 years ago
parent 74b82b5aa5
commit 4b658f04a6

@ -17,6 +17,8 @@
#include <pEp/openpgp_compat.h>
#include <pEp/mime.h>
#include <pEp/slurp.hh>
#include <boost/filesystem.hpp>
#include "json_spirit/json_spirit_reader.h"
@ -212,7 +214,7 @@ void ev_server::sendFile( evhttp_request* req, const std::string& mimeType, cons
return;
// not the best for big files, but this server does not send big files. :-)
const std::string fileContent = pEp::utility::slurp(fileName.string());
const std::string fileContent = pEp::slurp(fileName.string());
evbuffer_add(outBuf, fileContent.data(), fileContent.size());
evhttp_add_header(evhttp_request_get_output_headers(req), "Content-Type", mimeType.c_str());
evhttp_send_reply(req, HTTP_OK, "", outBuf);

@ -27,6 +27,7 @@
#include <pEp/keymanagement.h>
#include <pEp/status_to_string.hh> // from libpEpAdapter.
#include <pEp/locked_queue.hh>
#include <boost/filesystem.hpp>
#include "json_spirit/json_spirit_writer.h"
@ -74,7 +75,7 @@ typedef std::unique_ptr<std::thread, decltype(ThreadDeleter)> ThreadPtr;
typedef std::vector<ThreadPtr> ThreadPool;
// keyserver lookup
locked_queue< pEp_identity*, &free_identity> keyserver_lookup_queue;
utility::locked_queue< pEp_identity*, &free_identity> keyserver_lookup_queue;
PEP_SESSION keyserver_lookup_session = nullptr; // FIXME: what if another adapter started it already?
ThreadPtr keyserver_lookup_thread{nullptr, ThreadDeleter};
@ -135,7 +136,7 @@ struct JsonAdapter::Internal
PEP_SESSION session = nullptr;
// Sync
locked_queue< Sync_event*, &free_Sync_event> sync_queue;
utility::locked_queue< Sync_event*, &free_Sync_event> sync_queue;
PEP_SESSION sync_session = nullptr;
ThreadPtr sync_thread{nullptr, ThreadDeleter};
@ -223,32 +224,17 @@ struct JsonAdapter::Internal
return 0;
}
Sync_event* retrieveNextSyncMsg(time_t timeout)
Sync_event* retrieveNextSyncMsg(unsigned timeout)
{
Sync_event* msg = nullptr;
if(timeout)
{
std::chrono::steady_clock::time_point end_time = std::chrono::steady_clock::now()
+ std::chrono::seconds(timeout);
const bool success = sync_queue.try_pop_front(msg, end_time);
const bool success = sync_queue.try_pop_front(msg, std::chrono::seconds(timeout));
if(!success)
{
// this is timeout occurrence
return nullptr;
return new_sync_timeout_event();
}
/*
// we got a message while waiting for timeout -> compute remaining time
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
if (now < end_time)
{
*timeout = std::chrono::duration_cast<std::chrono::seconds>(end_time - now).count();
}
else
{
*timeout = 0;
}
*/
}else{
msg = sync_queue.pop_front();
}
@ -378,7 +364,7 @@ int JsonAdapter::injectSyncMsg(Sync_event* msg, void* obj)
}
Sync_event* JsonAdapter::retrieveNextSyncMsg(void* obj, time_t timeout)
Sync_event* JsonAdapter::retrieveNextSyncMsg(void* obj, unsigned timeout)
{
JsonAdapter* ja = static_cast<JsonAdapter*>(obj);
return ja->i->retrieveNextSyncMsg(timeout);

@ -72,7 +72,7 @@ public:
// BEWARE: msg is 1st parameter, obj is second!!!
static int injectSyncMsg(Sync_event* msg, void* obj);
static Sync_event* retrieveNextSyncMsg(void* obj, time_t timeout);
static Sync_event* retrieveNextSyncMsg(void* obj, unsigned timeout);
static void* syncThreadRoutine(void* arg);
void startSync();

@ -8,20 +8,7 @@ namespace pEp
namespace utility
{
std::string slurp(const std::string& filename)
{
std::ifstream input(filename.c_str());
if(!input)
{
throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
}
std::stringstream sstr;
sstr << input.rdbuf();
return sstr.str();
}
// We've all moved to libpEpAdapter. o/
} // end of namespace pEp::utility
} // end of namespace pEp

@ -15,7 +15,7 @@ namespace pEp
return { data, Deleter };
}
#if 0
// a thread-safe queue of T elements. Deleter is a functor that is called in clear() for each elements
// interface differs from std::queue because "top() and pop() if not empty()" does not work atomically!
// elements must be copied without exceptions!
@ -145,12 +145,8 @@ namespace pEp
return _q.empty();
}
};
// reads a whole file and returns it as std::string
// throws std::runtime_error() if the file cannot be read. Empty file is not an error.
std::string slurp(const std::string& filename);
#endif
} // end of namespace pEp::util
} // end of namespace pEp

@ -3,12 +3,13 @@
#include <fstream>
#include <sstream>
#include "logger.hh"
#include "pep-utils.hh"
#include "pep-utils-json.hh"
#include <pEp/pEpEngine.h> // for PEP_VERSION and get_engine_version()
#include <boost/algorithm/string/trim.hpp>
#include "json_spirit/json_spirit_reader.h"
#include <pEp/slurp.hh>
namespace js = json_spirit;
namespace {
@ -108,7 +109,7 @@ ServerVersion::ServerVersion(unsigned maj, unsigned min, unsigned p)
const std::string file_content =
boost::algorithm::trim_copy(
pEp::utility::slurp("PackageVersion")
pEp::slurp("PackageVersion")
);
try{

@ -1,4 +1,4 @@
#include "pep-utils.hh"
#include <pep/locked_queue.hh>
#include <thread>
#include <atomic>
#include <vector>
@ -12,7 +12,7 @@ unsigned Elements = 1000*1000;
std::atomic<bool> finished(false);
void do_nothing(uint64_t) {}
pEp::utility::locked_queue<uint64_t, &do_nothing> Q;
utility::locked_queue<uint64_t, &do_nothing> Q;
std::vector< std::vector<uint64_t> > v;

Loading…
Cancel
Save