netservices: Flesh out BHttpSession::Impl data and control structures
Change-Id: I4230570ea8339b12d855f7de7fa72e4664013e2d
This commit is contained in:
@@ -69,6 +69,7 @@ namespace Network {
|
||||
as well as their own cookies and certificate store.
|
||||
|
||||
\exception std::bad_alloc Unable to allocate resources for the object.
|
||||
\exception BRuntimeError Unable to create semaphores or threads.
|
||||
|
||||
\since Haiku R1
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,8 @@ public:
|
||||
BHttpSession& operator=(BHttpSession&&) noexcept = delete;
|
||||
|
||||
private:
|
||||
struct Impl;
|
||||
class Request;
|
||||
class Impl;
|
||||
std::shared_ptr<Impl> fImpl;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,17 +6,112 @@
|
||||
* Niels Sascha Reedijk, [email protected]
|
||||
*/
|
||||
|
||||
#include <deque>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <ErrorsExt.h>
|
||||
#include <HttpSession.h>
|
||||
#include <Locker.h>
|
||||
#include <OS.h>
|
||||
|
||||
using namespace BPrivate::Network;
|
||||
|
||||
|
||||
class BHttpSession::Impl {
|
||||
class BHttpSession::Request {
|
||||
|
||||
};
|
||||
|
||||
|
||||
class BHttpSession::Impl {
|
||||
public:
|
||||
Impl();
|
||||
~Impl() noexcept;
|
||||
|
||||
private:
|
||||
// Thread functions
|
||||
static status_t ControlThreadFunc(void* arg);
|
||||
static status_t DataThreadFunc(void* arg);
|
||||
|
||||
private:
|
||||
// constants (can be accessed unlocked)
|
||||
const sem_id fControlQueueSem;
|
||||
const sem_id fDataQueueSem;
|
||||
const thread_id fControlThread;
|
||||
const thread_id fDataThread;
|
||||
|
||||
// locking mechanism
|
||||
BLocker fLock;
|
||||
int32 fQuitting;
|
||||
|
||||
// queues
|
||||
std::deque<BHttpSession::Request> fControlQueue;
|
||||
std::deque<BHttpSession::Request> fDataQueue;
|
||||
std::vector<int32> fCancelList;
|
||||
|
||||
// data owned by the dataThread
|
||||
std::map<int,BHttpSession::Request> connectionMap;
|
||||
std::vector<object_wait_info> objectList;
|
||||
};
|
||||
|
||||
|
||||
BHttpSession::Impl::Impl()
|
||||
:
|
||||
fControlQueueSem(create_sem(0, "http:control")),
|
||||
fDataQueueSem(create_sem(0, "http:data")),
|
||||
fControlThread(spawn_thread(ControlThreadFunc, "http:control", B_NORMAL_PRIORITY, this)),
|
||||
fDataThread(spawn_thread(DataThreadFunc, "http:data", B_NORMAL_PRIORITY, this))
|
||||
{
|
||||
// check initialization of semaphores
|
||||
if (fControlQueueSem < 0)
|
||||
throw BRuntimeError(__PRETTY_FUNCTION__, "Cannot create control queue semaphore");
|
||||
if (fDataQueueSem < 0)
|
||||
throw BRuntimeError(__PRETTY_FUNCTION__, "Cannot create data queue semaphore");
|
||||
|
||||
// set up internal threads
|
||||
if (fControlThread < 0)
|
||||
throw BRuntimeError(__PRETTY_FUNCTION__, "Cannot create control thread");
|
||||
if (resume_thread(fControlThread) != B_OK)
|
||||
throw BRuntimeError(__PRETTY_FUNCTION__, "Cannot resume control thread");
|
||||
|
||||
if (fDataThread < 0)
|
||||
throw BRuntimeError(__PRETTY_FUNCTION__, "Cannot create data thread");
|
||||
if (resume_thread(fDataThread) != B_OK)
|
||||
throw BRuntimeError(__PRETTY_FUNCTION__, "Cannot resume data thread");
|
||||
}
|
||||
|
||||
|
||||
BHttpSession::Impl::~Impl() noexcept
|
||||
{
|
||||
atomic_set(&fQuitting, 1);
|
||||
delete_sem(fControlQueueSem);
|
||||
delete_sem(fDataQueueSem);
|
||||
status_t threadResult;
|
||||
wait_for_thread(fControlThread, &threadResult);
|
||||
// The control thread waits for the data thread
|
||||
}
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
BHttpSession::Impl::ControlThreadFunc(void* arg)
|
||||
{
|
||||
BHttpSession::Impl* impl = static_cast<BHttpSession::Impl*>(arg);
|
||||
|
||||
// Cleanup: wait for data thread
|
||||
status_t threadResult;
|
||||
wait_for_thread(impl->fDataThread, &threadResult);
|
||||
return threadResult;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ status_t
|
||||
BHttpSession::Impl::DataThreadFunc(void* arg)
|
||||
{
|
||||
// BHttpSession::Impl* data = static_cast<BHttpSession::Impl*>(arg);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
BHttpSession::BHttpSession()
|
||||
{
|
||||
fImpl = std::make_shared<BHttpSession::Impl>();
|
||||
@@ -34,4 +129,3 @@ BHttpSession::BHttpSession(const BHttpSession&) noexcept = default;
|
||||
|
||||
BHttpSession&
|
||||
BHttpSession::operator=(const BHttpSession&) noexcept = default;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user